When to reach for it
- Responsibility clearly shifts between specialists.
- User interactions must switch to the appropriate agent.
- Security boundaries apply per agent.
One agent yields. Another takes over.
An agent completely transfers control and relevant context to another specialist.
Agent A completes its turn, packages context, and transfers control to Agent B. A single directed handoff.
| Turn | Active agent | What happens | Context passed |
|---|---|---|---|
| 1 | Triage | Recognises a billing case and calls transfer_to_billing | The conversation, the customer ID, “double charge, October” |
| 2 | Billing | Finds two identical invoices and refunds one | Nothing. Billing keeps the conversation |
| 3 | Billing | The user asks when the money arrives. Billing answers directly | Nothing. Triage is no longer involved |
def run(agents, start, user_message):
active, history = start, [user_message]
while True:
reply = agents[active](history) # only the active agent runs
if reply.handoff_to: # e.g. the tool call transfer_to_billing
# what is not passed on is lost
history = reply.context_for_next or history
active = reply.handoff_to
continue
# the active agent answers the user itself
return active, reply.textWhen to reach for it
When it backfires
The handoff carries only the last N messages. Earlier context (user preferences, constraints) is lost.
Countermeasure
Define a structured context schema for every handoff. Include user state, constraints, and pending obligations.
The handoff condition has no history. Agents ping-pong because each thinks the other is the right owner.
Countermeasure
Track handoff history in state. Cap total handoffs per user session and escalate to a supervisor on exhaustion.
Threat exposure
Adopting this pattern opens these attack surfaces. Each links to its entry in the threat model.
Full threat model →Next pattern
Search patterns, frameworks, and pages.