OpenAI Agents SDK 是一个轻量级但功能强大的框架,用于在 JavaScript/TypeScript 中构建多智能体工作流。它不依赖于特定供应商,支持 OpenAI API 及其他服务。

[!NOTE]
寻找 Python 版本?请查看 OpenAI Agents SDK Python。
查看 examples/ 目录以了解 SDK 的实际应用。
nodejs_compat 的 Cloudflare Workers查看文档 获取更详细的信息。
npm install @openai/agents zod
import { Agent, run } from '@openai/agents';
const agent = new Agent({
name: 'Assistant',
instructions: 'You are a helpful assistant',
});
const result = await run(
agent,
'Write a haiku about recursion in programming.',
);
console.log(result.finalOutput);
// Code within the code,
// Functions calling themselves,
// Infinite loop's dance.
(运行此代码时,请确保已设置 OPENAI_API_KEY 环境变量)
查看 examples/ 目录以了解 SDK 的实际应用。
我们要感谢开源社区的卓越工作,特别是:
我们致力于将 Agents SDK 构建为一个开源框架,以便社区中的其他人能够扩展我们的方法。