Multi-Agent Systems with LangGraph
Design multi-agent pipelines using the LangGraph Supervisor pattern. Covers StateGraph construction, TypedDict shared state, add_messages reducer, checkpointers, human-in-the-loop interrupts, parallel branches, and error routing between specialist agents.
Overview
Overview
Multi-agent systems split a complex task across specialist agents that each own one narrow concern. LangGraph wires them together: agents become graph nodes and messages flow through shared state, which gives you explicit control over routing, state and persistence that a single monolithic agent chain cannot provide.
LangGraph fundamentals
LangGraph models execution as a directed graph. Each node takes the current state and returns a partial update; edges can be conditional, so the graph picks the next node from a state value.
- StateGraph — The graph builder
- Compiled graph (.compile()) — The runnable, with stream and invoke
- State TypedDict — The shared data model every node reads
- Checkpointer (optional) — Persistence of state between steps
- Nodes: Python functions or Runnables that receive the full state dict and return a partial dict of updates.
- Reducers: LangGraph merges each partial update into state. The built-in add_messages reducer appends to the messages list instead of replacing it.
> [!NOTE] add_messages is the primitive that makes multi-turn conversation inside a graph possible.
The supervisor pattern
The supervisor is a router node above all specialists. It reads the latest message, picks who acts next and never does the work itself; every specialist returns to it when done.
- 1 — Supervisor — Routes to the Researcher
- 2 — Researcher — Uses web search tools, appends a structured research summary
- 3 — Supervisor — Reads the summary, routes to the Writer
- 4 — Writer — Drafts the report and appends the draft
- 5 — Supervisor — Routes back to the Researcher for a gap-fill pass, or ends with the final draft
Shared state and message passing
All inter-agent communication rides in the state TypedDict. A minimal schema:
- Message types: messages holds HumanMessage, AIMessage and ToolMessage objects.
- No direct calls: agents never call each other; they only read and append to shared state.
Checkpointers for state persistence
A checkpointer saves the full state snapshot at every superstep. You pass it at compile time, for example graph.compile(checkpointer=SqliteSaver.from_conn_string("checkpoints.db")).
- MemorySaver — In-memory dict — Development and testing
- SqliteSaver — File on disk, survives restarts — Single-process deployments
- PostgresSaver — PostgreSQL, concurrent writers — Production, horizontally scaled
> [!TIP] Every invoke or stream call takes a config with a thread_id: the same thread_id resumes a session, a new one starts fresh.
Human-in-the-loop
interrupt_before and interrupt_after pause execution at a named node boundary. Compiled with interrupt_before=["writer"], the graph halts before the Writer runs; the caller can inspect state, change it with graph.update_state() and resume by calling invoke again with the same thread_id.
> [!TIP] Use interrupt_before=["writer"] to show users the research summary and get approval before a full draft is written, a zero-cost human quality gate.
Error handling and fallback routing
The supervisor's routing function can check the last message for error markers. Conditional edges accept a Python function that returns the next node name as a string.
> [!WARNING] Keep a max_iterations counter in state and route to END past a threshold. Without it, a misbehaving supervisor can loop forever between specialists.
Interview questions
- Design a multi-agent system where a Researcher agent gathers data from the web, and a Writer agent drafts a report. How do they communicate, and how do you handle state?
- How does state persistence work in LangGraph? What is the difference between MemorySaver and SqliteSaver?
- How do you run the Researcher and Writer agents in parallel instead of sequentially?
- How do you add a human approval checkpoint between the Researcher and Writer stages?
Sign up free to read the full topic
More Agentic AI topics
Start free on Cariara · Coding problems · System design studio