OpenAI Agents SDK — Multi-Agent Workflows in Python
Official OpenAI framework for building multi-agent workflows. Handoffs between agents, tool calling, guardrails, tracing, and streaming. Lightweight, Python-native. 20K+ stars.
What it is
OpenAI Agents SDK is the official lightweight Python framework from OpenAI for building multi-agent workflows. It provides core primitives: Agents (LLMs with instructions and tools), Handoffs (delegation between specialized agents), Guardrails (input/output validation), and Tracing (execution observability). The SDK is designed to be minimal yet production-ready.
The SDK targets Python developers building multi-agent systems with OpenAI models. It works with GPT-4o, o3, and any OpenAI-compatible endpoint, making it suitable for both cloud and self-hosted model deployments.
How it saves time or tokens
The SDK handles agent orchestration, context passing, and error recovery that you would otherwise build from scratch. Handoffs let specialized agents handle subtasks (billing, technical support, research) without routing logic in your application code. Guardrails validate inputs and outputs before and after agent runs, catching issues early and reducing wasted API calls.
How to use
- Install the SDK:
pip install openai-agents. - Define agents with instructions and tools, and configure handoffs between them.
- Run the workflow with
Runner.run_sync(agent, input)or the async equivalent.
Example
from agents import Agent, Runner
# Define specialized agents
billing_agent = Agent(
name='Billing',
instructions='Handle billing questions and refunds.'
)
technical_agent = Agent(
name='Technical',
instructions='Handle technical support questions.'
)
# Triage agent delegates to specialists
triage = Agent(
name='Triage',
instructions='Route the user to the right agent.',
handoffs=[billing_agent, technical_agent]
)
# Run the workflow
result = Runner.run_sync(triage, 'I need a refund for my last order.')
print(result.final_output)
Related on TokRepo
- Multi-Agent Frameworks -- compare multi-agent orchestration frameworks side by side
- AI Tools for Agents -- explore agent-building tools and frameworks
Common pitfalls
- The SDK is optimized for OpenAI models; using non-OpenAI endpoints may require adjusting prompt formats for handoff instructions.
- Guardrails run additional LLM calls for validation, which adds latency and cost; use them selectively on high-risk inputs.
- Tracing generates detailed execution logs that can be verbose; configure log levels appropriately for production deployments.
Frequently Asked Questions
The SDK works with any OpenAI-compatible endpoint, so you can point it at self-hosted models or third-party APIs that implement the OpenAI API format. However, handoff behavior is optimized for OpenAI models.
Agents SDK is OpenAI's official, lightweight framework focused on handoffs and guardrails. LangGraph is LangChain's graph-based orchestrator with more complex state management. Choose Agents SDK for OpenAI-centric workflows and LangGraph for provider-agnostic graph-based agents.
When an agent determines a task should be handled by a specialist, it returns a handoff instruction. The SDK transfers the conversation context to the target agent automatically, preserving message history.
No. Guardrails are optional decorators you add to validate inputs or outputs. They are useful for filtering harmful content, enforcing format requirements, or implementing business rules.
Yes. The SDK supports streaming responses through Runner.run_streamed(), which yields tokens as they are generated. This is useful for real-time chat interfaces.
Citations (3)
- OpenAI Agents SDK GitHub— Official OpenAI framework for multi-agent workflows
- OpenAI Docs— OpenAI API documentation for function calling and tool use
- OpenAI Cookbook— Multi-agent system design patterns
Related on TokRepo
Source & Thanks
Created by OpenAI. Licensed under MIT. openai/openai-agents-python — 20,000+ GitHub stars
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.