By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Step 17 introduced the supervisor. The next question is how the handoff itself works, because multi-agent systems fail at the seams rather than inside the workers. Two topologies dominate. In a supervisor team one node holds the routing policy: every worker returns to it, and it decides the next hop or finishes. In a swarm every agent may hand control straight to a peer; there is no central coordinator, so the path is decided hop by hop.
| Question | Supervisor | Swarm |
|---|---|---|
| Who decides the next hop | The supervisor node, one decision per turn | The current agent, as part of its own return value |
| Where control returns | Always to the supervisor before the next decision | Straight to a peer; no node sees the whole path |
| Trace shape | Hub and spoke: every hop passes through one node | Chain of peers: the node order is the path |
| Loop risk | Bounded in one place by the supervisor's budget | Ping-pong between peers, with no single owner |
| Fits when | Work has clear specialisms and coordination is worth a model call | Peers are close in capability and hand off by domain naturally |
| Cost per hop | One supervisor call plus one worker call | One agent call, with no separate coordination call |
Underneath, both are the same protocol: a handoff is a state update plus a transfer of control. Supervisor versus swarm is a question of where the routing policy lives, not a different runtime. That is why the same Command return and the same conditional-edge mapping implement both.
A handoff crosses a boundary of state, not a Python call stack. The worker reads what the schema declares and returns a partial update; its local variables are private and disappear the moment it returns. That makes the state schema the team's contract: if the schema does not name a fact, the fact cannot cross a worker boundary, and the next agent will behave as if it never existed.
active_agent (or next_agent) is who owns the turn now: one string, written on every handoff, read by the router or the next agent. This is the field that keeps the trace and the state in agreement.task is the concrete job the current agent is solving, kept apart from the chat transcript so a worker is not re-reading the whole conversation to find its assignment.messages carries the conversation with the add_messages reducer; share it when agents need the same context, drop it when a worker only needs the task.artifacts or findings use a reducer such as operator.add so several workers can contribute without an InvalidUpdateError.handoff_log records who handed off to whom and why; a handoff_budget counts the hops that remain. The log is for debugging; the budget is for stopping.status or error holds a terminal outcome (done, needs human, failed) that a synthesizer or caller can read without inferring it from prose.Two rules keep the contract honest. Write before you hand off: every fact the next agent needs must be in state before goto fires, not in a comment or a log line. Never reuse a field for two meanings: a next string that sometimes means a worker and sometimes means a finish label will eventually be read by the wrong half of the graph. Payload discipline matters too: short typed fields, ids rather than objects, no secrets and no giant blobs — checkpoints store everything you put in state.
Command packages both halves of a handoff into one return value. A node that returns Command(goto="billing", update={"active_agent": "billing"}) writes state and chooses the next node in the same step: LangGraph applies the update exactly like a normal partial update, then takes the dynamic edge that goto names.
goto names a node in the current graph, END, or a list of node names for a parallel dispatch.update is the partial state update; the same reducers apply, so a list written on a handoff still merges with operator.add.graph changes which graph the destination belongs to. Inside a compiled subgraph, Command(goto="billing", graph=Command.PARENT, update=...) hands control to a node in the parent graph instead of a sibling inside the subgraph.Command versus a conditional edge is mostly a readability choice. A conditional edge keeps the whole routing table visible in one place; Command keeps the decision local to the agent that makes it, which is natural for a swarm, but the edge is dynamic, so a static graph render will not show every possible destination — document them. Mixing the two in one graph is fine: a supervisor can return Command while its workers return to a shared conditional edge.
The example below is a complete three-agent swarm with deterministic workers — no model, no key. Each agent returns a Command; the state update and the next node come back together, and the notes list reduces across the hops. A real team swaps the worker bodies for model calls and keeps the handoff shape.
import operator
from typing import Annotated, TypedDict
from langgraph.graph import END, START, StateGraph
from langgraph.types import Command
class SwarmState(TypedDict):
request: str
active_agent: str
notes: Annotated[list[str], operator.add]
def intake(state: SwarmState) -> Command:
"""First hop: pick the specialist that owns refunds."""
return Command(goto="refunds", update={"active_agent": "refunds"})
def refunds(state: SwarmState) -> Command:
"""Refund specialist: check policy, then hand to order records."""
note = "policy: refunds within 30 days"
return Command(
goto="orders",
update={"active_agent": "orders", "notes": [note]},
)
def orders(state: SwarmState) -> Command:
"""Order specialist: confirm the order, then finish."""
note = "order A17: eligible, charged once"
return Command(goto=END, update={"active_agent": "done", "notes": [note]})
builder = StateGraph(SwarmState)
builder.add_node("intake", intake)
builder.add_node("refunds", refunds)
builder.add_node("orders", orders)
builder.add_edge(START, "intake")
graph = builder.compile()
result = graph.invoke(
{"request": "Refund order A17", "active_agent": "", "notes": []}
)
print(result["active_agent"])
print(result["notes"])
print(len(result["notes"]))Six failures account for most multi-agent incidents. Read this table as a pre-launch checklist, not a catalogue of exotic bugs: the first two are the most common, and the fifth — duplicate side effects — is the incident pattern the case study follows.
| Failure | What the trace shows | Fix |
|---|---|---|
| Ping-pong | Two agents hand a request back and forth without adding facts | Handoff budget plus a progress condition; route to a human or FINISH when no new fact was added |
| Context loss | The next worker ignores a fact the previous one already knew; the fact never appears in state | Name the fact in the schema and write it before the handoff; assert it in a test |
| Unknown destination | A runtime error or an edge that does not exist because goto named a node that is not in the graph | Validate against the node vocabulary; a model may only choose from an allowlist of names |
| Stale routing | goto and active_agent disagree; a resume routes on the old value | Return both in one Command, or derive the edge from the field written in the same step |
| Duplicate side effects | Two identical tool calls under one task, after a retry or a resume | Idempotency key and a check before the write; keep the write behind the approval gate |
| Silent stop | A worker returns without a handoff or a status, and the run ends on partial state | Require a terminal status; have the supervisor or synthesizer check completeness before END |
Every handoff is another superstep, and every superstep is another chance for the team to keep talking instead of finishing. recursion_limit catches the runaway at the runtime's boundary, but it is a backstop: the design-level bound is a budget in state that the team can see and report.
handoff_budget integer, initialised by the entry node, decremented on every handoff.handoff_log; the log is what makes a bad route debuggable without re-running the thread.END with status="needs_human" rather than raising a raw recursion error the caller cannot act on.Key takeaways
Supervisor and swarm are two topologies of one protocol: a handoff is a state update plus a transfer of control.
The shared state schema is the contract; facts that never enter it cannot cross a worker boundary, and private variables vanish on return.
Command(goto=..., update=...) returns both halves of a handoff in one value; graph=Command.PARENT hands off from inside a subgraph.
Know the six failure modes — ping-pong, context loss, unknown destination, stale routing, duplicate side effects and silent stop — and test the ones your topology makes likely.
Bound the team with a handoff budget in state, not only recursion_limit, and fail closed to a human when the budget runs out.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.