Core Concepts
Agents with Tools
from agents import Agent, function_tool
@function_tool
def get_weather(city: str) -> str:
'Get weather for a city.'
return f"Weather in {city}: 22C, sunny"
agent = Agent(
name="weather-bot",
instructions="You help users check the weather.",
tools=[get_weather],
)Handoffs (Agent Delegation)
billing_agent = Agent(
name="billing",
instructions="Handle billing questions. Access to payment tools.",
tools=[get_invoice, process_refund],
)
support_agent = Agent(
name="support",
instructions="Handle general support. Hand off billing questions to billing agent.",
handoffs=[billing_agent],
)
# When user asks about billing, support_agent hands off to billing_agentGuardrails
from agents import GuardrailFunctionOutput, input_guardrail
@input_guardrail
async def block_harmful(ctx, agent, input_text):
if "hack" in input_text.lower():
return GuardrailFunctionOutput(
output_info={"reason": "Potentially harmful request"},
tripwire_triggered=True,
)
agent = Agent(
name="safe-agent",
input_guardrails=[block_harmful],
)Tracing
Every agent run produces a detailed trace:
result = Runner.run_sync(agent, "Help me with my order")
# View trace at: https://platform.openai.com/traces/{trace_id}
# Shows: agent decisions, tool calls, handoffs, guardrail checksStructured Output
from pydantic import BaseModel
class OrderSummary(BaseModel):
order_id: str
status: str
total: float
agent = Agent(
name="order-agent",
output_type=OrderSummary, # Enforces structured response
)Multi-Agent Architecture
researcher = Agent(name="researcher", tools=[search_web])
writer = Agent(name="writer", handoffs=[researcher])
editor = Agent(name="editor", handoffs=[writer])
# editor -> writer -> researcher (chain of delegation)
result = Runner.run_sync(editor, "Write an article about AI agents")Key Stats
- 8,000+ GitHub stars
- Official OpenAI product
- Handoffs for agent delegation
- Input/output guardrails
- Built-in tracing and observability
FAQ
Q: What is OpenAI Agents SDK? A: The official Python SDK for building multi-agent systems with handoffs between specialists, safety guardrails, and execution tracing.
Q: Is it free? A: The SDK is open-source under MIT. You need an OpenAI API key.
Q: Does it work with Claude or other models? A: Designed for OpenAI models. For multi-model support, use LangGraph or CrewAI instead.