OpenAI 官方 Agent 开发框架,Python 原生构建。支持多 Agent 协作、Handoff 交接、Guardrails 安全护栏和 Tracing 追踪。轻量级设计,可组合扩展,替代 Assistants API。
快速安装
确保已安装 clawhub CLI
clawhub install openai-agents-sdkOpenAI 官方 Agent 开发框架——用 Python 构建生产级多 Agent 系统。
OpenAI Agents SDK 是 OpenAI 于 2026 年 3 月发布的官方 Agent 框架,替代了之前的 Assistants API。它采用轻量级、可组合的设计理念,让开发者用最少的代码构建复杂的多 Agent 协作系统。
核心概念:
与其他框架的区别:
pip install openai-agents # 设置 API Key export OPENAI_API_KEY=your-key
from agents import Agent, Runner agent = Agent( name="Assistant", instructions="You are a helpful assistant.", ) result = await Runner.run(agent, "Hello!") print(result.final_output)
from agents import Agent, Runner, handoff triage = Agent( name="Triage", instructions="Route to the right specialist.", handoffs=[ handoff(research_agent, "For research questions"), handoff(coder_agent, "For coding tasks"), ] ) result = await Runner.run(triage, "帮我写一个 Python 排序算法") # Triage → 自动交接给 coder_agent
from agents import Agent, GuardrailFunctionOutput, input_guardrail @input_guardrail async def check_toxicity(ctx, agent, input_data): is_toxic = await toxicity_check(input_data) return GuardrailFunctionOutput( output_info={"toxic": is_toxic}, tripwire_triggered=is_toxic ) agent = Agent( name="Safe Assistant", instructions="Be helpful.", input_guardrails=[check_toxicity] )
from agents import trace with trace("Research Workflow") as t: result = await Runner.run(agent, "Analyze this paper") # 自动记录所有 LLM 调用和工具执行 # 可在 OpenAI Dashboard 查看
提示:Agents SDK 的 Handoff 和 Guardrails 模式可以很好地与 MCP Server 集成——每个 Agent 连接不同的 MCP 工具集,Handoff 实现工具域的自动切换。
GitHub: https://github.com/openai/openai-agents-python (12k+ stars)
版本
v0.1.0
作者
openai
平台
发布时间
2026年5月10日
一站式 Agent 开发框架,原生支持 MCP 协议全特性(含 Sampling 和 Elicitations)。声明式语法定义 Agent,CLI 交互式调试,支持 Anthropic/OpenAI/Google/Ollama 等多种模型。
Python 原生多 Agent 协作框架,通过角色定义+任务分解+流程编排实现 Agent 团队协作。支持顺序和层级流程,内置记忆和工具系统。