OpenAI Agents SDK — Build Multi-Agent Systems in Python
Official OpenAI Python SDK for building multi-agent systems with handoffs, guardrails, and tracing. Agents delegate to specialists, enforce safety rules, and produce observable traces. 8,000+ stars.
What it is
The OpenAI Agents SDK is the official Python framework for building multi-agent systems. It provides primitives for creating agents that delegate tasks to specialist sub-agents (handoffs), enforce safety constraints (guardrails), and produce observable execution traces. Each agent has its own instructions, tools, and model configuration, and agents can hand off conversations to each other based on the task at hand.
Developers building complex AI applications that require task decomposition, specialist routing, or safety guardrails benefit from this SDK. It is designed for production use with OpenAI models.
How it saves time or tokens
The SDK handles the orchestration complexity of multi-agent systems: routing, context passing, safety checks, and trace collection. Without it, developers build these patterns from scratch with custom code. The handoff mechanism lets you use cheaper models for simple tasks and route complex tasks to more capable models, optimizing token costs across the system.
How to use
- Install the SDK via pip
- Define agents with instructions, tools, and handoff rules
- Run the agent system with Runner and inspect traces
Example
from agents import Agent, Runner
triage = Agent(
name='triage',
instructions='Route user questions to the right specialist.',
handoffs=['coder', 'writer']
)
coder = Agent(
name='coder',
instructions='You write Python code to solve problems.',
model='gpt-4o'
)
writer = Agent(
name='writer',
instructions='You write clear, concise documentation.',
model='gpt-4o-mini'
)
result = Runner.run_sync(
triage,
messages=[{'role': 'user', 'content': 'Write a Python function to parse CSV'}]
)
print(result.final_output)
Related on TokRepo
- Multi-agent frameworks — Compare multi-agent orchestration tools
- AI tools for agents — Browse agent frameworks and SDKs
Common pitfalls
- Handoff loops can occur if agents keep routing to each other; set clear handoff conditions and a maximum depth
- Guardrails add latency to each agent turn; test performance impact before adding many validators
- The SDK is tightly coupled to OpenAI models; using it with other providers requires an OpenAI-compatible API proxy
Frequently Asked Questions
The SDK is designed for OpenAI models. You can use it with OpenAI-compatible API endpoints (like LiteLLM or vLLM) by pointing the base URL. Native support for Anthropic or Google models is not included.
Handoffs let one agent delegate a conversation to another specialized agent. The triage agent decides which specialist should handle the request and passes the conversation context. This enables task decomposition across multiple agents.
The SDK automatically records execution traces including agent turns, tool calls, handoffs, and guardrail evaluations. Traces can be viewed in the OpenAI dashboard or exported for custom analysis.
Yes. Agents can use custom Python functions as tools. Decorate a function with @tool, and the agent can call it during execution. Tools can access databases, APIs, file systems, or any Python-accessible resource.
The SDK itself is open-source and free. You pay for the OpenAI API calls that agents make. Costs depend on which models you configure for each agent and how many turns each task requires.
Citations (3)
- OpenAI Agents SDK GitHub— Official OpenAI Python SDK for multi-agent systems
- OpenAI Documentation— Handoffs, guardrails, and tracing primitives
- OpenAI Blog— Multi-agent orchestration with tool integration
Related on TokRepo
Source & Thanks
Created by OpenAI. Licensed under MIT.
openai-agents-python — stars 8,000+
Thanks to OpenAI for standardizing multi-agent patterns.