How does OpenAI Swarm / Agents SDK express an agent handoff?
In Swarm and the OpenAI Agents SDK, a handoff is just a tool whose return value is the next Agent. The runtime swaps the active agent and keeps the loop running; no orchestrator graph.
Picture a small restaurant with three specialists, a host, a server, and a chef, but no manager. The host greets you and, if you ask about the menu, hands you a card that says 'Talk to the server.' That card is the entire handoff mechanism. The host did not call a manager, did not send a message through a special channel, did not flag a transfer event. They just used a tool they already had (handing you a card) whose result happened to mean 'now this other person is talking to you.' Swarm bets that the simplest possible primitive, a normal tool that returns a person, is enough to coordinate the whole restaurant.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 minutes: the tool-returns-Agent mechanism, what Swarm intentionally lacks, the design bet, and when to graduate to LangGraph.
from swarm import Swarm, Agent
def transfer_to_billing():
"""Hand off to the billing specialist when the user asks about invoices, refunds, or pricing."""
return billing
def transfer_to_tech():
"""Hand off to the tech specialist when the user reports a bug or asks how to use the product."""
return tech
greeter = Agent(
name="Greeter",
instructions="Greet the user, identify the topic, then hand off.",
functions=[transfer_to_billing, transfer_to_tech],
)
billing = Agent(name="Billing", instructions="Resolve billing questions.")
tech = Agent(name="Tech", instructions="Resolve technical questions.")
client = Swarm()
result = client.run(agent=greeter, messages=[{"role": "user", "content": "I was double-charged."}])
# greeter sees 'double-charged', calls transfer_to_billing(), runtime swaps in billing, loop continues.| Framework | Handoff mechanism | Orchestration primitive |
|---|---|---|
| Swarm / OpenAI Agents SDK | Tool returning an Agent | None. Model picks via tool call |
| LangGraph | Node + conditional edge / Supervisor pattern | StateGraph |
| CrewAI Hierarchical | Manager LLM delegates via `delegate` tool | Crew + manager_llm |
| AutoGen GroupChat | Manager picks via select_speaker | GroupChatManager |
Real products, models, and research that use this idea.
- OpenAI's original Swarm GitHub repository explicitly describes itself as 'educational' and 'experimental'. The design exists to teach a minimal orchestration pattern.
- The OpenAI Agents SDK (the productionised evolution of Swarm) inherits the handoff as tool pattern and adds typed inputs, tracing, and guardrails.
- Production triage agents at customer-support platforms commonly use a greeter agent whose handoff tool returns one of (billing_specialist, tech_specialist, account_specialist) based on the user's first message.
- CrewAI's hierarchical mode, LangGraph's Supervisor pattern, and AutoGen's GroupChatManager are the heavier alternatives that pay for explicit orchestration primitives Swarm chose not to invent.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you enforce a deterministic routing policy on top of Swarm handoffs?
QWhat does the conversation history look like across a handoff?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming Swarm needs an orchestrator graph or a transfer protocol. And missing the point that handoffs reuse the model's existing tool-calling capability with zero new orchestration primitives.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.