# OpenAI Agents SDK: A Practical Guide to Agents, Handoffs and Guardrails

> The OpenAI Agents SDK is a lightweight Python framework built on a few primitives: agents, handoffs, guardrails and tracing, plus sessions and human approvals. It suits assistants with clear roles, such as a triage agent routing to specialists; long-running, stateful processes need orchestration you build yourself.

Canonical URL: https://www.ruebstudio.de/en/guides/agent-frameworks/openai-agents-sdk-guide  
Author: Dr.-Ing. Marcus Rüb, CEO  
Published: 2026-11-17

The OpenAI Agents SDK is OpenAI's Python library for building agents that call tools, delegate work and check their own inputs and outputs. It deliberately offers a handful of primitives rather than a full platform. This guide is written for IT leads and engineering managers who need to judge whether it fits a business use case. Everything below reflects version 0.24.0, the current release on [PyPI](https://pypi.org/project/openai-agents/) as of November 2026.

## What is the OpenAI Agents SDK?

The OpenAI Agents SDK is an open-source Python framework, MIT-licensed, that runs a model in a loop until a task is done. You give an agent instructions and tools; the SDK handles tool calls, hand-offs between agents, validation checks and a trace of every step. It targets teams that want control without adopting a heavyweight orchestration layer.

The [official documentation](https://openai.github.io/openai-agents-python/) states two design goals: enough features to be worth using but few enough primitives to learn quickly, and sensible defaults that you can still customise in detail. That is the main thing separating it from larger frameworks. There is no graph DSL, no visual builder and no bundled database. What you get is an agent loop and a small set of hooks around it.

According to the [GitHub repository](https://github.com/openai/openai-agents-python), the SDK is provider-agnostic, supporting OpenAI's Responses and Chat Completions APIs "as well as 100+ other LLMs". A separate JavaScript/TypeScript package, openai-agents-js, exists for Node.js teams.

Where it tends to show up in companies:

- **Front-door triage:** an intake agent reads an incoming message, decides whether it is a complaint, a quote request or a billing question, and passes it to the right specialist.
- **System-aware assistants:** an agent queries order status in the ERP or searches technical manuals to answer questions from sales support or field service.
- **Voice agents:** the SDK ships building blocks for realtime and voice pipelines that chain speech-to-text, an agent and text-to-speech.

For a wider view of how it compares with other frameworks, see the [AI agent framework comparison](https://www.ruebstudio.de/en/guides/agent-frameworks/ai-agent-frameworks-comparison). For an overview of which business tasks agents handle well, start with [AI agents for business](https://www.ruebstudio.de/en/ai-agents).

## How does it work? Agents, handoffs, guardrails and tracing

Four primitives carry the design. An agent is a model plus instructions plus tools. A handoff transfers the conversation to another agent. A guardrail validates input, output or individual tool calls. Tracing records every step of a run. A runner ties them together by executing the agent loop.

### The agent loop

You run an agent through `Runner.run()` (async), `Runner.run_sync()` or `Runner.run_streamed()`. The [running agents page](https://openai.github.io/openai-agents-python/running_agents/) describes each iteration: the runner calls the model; if the reply is final output with no tool calls, the run ends; if it is a handoff, the active agent changes and the loop continues; if it contains tool calls, the runner executes them, appends the results and calls the model again.

A turn limit stops runaway loops. In the 0.24.0 source the default `max_turns` is 10, and exceeding it raises `MaxTurnsExceeded`.

```python
import asyncio
from agents import Agent, Runner, function_tool


@function_tool
def order_status(order_id: str) -> str:
    """Return the shipping status for an order."""
    # Replace with a real ERP lookup
    return f"Order {order_id}: shipped"


agent = Agent(
    name="Order desk assistant",
    instructions="Answer questions about orders briefly and factually.",
    tools=[order_status],
)


async def main():
    result = await Runner.run(agent, "Where is order 4711?")
    print(result.final_output)


asyncio.run(main())
```

Any Python function decorated with `function_tool` becomes a tool. The SDK builds the JSON schema from the signature and docstring and validates arguments with Pydantic. The current quickstart uses a shorter alias, `tool`, imported from `agents.decorators`; it points at the same function.

### Handoffs versus agents as tools

The [handoffs documentation](https://openai.github.io/openai-agents-python/handoffs/) explains that handoffs are presented to the model as tools, named `transfer_to_<agent_name>` by default. The receiving agent sees the full conversation so far. An `input_filter` trims what it receives, and an `on_handoff` callback lets you run your own code at the moment of transfer, for example to log the routing decision.

The [multi-agent page](https://openai.github.io/openai-agents-python/multi_agent/) contrasts this with `Agent.as_tool()`. As a tool, a specialist answers a bounded sub-question and the manager agent keeps ownership of the reply. Through a handoff, the specialist becomes the active agent and speaks to the user directly. A practical rule: if one agent must be accountable for the final answer, use agents as tools; if routing to an expert is the point, use handoffs.

### Guardrails

The [guardrails documentation](https://openai.github.io/openai-agents-python/guardrails/) defines three kinds. Input guardrails run only on the first agent in a chain. Output guardrails run only on the agent that produces the final output. Tool guardrails wrap individual function tools and run before and after each guarded call. A failed check raises an exception such as `InputGuardrailTripwireTriggered`.

One detail matters for anything with side effects. Input guardrails run in parallel with the agent by default, which keeps latency down, but the documentation warns that the agent may already have consumed tokens and executed tools before it is cancelled. Setting `run_in_parallel=False` makes the check complete first. For agents that write to business systems, blocking mode is the safer default.

### Tracing

The [tracing documentation](https://openai.github.io/openai-agents-python/tracing/) confirms tracing is on by default and that traces go to the OpenAI Traces dashboard. You can switch it off with the `OPENAI_AGENTS_DISABLE_TRACING=1` environment variable, with `set_tracing_disabled(True)`, or per run through `RunConfig.tracing_disabled`. `set_trace_processors()` replaces the default destination with your own, such as a self-hosted MLflow or Langfuse instance. Organisations on a Zero Data Retention agreement with OpenAI cannot use OpenAI's tracing backend at all.

## What else ships with the SDK?

Around the four core primitives sit sessions for conversation memory, human approvals for sensitive tool calls, MCP integration, OpenAI's hosted tools and realtime voice support. These make the SDK usable in production settings, but they do not change the underlying model: a loop that runs until the model produces a final answer.

### Sessions

Without a session, each run starts from a blank slate. The [sessions page](https://openai.github.io/openai-agents-python/sessions/) lists the available backends: `SQLiteSession` (file-backed or in-memory), Redis for shared memory across workers, SQLAlchemy for an existing relational database, MongoDB, Dapr, a server-side option built on OpenAI's Conversations API, and `EncryptedSession`, which adds encryption and expiry on top of another backend. A `SQLiteSession` created without a file path lives in memory and disappears when the process ends.

You can also manage history yourself with `result.to_input_list()`, or let OpenAI hold it via `conversation_id` or `previous_response_id`. The documentation notes that sessions cannot be combined with server-managed conversations.

### Human approvals

Mark a tool with `needs_approval` and the run pauses before calling it. According to the [human-in-the-loop page](https://openai.github.io/openai-agents-python/human_in_the_loop/), pending calls appear in `result.interruptions`. `result.to_state()` returns a `RunState` you can serialise to JSON, store, approve or reject later, and resume with `Runner.run(agent, state)`. The page is explicit that loading a state snapshot does not authenticate the snapshot or the reviewer. Where you store it and who may approve are your responsibility.

### Tools and MCP

The [tools page](https://openai.github.io/openai-agents-python/tools/) separates hosted OpenAI tools (web search, file search, code interpreter, hosted MCP, image generation), tools that run in your own environment such as `ComputerTool`, function tools from your own Python code, and agents exposed as tools. MCP servers can be attached so their tools appear next to yours. Hosted tools require OpenAI's Responses API model class.

## Which business agents is it suited for?

The SDK fits agents whose work happens in short, well-bounded turns: a request comes in, a few tools run, an answer goes out, perhaps after a handoff to a specialist. It is a weaker fit for processes that span days, branch heavily and need an auditable business state at every step.

Good fits:

- **Service triage with specialists:** one intake agent, specialists for spare parts, warranty claims and maintenance, connected by handoffs. Related reading: [AI agents for technical service](https://www.ruebstudio.de/en/ai-agents/technical-service).
- **Read-mostly internal assistants:** answering questions from manuals, inspection reports or order data through function tools. See [AI agents for knowledge management](https://www.ruebstudio.de/en/ai-agents/knowledge-management).
- **Quote preparation with sign-off:** the agent gathers customer data and list prices through tools, and a person approves the draft through `needs_approval`. See [AI agents for quotation](https://www.ruebstudio.de/en/ai-agents/quotation).

Weaker fits:

- **Multi-day workflows:** `RunState` handles pauses for approval, but it is not a workflow engine with explicit states and retries.
- **Fixed, fully known procedures:** if every step is predetermined, a graph library or plain Python calling the model at specific points is easier to test.
- **File- and shell-heavy work:** a harness such as the [Claude Agent SDK](https://www.ruebstudio.de/en/guides/agent-frameworks/claude-agent-sdk-guide) brings file and command tools out of the box.

### How it differs from the Claude Agent SDK

The two take opposite starting points. The [Claude Agent SDK](https://code.claude.com/docs/en/agent-sdk/overview) hands you a ready-made agent harness with built-in tools for files and commands, context management and permissions, and you restrict it. The OpenAI Agents SDK hands you primitives, and you assemble the agent: which tools exist, how agents split work, where checks sit. In practice that means more of your own code with the OpenAI SDK, a thinner dependency, and more freedom to plug in models from other providers.

## What do you need before you start?

On the technical side you need Python 3.10 or later (the requirement listed on PyPI for 0.24.0), an API key for your chosen model, and clean interfaces to the systems the agent will touch. On the organisational side you need one clearly scoped task, agreed approval rules and a decision on where trace data is allowed to go.

- **Model access:** if you set nothing, the SDK falls back to a default OpenAI model described in the [models documentation](https://openai.github.io/openai-agents-python/models/). Override it with `OPENAI_DEFAULT_MODEL`, `RunConfig(model=...)` or `Agent.model`.
- **Other providers:** point `set_default_openai_client` at any OpenAI-compatible `base_url`, or use the LiteLLM and Any-LLM adapters, which the documentation labels beta and best-effort. It also warns that some providers do not enforce a JSON schema for structured output, hosted tools are unavailable, and Responses-only fields are silently dropped on Chat Completions.
- **Integrations:** every tool is a Python function. Expect most of the effort to go into reliable functions for your ERP, CRM or document store, not into the agent definition.
- **Data protection:** decide in advance which model processes personal data, in which region, and whether traces may leave your environment. A setup can be operated in line with the GDPR only with the right contracts, hosting region and tracing configuration. Treat this as orientation, not legal advice.

## A step-by-step rollout

Build in layers. Start with one agent that can only read, then add approvals, then additional agents. Check each layer against real cases before adding the next, so you can still tell which component caused which behaviour.

1. **Pick one task.** One process, one input channel, one clear output, for example "classify incoming warranty emails and attach the matching order record".
2. **Build a single read-only agent.** Set `max_turns` deliberately and keep tracing on, but send traces somewhere you control.
3. **Collect test cases.** Gather 30 to 50 real, anonymised cases with expected results. The multi-agent documentation explicitly recommends investing in evals.
4. **Add guardrails.** A blocking input guardrail for out-of-scope requests, an output guardrail for format and content.
5. **Gate write actions.** Anything that books, sends or updates gets `needs_approval`, with the `RunState` stored server-side.
6. **Split into multiple agents only when needed.** Once one agent carries too many tools and instructions, divide the work with agents as tools or handoffs.
7. **Choose a production session store.** SQLite for testing; SQLAlchemy on your existing database, or Redis when several workers share conversations.

The documentation also describes a middle path between letting the model orchestrate and hard-coding everything: structured outputs to make routing decisions inspectable, agents chained in sequence, and independent subtasks run concurrently with `asyncio.gather`. It notes that orchestrating in code is more predictable in speed, cost and performance, which is usually what business processes need.

## Limits and risks

The SDK's lightness is also its main limitation. Business state, control flow across turns, permissions and operations remain largely your job. On top of that, several conveniences depend on OpenAI services and behave differently, or vanish, when you switch to another model provider.

- **State is yours to manage.** Sessions store conversation history, not business state. Whether a claim is open or closed belongs in your database, not in a chat log.
- **Control flow is implicit.** With handoffs, the model decides where to route. That is flexible but harder to test than an explicit branch. Where routes are fixed, route in code.
- **Guardrails have gaps.** Per the documentation, tool guardrails do not apply to the handoff call itself or to hosted tools, and input guardrails only fire on the first agent.
- **Parallel guardrails can be late.** In the default mode a tool may already have run before the check trips.
- **Tracing sends data to OpenAI by default.** Overlook this and prompts and tool results leave your environment unnoticed.
- **The API is still 0.x.** Interfaces shift between minor versions; the quickstart has already moved to the `tool` alias. Pin the version and read the release notes before upgrading.
- **Third-party models behave differently.** Hosted tools disappear and structured output varies by backend. Test the exact model you will run in production.

In our own operations, we start every agent read-only and route every write action through an approval step first, whichever framework is underneath.

## How to get started

Create a virtual environment, install the package, and build one agent with one read-only tool against a real process. Review ten real cases in the trace view before you add handoffs, guardrails or further agents.

```bash
python -m venv .venv
source .venv/bin/activate
pip install openai-agents==0.24.0
export OPENAI_API_KEY=...   # keep keys in the environment, never in code
```

Three questions settle whether the SDK is the right tool:

1. **Can the work be broken into short turns?** Then the agent loop fits well.
2. **Do you need roles that pass conversations to each other?** Then handoffs are a real advantage.
3. **Does the process run for days with a fixed state model?** Then pair the SDK with a workflow engine, or look at alternatives in the [framework comparison](https://www.ruebstudio.de/en/guides/agent-frameworks/ai-agent-frameworks-comparison).

If the open question is which processes in your organisation are worth automating at all, the overview of [AI agents for business](https://www.ruebstudio.de/en/ai-agents) is a sensible starting point. For decisions about model hosting and data residency, see [sovereign AI](https://www.ruebstudio.de/en/sovereign-ai).

## Frequently asked questions

### Does the OpenAI Agents SDK cost anything?

The library is MIT-licensed and free to use. You pay for the model calls it makes, billed by whichever model provider you use.

### Can I use it with models from other providers?

Yes, through OpenAI-compatible endpoints, a custom model provider, or the beta LiteLLM and Any-LLM adapters. Hosted tools such as web search and file search generally stop working outside OpenAI's Responses API.

### What is the difference between a handoff and an agent used as a tool?

With a handoff, the specialist takes over the conversation for the rest of the turn. With Agent.as_tool(), a manager agent keeps control and only asks the specialist for a bounded result.

### Is there a TypeScript version?

Yes, OpenAI maintains a separate JavaScript/TypeScript SDK called openai-agents-js. This guide covers the Python package.

## Sources

- [OpenAI Agents SDK documentation (overview)](https://openai.github.io/openai-agents-python/)
- [OpenAI Agents SDK: Quickstart](https://openai.github.io/openai-agents-python/quickstart/)
- [OpenAI Agents SDK: Running agents](https://openai.github.io/openai-agents-python/running_agents/)
- [OpenAI Agents SDK: Handoffs](https://openai.github.io/openai-agents-python/handoffs/)
- [OpenAI Agents SDK: Guardrails](https://openai.github.io/openai-agents-python/guardrails/)
- [OpenAI Agents SDK: Tracing](https://openai.github.io/openai-agents-python/tracing/)
- [OpenAI Agents SDK: Sessions](https://openai.github.io/openai-agents-python/sessions/)
- [OpenAI Agents SDK: Human in the loop](https://openai.github.io/openai-agents-python/human_in_the_loop/)
- [OpenAI Agents SDK: Models](https://openai.github.io/openai-agents-python/models/)
- [OpenAI Agents SDK: Orchestrating multiple agents](https://openai.github.io/openai-agents-python/multi_agent/)
- [OpenAI Agents SDK: Tools](https://openai.github.io/openai-agents-python/tools/)
- [openai/openai-agents-python on GitHub](https://github.com/openai/openai-agents-python)
- [openai-agents on PyPI](https://pypi.org/project/openai-agents/)
- [Claude Agent SDK: Overview](https://code.claude.com/docs/en/agent-sdk/overview)
