Run it
From a clone of stackunseen/examples (on Windows, type python where it says python3):
git clone https://github.com/stackunseen/examples
cd examples
cd langgraph-supervisor
python3 -m pip install langgraph
python3 graph.pyWhat it prints
{'supervisor': {'question': 'How should I chunk documents?', 'context': [], 'answer': '', 'next': 'retrieve'}}
{'retrieve': {'question': 'How should I chunk documents?', 'context': ['Chunk the corpus by structure, not size.'], 'answer': '', 'next': 'retrieve'}}
{'supervisor': {'question': 'How should I chunk documents?', 'context': ['Chunk the corpus by structure, not size.'], 'answer': '', 'next': 'answer'}}
{'answer': {'question': 'How should I chunk documents?', 'context': ['Chunk the corpus by structure, not size.'], 'answer': 'Chunk the corpus by structure, not size.', 'next': 'done'}}This is the supervisor from Multi-agent orchestration without a framework, expressed as a LangGraph state graph instead of a loop your code owns. The retrieval step is a stub and the supervisor is a rule rather than a model call, so it runs offline and every run takes the same route.
Why a graph
When the routing matters more than the prompts, an explicit graph makes the control flow reviewable. Every edge is declared in code, every step shows up in the stream, and the state the nodes share has a type. A reviewer can see that retrieval always hands back to the supervisor and that only one node can end the run.
What to notice
The supervisor node is deterministic. In many systems it is a small model call, but a decision you can express in code should stay in code: it costs nothing to run and its tests are stable. Move to a model call only for the routing that genuinely needs judgment, and keep the rule as the fallback.
Graph or loop
The framework-free version and this one do the same work. The loop is less code and easier to step through in a debugger. The graph makes paths explicit and gives you the framework's checkpointing and streaming. LangGraph vs writing the agent loop yourself compares the two in more depth.
Taking it further
Replace the retrieve stub with the hybrid retriever from the RAG starter, so the context carries real passages with their citations. Then make the supervisor a model call for questions the rule cannot route, and test that every route still ends at the answer node.