CLI ToolsApr 7, 2026·2 min read

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.

TL;DR
Official OpenAI SDK for multi-agent systems with handoffs, guardrails, and tracing in Python.
§01

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.

§02

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.

§03

How to use

  1. Install the SDK via pip
  2. Define agents with instructions, tools, and handoff rules
  3. Run the agent system with Runner and inspect traces
§04

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)
§05

Related on TokRepo

§06

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

Does the Agents SDK work with non-OpenAI models?+

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.

What are handoffs?+

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.

How does tracing work?+

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.

Can I add custom tools to agents?+

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.

Is the Agents SDK free?+

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)
🙏

Source & Thanks

Created by OpenAI. Licensed under MIT.

openai-agents-python — stars 8,000+

Thanks to OpenAI for standardizing multi-agent patterns.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets