Skills2026年3月30日·1 分钟阅读

OpenAI Agents SDK — Multi-Agent Workflows in Python

Official OpenAI framework for building multi-agent workflows. Handoffs between agents, tool calling, guardrails, tracing, and streaming. Lightweight, Python-native. 20K+ stars.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Community
入口
OpenAI Agents SDK — Multi-Agent Workflows in Python
直接安装命令
npx -y tokrepo@latest install e0a359b3-9fb4-42a0-9785-aadd90c6e23d --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
OpenAI Agents SDK provides Python primitives for agent handoffs, tool calling, guardrails, and tracing in multi-agent systems.
§01

What it is

OpenAI Agents SDK is the official lightweight Python framework from OpenAI for building multi-agent workflows. It provides core primitives: Agents (LLMs with instructions and tools), Handoffs (delegation between specialized agents), Guardrails (input/output validation), and Tracing (execution observability). The SDK is designed to be minimal yet production-ready.

The SDK targets Python developers building multi-agent systems with OpenAI models. It works with GPT-4o, o3, and any OpenAI-compatible endpoint, making it suitable for both cloud and self-hosted model deployments.

§02

How it saves time or tokens

The SDK handles agent orchestration, context passing, and error recovery that you would otherwise build from scratch. Handoffs let specialized agents handle subtasks (billing, technical support, research) without routing logic in your application code. Guardrails validate inputs and outputs before and after agent runs, catching issues early and reducing wasted API calls.

§03

How to use

  1. Install the SDK: pip install openai-agents.
  2. Define agents with instructions and tools, and configure handoffs between them.
  3. Run the workflow with Runner.run_sync(agent, input) or the async equivalent.
§04

Example

from agents import Agent, Runner

# Define specialized agents
billing_agent = Agent(
    name='Billing',
    instructions='Handle billing questions and refunds.'
)

technical_agent = Agent(
    name='Technical',
    instructions='Handle technical support questions.'
)

# Triage agent delegates to specialists
triage = Agent(
    name='Triage',
    instructions='Route the user to the right agent.',
    handoffs=[billing_agent, technical_agent]
)

# Run the workflow
result = Runner.run_sync(triage, 'I need a refund for my last order.')
print(result.final_output)
§05

Related on TokRepo

§06

Common pitfalls

  • The SDK is optimized for OpenAI models; using non-OpenAI endpoints may require adjusting prompt formats for handoff instructions.
  • Guardrails run additional LLM calls for validation, which adds latency and cost; use them selectively on high-risk inputs.
  • Tracing generates detailed execution logs that can be verbose; configure log levels appropriately for production deployments.

常见问题

Can I use OpenAI Agents SDK with non-OpenAI models?+

The SDK works with any OpenAI-compatible endpoint, so you can point it at self-hosted models or third-party APIs that implement the OpenAI API format. However, handoff behavior is optimized for OpenAI models.

What is the difference between Agents SDK and LangGraph?+

Agents SDK is OpenAI's official, lightweight framework focused on handoffs and guardrails. LangGraph is LangChain's graph-based orchestrator with more complex state management. Choose Agents SDK for OpenAI-centric workflows and LangGraph for provider-agnostic graph-based agents.

How do handoffs work?+

When an agent determines a task should be handled by a specialist, it returns a handoff instruction. The SDK transfers the conversation context to the target agent automatically, preserving message history.

Are guardrails required?+

No. Guardrails are optional decorators you add to validate inputs or outputs. They are useful for filtering harmful content, enforcing format requirements, or implementing business rules.

Does the SDK support streaming?+

Yes. The SDK supports streaming responses through Runner.run_streamed(), which yields tokens as they are generated. This is useful for real-time chat interfaces.

引用来源 (3)
🙏

来源与感谢

Created by OpenAI. Licensed under MIT. openai/openai-agents-python — 20,000+ GitHub stars

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产