Walk through the LangGraph supervisor pattern for multi-agent orchestration
Describe the LangGraph supervisor pattern end to end: the graph topology, how routing decisions are made, how state flows between supervisor and workers, and why teams choose this pattern over AutoGen GroupChat or a CrewAI hierarchical crew.
A supervisor LLM node routes to one of N worker nodes via a conditional edge based on its structured output; workers update shared state and return to the supervisor; the loop terminates when the supervisor outputs
Picture a newsroom. The editor (supervisor) reads what is on the table and says 'researcher, dig into this' or 'writer, draft a paragraph' or 'critic, check the facts'. Each person does their bit, hands the work back to the editor, and the editor decides who is next. Eventually the editor says 'good, we publish'. The whole thing is happening on one shared whiteboard everyone can see, and somebody is taking photos of the whiteboard after each handoff so the work survives even if the building burns down. That photo log is the checkpointer.
Detailed answer & concept explanation~6 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.
6 minutes: draw the topology, walk supervisor routing via structured output, describe state and reducers, name the checkpointer benefits, and contrast with AutoGen GroupChat and CrewAI Hierarchical on the production-fit axes.
from typing import Annotated, Literal
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, END
from langgraph.graph.message import add_messages
from langgraph.checkpoint.postgres import PostgresSaver
from langchain_openai import ChatOpenAI
from pydantic import BaseModel
class State(TypedDict):
messages: Annotated[list, add_messages]
next: str
class Route(BaseModel):
next: Literal['researcher', 'writer', 'critic', 'FINISH']
llm = ChatOpenAI(model='gpt-4o').with_structured_output(Route)
def supervisor(state: State) -> dict:
decision = llm.invoke([
{'role': 'system', 'content': 'Route to researcher, writer, critic, or FINISH.'},
*state['messages'],
])
return {'next': decision.next}
def researcher(state): ... # returns {'messages': [AIMessage(...)]}
def writer(state): ...
def critic(state): ...
builder = StateGraph(State)
for name, fn in [('supervisor', supervisor), ('researcher', researcher), ('writer', writer), ('critic', critic)]:
builder.add_node(name, fn)
builder.set_entry_point('supervisor')
for w in ['researcher', 'writer', 'critic']:
builder.add_edge(w, 'supervisor')
builder.add_conditional_edges(
'supervisor',
lambda s: 'END' if s['next'] == 'FINISH' else s['next'],
{'researcher': 'researcher', 'writer': 'writer', 'critic': 'critic', 'END': END},
)
with PostgresSaver.from_conn_string(DB_URL) as cp:
graph = builder.compile(checkpointer=cp, interrupt_before=['supervisor'])Real products, models, and research that use this idea.
- LangChain's multi-agent supervisor tutorial uses researcher and chart-generator workers behind a supervisor LLM
- Production teams deploying long-running research agents on Claude Opus 4.7 use supervisor patterns with Postgres checkpointers for crash recovery
- LangGraph Cloud's hosted templates ship supervisor patterns as a first-class scaffold
- Code-review automations use a critic and revise loop where the supervisor routes between code-author and code-reviewer until FINISH
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does the supervisor pattern handle parallel worker execution?
QWhat changes if you replace the supervisor LLM with a deterministic routing function?
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.
Letting the supervisor return free-form text instead of a structured route. The conditional edge needs a typed signal, not a string parse.
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.