By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A graph with one model node and a dozen tools works until the instructions for billing, policy research and order support start to collide in the same prompt. Every new tool competes for the model's attention, every prompt change risks a different specialism, and the trace shows one long model loop with no clear ownership. The supervisor pattern splits that work: a supervisor node decides who works next, and each specialist worker is a node or compiled subgraph with its own tools, prompt and sometimes its own model.
In LangGraph this is a graph of agents. The supervisor reads the shared state, picks a worker by name, and a conditional edge hands control to that worker. The worker returns to the supervisor, which decides again — another worker, or FINISH. The workers never call each other directly, so every collaboration is a named edge you can see in the graph and follow in a trace.
A handoff is two things at once. It is a routing decision — which node runs next — and a state update — where the shared record says the team is. In a hand-built supervisor both halves are explicit: the supervisor writes next_worker into state, and a conditional edge reads that field and maps it to a node.
next_worker (or next) is the router's input; it is a string because node names are the graph's vocabulary.Command(goto=..., update=...) instead of a dict to combine both halves in one return value.FINISH when the budget is spent; a team whose workers keep deferring is an infinite loop with extra steps.billing reads better than worker_2.The example below is a complete supervisor graph with deterministic workers — no model, no key. The supervisor routes on the request, the worker appends a finding to the shared list, and the loop finishes when the supervisor sees that a finding exists. Swap the workers for compiled subgraphs and the routing code stays the same.
from typing import TypedDict
from langgraph.graph import END, START, StateGraph
class TeamState(TypedDict):
request: str
next_worker: str
findings: list[str]
def supervisor(state: TeamState) -> dict:
"""One decision per turn: who works next, or FINISH."""
if state["findings"]:
return {"next_worker": "FINISH"}
if "refund" in state["request"].lower():
return {"next_worker": "billing"}
return {"next_worker": "researcher"}
def researcher(state: TeamState) -> dict:
return {"findings": [*state["findings"], "policy: refunds within 30 days"]}
def billing(state: TeamState) -> dict:
return {"findings": [*state["findings"], "order A17 is eligible"]}
builder = StateGraph(TeamState)
builder.add_node("supervisor", supervisor)
builder.add_node("researcher", researcher)
builder.add_node("billing", billing)
builder.add_edge(START, "supervisor")
builder.add_conditional_edges(
"supervisor",
lambda state: state["next_worker"],
{"researcher": "researcher", "billing": "billing", "FINISH": END},
)
builder.add_edge("researcher", "supervisor")
builder.add_edge("billing", "supervisor")
graph = builder.compile()
result = graph.invoke(
{"request": "Refund order A17", "next_worker": "", "findings": []}
)
print(result["next_worker"])
print(result["findings"])Command is the compact form of the same protocol. Returning a Command from a node replaces both the state update and the edge for that turn: goto names the next node and update merges into state. It is convenient when the handoff decision and the routing label are produced together.
from langgraph.graph import END
from langgraph.types import Command
from supervisor_graph import TeamState # the schema from above
def supervisor(state: TeamState) -> Command:
"""Return the handoff itself: where to go and what to record."""
if state["findings"]:
return Command(goto=END)
worker = "billing" if "refund" in state["request"].lower() else "researcher"
return Command(goto=worker, update={"next_worker": worker})Multi-agent designs fail in the seams, not inside the workers. The seam is the state schema: if a worker can only communicate through fields the schema names, the team stays reviewable. Anything a worker computes but does not write into the schema is invisible to the next worker and to the supervisor.
findings list annotated with operator.add lets several workers contribute without an InvalidUpdateError.next_worker, plan) so a test can assert on it.recursion_limit is a backstop; a handoffs counter or a step budget is the design.A supervisor is a coordination pattern, and coordination is not free: every handoff is another model turn, another chance to route wrongly, and one more hop to read in a trace. Use this table as a decision aid before splitting an agent.
| Situation | Better choice | Why |
|---|---|---|
| One domain and a handful of tools | A single agent with ToolNode | The tools are already the boundary; a supervisor adds routing overhead for no specialism |
| A fixed sequence of steps | A plain StateGraph with normal edges | Deterministic flow does not need a model to choose the next node |
| Workers need different models or prompts | Supervisor plus workers | Each worker keeps its own prompt, tools and model; the supervisor only routes |
| Latency or cost is tight | One agent, split only where it hurts | Every handoff is an extra model call; a team is slower and more expensive than one agent |
| Regulated decisions with a fixed escalation path | A deterministic graph with an interrupt | Policy belongs in edges and approval gates, not in a supervisor's judgement |
Key takeaways
A supervisor graph routes between specialist workers and makes one decision per turn: who works next, or FINISH.
A handoff is a routing decision plus a state update — a conditional edge, or Command(goto=..., update=...) from the node.
The shared state schema is the team's contract; facts that never enter it cannot cross a worker boundary.
Do not split by default: one agent with tools beats a supervisor for one domain, and every handoff costs a model turn.
Bound the loop with a handoff budget so two workers cannot defer to each other forever.
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.