OpenAI Agents SDK (Python)
TL;DR
The OpenAI Agents SDK is OpenAI's MIT-licensed Python library for agent workflows built from a few primitives: agents with tools, handoffs, guardrails, sessions and tracing. It works with OpenAI's Responses and Chat Completions APIs and other providers. It suits Python developers who want a thin, code-first layer, especially on OpenAI models.
Key facts
| Type | Framework |
|---|---|
| Languages / SDKs | Python |
| License | MIT |
| Pricing model | Open source, free |
| Orchestration pattern | Handoff |
| GitHub stars | 29,790 (as of 2026-10-01) |
| GitHub forks | 4,841 |
| Last push | 2026-10-01 |
| Latest release | v0.22.3 |
| Repository | openai/openai-agents-python |
| Website | openai.github.io |
| Documentation | openai.github.io |
| Last verified | 2026-09-30 |
Key features
Agent: a model plus instructions, tools, guardrails and handoffs, run by aRunnerloop until it produces final output. (source)- Handoffs: a triage agent passes the conversation to a specialist, which becomes the active agent; input filters control what history moves over. (source)
- Agents as tools: a manager agent calls specialists through
Agent.as_tool()and keeps ownership of the answer. (source) - Input and output guardrails that run alongside the agent and can stop a run when a check trips. (source)
- Sessions that store conversation history across runs, with SQLite, Redis, SQLAlchemy and OpenAI Conversations backends. (source)
- Built-in tracing of model calls, tools and handoffs, sent to the OpenAI traces dashboard or to custom processors. (source)
- MCP support over stdio, SSE and Streamable HTTP, plus hosted MCP tools executed by the Responses API. (source)
- Sandbox agents that work inside a container or local workspace for longer file and shell tasks. (source)
Architecture and orchestration pattern
Pattern: Handoff
The basic unit is an Agent: a model with instructions, tools, guardrails and a list of agents it may hand off to. Runner.run() (or run_sync / run_streamed) drives the loop: call the model, execute tool calls, follow handoffs, and stop when an agent produces final output.
The docs describe two main multi-agent patterns. With handoffs, a triage agent routes the conversation to a specialist, and that specialist takes over for the rest of the turn. With agents as tools, a manager agent calls specialists via Agent.as_tool() and composes their results itself. The two can be combined, and flows can also be orchestrated in plain Python by chaining runs or running agents in parallel.
Runs hold no memory by default. Sessions persist conversation history client-side (SQLite, Redis, SQLAlchemy and others), or the app can use OpenAI's server-managed continuation (previous_response_id, conversation_id) instead. A paused run can be serialized as RunState and resumed later. Tracing records each model call, tool call and handoff as spans.
Human in the loop
Tools declare needs_approval=True, or pass an async function that decides per call. This is available on function tools, Agent.as_tool, ShellTool and ApplyPatchTool; local MCP servers take require_approval and hosted MCP tools a require_approval tool config. When approval is needed, the run stops and the result lists pending approvals as interruptions. The application approves or rejects each item on the RunState, which can be serialized and stored, and then resumes the original run. Approvals raised inside handoffs or nested agent tools surface on the outer run. Some tool types also accept programmatic approval callbacks so the run continues without pausing.
Harnesses it can drive
- Codex (evidence)
Protocols
| Protocol | Support | Note |
|---|---|---|
| MCP | Yes evidence | Client: MCPServerStdio, MCPServerSse and MCPServerStreamableHttp connect agents to MCP servers, and HostedMCPTool lets the Responses API call a public MCP server. |
| A2A | No evidence | A maintainer comment on issue #472 (2026-08-05) states OpenAI does not plan to add an SDK-owned A2A abstraction and shows wiring the separate a2a-sdk by hand instead. |
| AG-UI | Unknown | No AG-UI mention in the SDK docs or repo code search; the AG-UI README lists 'OpenAI Agent SDK' under community integrations with status 'In Progress'. |
Best for
- Customer-facing assistants that route requests from a triage agent to specialist agents (shortlist)
- Delegating bounded repository tasks to the Codex CLI from inside an agent run (experimental) (shortlist)
- Tool calls that need human approval with pause and resume across processes (shortlist)
- Python teams already on the OpenAI Responses API who want tracing without extra setup
Not for
- Systems that need built-in A2A interoperability; maintainers have said an SDK-owned A2A layer is not planned
- Teams that need API stability guarantees; the SDK is still on 0.Y versions where minor releases can break interfaces
- Browser-based WebRTC voice sessions; the Python SDK's realtime transport covers server-side WebSocket and SIP only
Quickstart
pip install openai-agents from agents import Agent, Runner
billing = Agent(name="Billing agent",
instructions="Answer billing questions in two sentences.")
tech = Agent(name="Tech support agent",
instructions="Answer technical questions step by step.")
triage = Agent(
name="Triage agent",
instructions="Decide who should answer and hand off to that agent.",
handoffs=[billing, tech],
)
# needs OPENAI_API_KEY in the environment
result = Runner.run_sync(triage, "I was charged twice this month.")
print(result.last_agent.name) # the specialist that answered
print(result.final_output)
Common pitfalls
- Python 3.10 or newer is required.
- Set
OPENAI_API_KEYbefore running; other providers need the model adapters described on the models page. - Voice and Redis sessions are optional extras:
openai-agents[voice],openai-agents[redis]. - Versions follow 0.Y.Z: a minor bump (for example 0.21 to 0.22) may contain breaking changes, so pin the minor version.
- Tracing is on by default; set
OPENAI_AGENTS_DISABLE_TRACING=1to turn it off. It is not available to organizations under Zero Data Retention. - A session cannot be combined with
previous_response_idorconversation_idin the same run.
Pros
- Few primitives to learn: agents, tools, handoffs, guardrails, sessions and tracing. (source)
- Not tied to OpenAI models: the README states support for the Responses and Chat Completions APIs and 100+ other LLMs. (source)
- Approvals work across handoffs and nested agent tools, and paused runs can be serialized and resumed. (source)
- Tracing is built in and can also feed third-party processors. (source)
- Covers all common MCP transports plus hosted MCP tools. (source)
Cons
- Maintainers stated in 2026 that there are no plans for an SDK-owned A2A abstraction. (source)
- Still versioned 0.Y.Z; minor releases may break public interfaces, and the changelog lists such changes. (source)
- Tracing is enabled by default and is unavailable to organizations under OpenAI's Zero Data Retention policy. (source)
- The Codex tool that drives the Codex CLI is marked experimental and may change. (source)
- Pull requests are accepted only from repository collaborators. (source)
Alternatives
FAQ
Does the OpenAI Agents SDK support MCP?
Yes, as a client. Agents connect to MCP servers over stdio, SSE or Streamable HTTP, and HostedMCPTool lets OpenAI's Responses API call a public MCP server directly.
Does it support A2A?
No. A maintainer comment on issue #472 in August 2026 said OpenAI does not plan an SDK-owned A2A abstraction and showed how to wire the separate a2a-sdk manually.
Is it free?
The SDK is MIT-licensed. Model calls and hosted tools on OpenAI's API are billed under OpenAI API pricing; other providers are billed by those providers.
Can I use non-OpenAI models?
Yes. The README says the SDK is provider-agnostic, and the models page covers non-OpenAI providers through adapters such as any-llm and LiteLLM.
What is the difference between handoffs and agents as tools?
A handoff makes the specialist the active agent for the rest of the turn. With agents as tools, a manager agent calls the specialist and keeps control of the final answer.
Sources
- OpenAI Agents SDK (Python) GitHub repository
- OpenAI Agents SDK documentation
- OpenAI Agents SDK README
- Quickstart (Agents SDK docs)
- Agents (Agents SDK docs)
- Handoffs (Agents SDK docs)
- Agent orchestration (Agents SDK docs)
- Guardrails (Agents SDK docs)
- Sessions (Agents SDK docs)
- Tracing (Agents SDK docs)
- Model context protocol (Agents SDK docs)
- Human-in-the-loop (Agents SDK docs)
- Tools, including the experimental Codex tool (Agents SDK docs)
- Models and providers (Agents SDK docs)
- Release process and breaking-change changelog (Agents SDK docs)
- Sandbox agents (Agents SDK docs)
- Maintainer comment on A2A support, issue #472
- AG-UI README, supported integrations
- OpenAI API pricing
- OpenAI Agents SDK for JavaScript/TypeScript
- Realtime transport (Agents SDK docs)