Dynamically validates and loads the OpenAI Agents SDK module with dependency checks. Reuse for optional peer dependency loading in AI tooling.
// Source: https://github.com/promptfoo/promptfoo | License: MIT | Copyright Promptfoo 2025
// Provided via justclaw.it.com; keep this notice with the code.
import { createRequire } from 'node:module';
import path from 'node:path';
import semverSatisfies from 'semver/functions/satisfies.js';
import { getDirectory } from '../../esm';
import {
isMissingPackageImportError,
optionalPackageInstallHint,
} from '../../util/packageImportErrors';
import { getPackageVersion } from '../../util/packageVersion';
const installCommand = 'npm install promptfoo @openai/agents@^0.14.1';
/** Check Promptfoo's SDK before loading either the provider or its redteam tool loader. */
export async function loadOpenAiAgentsModule<T>(load: () => Promise<T>): Promise<T> {
try {
// Use Node's loader so Plu
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key