ExamplescriptIntermediateRunnableguided-flow
OpenAI Agents SDK handoffs: a triage agent routes tickets to specialists
A triage agent reads a support ticket and hands it off to a tech-support or billing agent through the SDK's handoffs. Runnable, asynchronous Python.
Key Facts
- Level
- Intermediate
- Runtime
- Python
- Pattern
- Inspectable flow with visible system boundaries
- Interaction
- Live sandbox • Script
- Code last changed
- 13 March 2025
Navigate this example
Library
Browse examplesReopen the wider library to compare adjacent patterns and linked learning paths.Interaction
Run sandbox nowTry the interaction directly in this example’s guided sandbox surface.Source
Open full sourceRead the real implementation, highlighted checkpoints, and runtime requirements.MCP
Call via MCPUse the same resource inside agents, deterministic exports, and MCP setup flows.
Linked principles
02-handoffs.py
python
from agents import Agent, Runner
import asyncio
import nest_asyncio
nest_asyncio.apply()
tech_support_agent = Agent(
name="Tech Support Agent",
instructions="You handle technical issues with our product. Be concise and helpful.",
)
billing_agent = Agent(
name="Billing Agent",
instructions="You handle billing and payment inquiries. Be concise and helpful.",
)
triage_agent = Agent(
name="Triage Agent",
instructions="Analyze the customer ticket and handoff to the appropriate specialist agent.",
handoffs=[tech_support_agent, billing_agent],
)
async def main():
result = await Runner.run(
triage_agent, input="My app keeps crashing when I try to open it."
)
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())
Related principles
- P1DelegationDesign for delegation rather than direct manipulationDesign experiences around the assignment of work, the expression of intent, the setting of constraints, and the review of results, rather than requiring users to execute each step manually.Open principle →
- P2VisibilityEnsure that background work remains perceptibleWhen the system is operating asynchronously or outside the user’s immediate focus, it should provide persistent and proportionate signals that work is continuing.Open principle →
- P5DelegationReplace implied magic with clear mental modelsThe product should help users understand what the system can do, what it is currently doing, what it cannot do, and what conditions govern its behaviour.Open principle →
- P8TrustMake hand-offs, approvals, and blockers explicitWhen the system cannot proceed, the reason should be immediately visible, along with any action required from the user or another dependency.Open principle →
- P9OrchestrationRepresent delegated work as a system, not merely as a conversationWhere work involves multiple steps, agents, dependencies, or concurrent activities, it should be represented as a structured system rather than solely as a message stream.Open principle →
- P10DelegationOptimise for steering, not only initiatingThe system should support users not only in starting tasks, but also in guiding, refining, reprioritising, and correcting work while it is underway.Open principle →