OpenAI Agents SDK: A Practical Guide to Building Multi-Agent Apps

OpenAI Agents SDK: A Practical Guide to Building Multi-Agent Apps

OpenAI Agents SDK is OpenAI’s open-source framework for building multi-agent applications in Python, with a TypeScript version for JavaScript projects. It launched in March 2025 and replaced OpenAI’s earlier experimental Swarm framework. The short answer to what it does is simple: it gives you a small set of building blocks — agents, handoffs, guardrails and tracing — that are enough to build real multi-agent systems without learning a heavy new abstraction.

This guide explains how the SDK works, what each primitive does, when it is the right choice, and where its limits show up in production.

Key takeaways

  • The OpenAI Agents SDK is a lightweight, open-source framework for building agents in Python and TypeScript.
  • Its core primitives are agents, handoffs, guardrails, sessions and built-in tracing.
  • It replaced the experimental Swarm framework when it launched in March 2025.
  • A triage agent with handoffs is the standard pattern for routing work to specialist agents.
  • The SDK owns the agent loop, so you write less orchestration code but must understand what it hides.

What the OpenAI Agents SDK is

The OpenAI Agents SDK enables you to build agentic AI apps in a lightweight, easy-to-use package with very few abstractions. You install it with pip install openai-agents, and you import agents from the agents package — not from the plain openai package, which still handles raw chat, responses and embeddings. That distinction trips people up on day one, so it is worth stating plainly.

The SDK is Python-first. You use built-in language features to orchestrate and chain agents, rather than learning a new configuration language or a graph notation. A TypeScript version exists for JavaScript projects, but Python is where the ecosystem and examples are deepest.

OpenAI describes the SDK as production-ready, and it is the successor to Swarm, an earlier experiment that proved the handoff pattern but was never meant for production use. The Agents SDK keeps Swarm’s best idea — agents delegating to other agents — and adds the guardrails, sessions and tracing that production systems need.

The core primitives

The SDK has a very small set of primitives, and that is the point. An agent is a language model equipped with instructions and tools. A handoff lets one agent delegate to another agent for a specific task. A guardrail validates agent inputs and outputs. Tracing records every step of a run so you can visualise and debug it.

Sessions add conversation memory. The SDK can maintain conversation history automatically across agent runs, so you do not need to manage message lists by hand between turns. A built-in session backed by SQLite is available for local development and simple deployments.

Agents can also call other agents as tools, which is a different pattern from handoffs: the calling agent keeps control and uses the other agent’s output as one input among many. Handoffs transfer control entirely, so the new agent takes over the conversation with its own instructions and tools.

Agents and the Runner

The mental model is small: an agent plus a Runner. You describe the agent declaratively — its instructions, its tools, its handoffs and its guardrails — and hand it to the Runner, which runs until the model returns a final output or a guardrail trips. The Runner owns the loop: it calls the model, executes tools, feeds results back, and repeats.

Function tools turn any Python function into a tool with automatic schema generation and validation powered by Pydantic. You write a function with a type-annotated signature and a docstring, and the SDK turns that into the tool schema the model sees. Built-in tools include web search, file search and code interpretation, and you can expose MCP servers as tools too.

The result object from a run carries the final output along with the new items produced, the raw responses and the last agent that ran. In production you will usually want the async Runner with streaming events rather than the blocking synchronous entry point, so your application can show progress as the agent works.

Hands typing on a laptop keyboard with a blurred screen showing simple colourful flow shapes
The SDK keeps the code small: an agent plus a Runner is often all you need.

Handoffs: the pattern that sells the SDK

A handoff is a delegation from one agent to another, modelled to the language model as a regular tool call. When the model decides to hand off, the SDK swaps the active agent mid-run — new instructions, new tools, same conversation — and keeps going. You write no routing code.

The standard pattern is a triage agent. It has no tools of its own, only handoffs to specialist agents. A support triage agent might route billing questions to a billing agent, technical questions to a support agent, and abuse reports to a read-only policy agent. The SDK renders each handoff target as a tool named after the agent, so the model picks a handoff the same way it picks any tool call.

This pattern scales well because each specialist agent is small and easy to test on its own. The triage agent’s job is only to choose correctly, which is a much easier task than doing everything. If a handoff goes wrong, you can see it in the trace and fix the triage instructions or add a guardrail.

Guardrails: safety checks that run alongside

Guardrails are configurable safety checks for input and output validation. They run in parallel with agent execution and fail fast when a check does not pass, so a run stops before a bad input reaches the model or a bad output reaches the user.

Input guardrails screen what comes in: they can check for prompt injection, off-topic requests, or content your system should not handle. Output guardrails check what the agent produces: they can verify that an answer follows policy, contains required information, or stays within bounds. Because guardrails run concurrently, they add little latency to the run.

