Velamuvi AIAcademy

Lesson 3 of 6 · Concepts

Handoffs

How agent handoffs work: triage passes a conversation to a specialist with a summary, hands back on topic change and avoids ping-pong. With runnable Python.

  • 7 min read
  • Advanced
  • Reviewed
In this lesson you will learn
  • Explain how a handoff differs from an orchestrator calling a worker
  • Pass the right context in a handoff: a summary and key details
  • Restrict which agents may hand off to which
  • Stop handoff loops and hand over to a person when needed

Passing the conversation on

Call a company's support line and you're often transferred: from a receptionist to billing, from billing to technical support. Agent handoffs work the same way.

That's the key difference from the orchestrator pattern. A lead agent delegates a sub-task and gets a result back, staying in charge. A handoff transfers control: the new agent now owns the conversation, until it hands off again.

Orchestrator and workersHandoffs
Who talks to the userAlways the leadWhichever agent currently has control
What comes backA result for the lead to useNothing; control moves on
Typical useResearch, analysis, building something in partsCustomer support, assistants with distinct areas

A triage agent and two specialists

A common setup has a triage agent that works out what the user needs and hands off to a specialist. Each specialist can hand back to triage when the user changes topic:

Try it yourselfPython
# Handoffs: control of the conversation moves from one agent to another, with a short summary.
AGENTS = {
    "triage":  {"can_hand_to": ["billing", "tech"]},
    "billing": {"can_hand_to": ["triage"], "tools": ["get_invoice", "refund"]},
    "tech":    {"can_hand_to": ["triage"], "tools": ["check_status", "reset_router"]},
}

# Stand-in for the models' decisions on each user message: (agent, reply or handoff)
def decide(agent, message):
    if agent == "triage" and "charged" in message:
        return {"handoff": "billing", "summary": "Customer 5512 says they were charged twice in May."}
    if agent == "triage" and "internet" in message:
        return {"handoff": "tech", "summary": "Customer 5512 reports the internet drops every evening."}
    if agent == "billing" and "charged" in message:
        return {"reply": "I can see two May payments of 39 EUR. I've refunded the duplicate."}
    if agent == "billing":
        return {"handoff": "triage", "summary": "Billing issue solved (refund sent). New topic from the customer."}
    if agent == "tech":
        return {"reply": "The line check shows evening drops; I've scheduled a line repair for Thursday."}
    return {"reply": "How can I help?"}

def handle(active, message, max_handoffs=3):
    context = message
    for _ in range(max_handoffs + 1):
        decision = decide(active, context)
        if "reply" in decision:
            return active, decision["reply"]
        target = decision["handoff"]
        if target not in AGENTS[active]["can_hand_to"]:
            return active, f"(blocked handoff {active} -> {target})"
        print(f"   handoff {active} -> {target}: {decision['summary']}")
        active, context = target, decision["summary"] + " Latest message: " + message
    return "human", "Too many handoffs; passing you to a person."

active = "triage"
for msg in ["I was charged twice this month!", "Also, my internet keeps dropping in the evening."]:
    print("User:", msg)
    active, reply = handle(active, msg)
    print(f"{active}: {reply}\n")

Follow the second message. The billing agent sees a technical question it can't handle, so it hands back to triage with a summary that its issue is solved. Triage then hands off to the technical agent. The user never has to repeat themselves, because each handoff carries a summary of what matters.

Notice the safety rails: each agent has a list of agents it's allowed to hand off to, and there's a maximum number of handoffs per message, after which a person takes over.

Handoffs as tool calls

In practice, a handoff is usually a tool the model can call. The billing agent gets a tool like transfer_to_tech(summary). When the model calls it, your code switches the active agent, builds the new agent's context and carries on. OpenAI's Agents SDK, for example, represents each handoff as a tool named after the target agent, such as transfer_to_refund_agent.

Making handoffs tools has useful side effects: the model has to state a reason or summary in the arguments, your code can validate the handoff, and every handoff appears in your logs.

What to pass along

The receiving agent needs enough context to continue, but not everything:

  • A short summary of the situation, written by the agent handing off.
  • Key details as structured fields: customer ID, order number, what's been tried.
  • The user's latest message, word for word.
  • Usually not the whole history: earlier small talk and another agent's tool results are noise for the new agent, and may include things it shouldn't see.

Handing over to a person

A person is just another place to hand off to, and often the most important one. Hand over to a human when the user asks for one, when the agents can't solve the problem, when the stakes are high (complaints, legal threats, vulnerable customers), or when the agents start passing the conversation back and forth.

Common mistakes

Practice exercise

Write a guard against agents passing one request back and forth: while handling a single user message, stop as soon as the same handoff happens twice.

Your solutionPython
handoffs = [("triage", "billing"), ("billing", "triage"), ("triage", "billing"), ("billing", "triage")]

# Go through the handoffs in order. If a handoff (from, to) has already happened before,
# print "Repeated handoff at step <n>: <from> -> <to>" and stop.
# If there are no repeats, print "No repeats".
Knowledge check

What is the main difference between a handoff and an orchestrator delegating to a worker?

Summary

  • A handoff transfers control of a conversation to another agent; delegation returns a result to a lead that stays in charge.
  • A triage agent routes to specialists, which hand back when the topic changes.
  • Handoffs are usually tool calls, so they carry a summary and can be validated and logged.
  • Pass a summary, key details and the latest message, not everything.
  • Restrict allowed targets, cap handoffs, stop ping-pong, and always allow handover to a person.

Next: agent communication, how agents exchange messages reliably.

Finished reading? Tick it off to track your progress.