OpenAI Agents SDK Integration
OpenAI Agents SDK — official Python SDK for building agents based on OpenAI models. Provides abstractions over Assistants API and Responses API: Agent (wrapper over model with tools), Runner (agent execution), Handoffs (delegation between agents), Guardrails (checks), tracing. SDK replaces direct Assistants API calls with a more typed and testable interface.
Basic Agent
# pip install openai-agents
import asyncio
from openai import AsyncOpenAI
from agents import Agent, Runner, function_tool, RunConfig
client = AsyncOpenAI()
# Tools through decorator
@function_tool
def get_weather(city: str, unit: str = "celsius") -> str:
"""Get current weather in a city."""
data = weather_api.get(city=city, unit=unit)
return f"Weather in {city}: {data['temp']}°, {data['description']}"
# Create agent
assistant = Agent(
name="Corporate Assistant",
instructions="You are a corporate assistant. Help employees with meetings and tasks.",
model="gpt-4o",
tools=[get_weather],
)
# Run
async def main():
result = await Runner.run(
assistant,
input="Schedule a team meeting for tomorrow at 2 PM",
)
print(result.final_output)
asyncio.run(main())
Handoffs: Delegation Between Specialized Agents
from agents import Agent, handoff, Runner
# Specialized agents for different domains
triage_agent = Agent(
name="Triage",
instructions="Classify request and delegate to appropriate agent.",
model="gpt-4o-mini",
)
billing_agent = Agent(
name="Billing Support",
instructions="Help with billing questions, payments, subscriptions.",
model="gpt-4o",
tools=[get_invoice, process_refund, update_payment_method],
)
tech_agent = Agent(
name="Technical Support",
instructions="Solve technical issues: API, integrations, errors.",
model="gpt-4o",
tools=[check_api_status, get_error_logs, create_bug_report],
)
# Setup handoffs for triage
triage_agent.handoffs = [
handoff(billing_agent, tool_name_override="transfer_to_billing"),
handoff(tech_agent, tool_name_override="transfer_to_technical"),
]
# Triage automatically delegates to appropriate agent
result = await Runner.run(
triage_agent,
input="I was charged twice last month",
)
Timeline
- Basic agent with tools: 2–4 days
- Handoff architecture with 3–5 agents: 1–2 weeks
- Guardrails and safety checks: 3–5 days
- Tracing and monitoring: 3–5 days
- Production deployment: 1 week