Guardrails are not blocking middleware in the traditional sense. They are concurrent validators that can trip an exception mid-run, and you decide what happens next — whether to stop, retry, or route to a human. That distinction matters when you design error handling, because a tripped guardrail is an event your application must handle, not a silent filter.

OpenAI Agents SDK at a glance

Dimension OpenAI Agents SDK What it means in practice
Languages Python and TypeScript Python is the primary ecosystem; TypeScript covers JavaScript projects
Install pip install openai-agents Separate package from the plain openai client library
Core primitives Agents, handoffs, guardrails, sessions, tracing Five concepts cover most multi-agent designs
Orchestration The Runner owns the loop You describe agents; the SDK runs them to completion
Tools Function tools, built-in tools, MCP servers Any Python function can become a tool
Memory Sessions for conversation history History handled automatically across runs
Human approval Supported for sensitive tool calls A person can approve before a risky action runs
Tracing Built in, with external destinations View runs in the OpenAI dashboard or export to observability tools
Voice Realtime voice agents supported Voice agents use the same agent primitives
Predecessor Replaced the experimental Swarm framework Swarm proved the handoff pattern; the SDK is the production version

Tracing and observability

The SDK automatically traces your agent runs, making it easy to track and debug behaviour. Tracing is extensible by design, supporting custom spans and a wide variety of external destinations, including observability tools such as Logfire, AgentOps and Braintrust. You can view traces in the OpenAI dashboard, where every run shows its tool calls and outputs.

Tracing is also the foundation for evaluation. The SDK’s tracing integrates with OpenAI’s evaluation, fine-tuning and distillation tools, so you can measure how your agents perform on real traffic and improve them systematically. That matters because agent behaviour drifts as you change prompts, tools and models, and you need evidence of what changed.

When the OpenAI Agents SDK fits

Best for the OpenAI Agents SDK: support and triage systems, internal assistants, and any multi-agent application where a small number of specialist agents route work between themselves and the team is already working in Python.

The SDK shines when the workflow is a routing problem. Triage, classification, escalation and delegation are its home territory. It is also a good first framework for a team new to agents, because the learning curve is gentle and the code stays close to plain Python. For a wider comparison before you commit, see our overview of AI agent frameworks and how to choose one.

It fits less well when you need explicit control over execution order, durable checkpoints across days, or a graph you can audit step by step. For those needs, a graph-based framework is a better match — see our guide to AI agent design patterns that actually hold up in production.

Production checklist

Use this checklist before you ship an application built on the SDK.

  • Pin the SDK version and treat every upgrade as potentially breaking, since the SDK is young and changes quickly.
  • Set up tracing from day one and decide how traces link to your request IDs and user sessions.
  • Add input guardrails for prompt injection and off-topic requests, and output guardrails for policy and format.
  • Require human approval for sensitive tool calls, such as refunds, deletions or external messages.
  • Test the triage agent separately from the specialists, with cases designed to confuse routing.
  • Log token use and cost per run, and alert on runs that cost far more than the median.
  • Build an evaluation set with expected outcomes and re-run it after every prompt or model change.
  • Keep business rules in Python code where tests can reach them, not only in agent instructions.

Common mistakes to avoid

The most common mistake is putting load-bearing logic in instructions. The model does the soft part — understanding language and choosing between options. Python should enforce the hard part: checking permissions, validating amounts, and deciding whether an action is allowed. If a rule only exists in a prompt, it will eventually be broken.

Another mistake is ignoring version pins. The SDK cuts roughly one minor release a month, and signatures have broken between minor versions. Pin the version in production, test upgrades in staging, and read the changelog before you deploy.

Frequently asked questions

What is the OpenAI Agents SDK?

It is an open-source framework from OpenAI for building multi-agent applications in Python and TypeScript. Its core primitives are agents, handoffs, guardrails, sessions and tracing, and it replaced the experimental Swarm framework.

How do I install the OpenAI Agents SDK?

Install it with pip install openai-agents, then import Agent and Runner from the agents package. It is a separate package from the plain openai client library, which handles raw chat, responses and embeddings.

What is a handoff in the OpenAI Agents SDK?

A handoff is a delegation from one agent to another, modelled as a tool call. When the model chooses it, the SDK swaps the active agent mid-run, keeping the same conversation but applying the new agent’s instructions and tools.

Does the OpenAI Agents SDK work with models other than OpenAI’s?

The SDK is designed around OpenAI models, but it supports other providers through its model configuration. Check the current documentation for the providers supported in your version, since this area changes frequently.

What are guardrails in the OpenAI Agents SDK?

Guardrails are safety checks that validate agent inputs and outputs. They run in parallel with execution and fail fast when a check does not pass, so bad inputs or outputs are caught before they cause harm.

Is the OpenAI Agents SDK free?

The SDK itself is open source and free to use. You pay for the OpenAI API usage your agents generate, including model calls, tracing and any built-in tools you use.

Latest articles

Scroll to Top