LangGraph Tutorial Build Multi Agent System 2026
LangGraph models agent workflows as a directed graph with shared state, so loops, branches and human checkpoints become natural. This goes from three core concepts to a working research-write-review pipeline.
📜 Table of Contents
📖 Keep reading
LangGraph Tutorial 2026: Build a Multi-Agent System with Graph State
Most agent frameworks run linearly: receive task, call tool, return. Real work needs more — a failed review must send the draft back, an empty search must retry with new terms, a critical step must pause for human approval. LangGraph expresses all of that as a directed graph: nodes execute, edges route, and every node shares one state object.
1. Three concepts
| Concept | What it is | In code |
|---|---|---|
| State | shared data, nodes return partial updates | a TypedDict |
| Node | a function: state in, updates out | add_node(name, fn) |
| Edge | fixed or conditional transition | add_edge / add_conditional_edges |
The important detail: state is accumulated, not passed. A node's returned dict is merged into global state.
2. Design the state first
| Field | Type | Purpose |
|---|---|---|
topic |
str |
input, unchanged |
research |
str |
written by researcher |
draft |
str |
written by writer |
review |
str |
reviewer feedback |
rounds |
int |
loop counter |
approved |
bool |
pass/fail |
3. Nodes do one thing each
def researcher(state: State):
return {"research": f"notes on {state['topic']}"}
def writer(state: State):
return {"draft": f"draft built from: {state['research']}"}
def reviewer(state: State):
ok = state["rounds"] >= 2
return {"review": "ok" if ok else "needs data",
"approved": ok, "rounds": state["rounds"] + 1}
LangGraph does not increment counters for you — whatever you return is the new value.
4. Wire the graph: conditional edges are the point
from langgraph.graph import StateGraph, END
g = StateGraph(State)
g.add_node("researcher", researcher)
g.add_node("writer", writer)
g.add_node("reviewer", reviewer)
g.set_entry_point("researcher")
g.add_edge("researcher", "writer")
g.add_edge("writer", "reviewer")
def route(state):
return "end" if state["approved"] or state["rounds"] >= 3 else "writer"
g.add_conditional_edges("reviewer", route, {"writer": "writer", "end": END})
app = g.compile()
Every value a router returns must exist as a key in the mapping — that mismatch is the most common runtime error. And a loop needs two exits: pass, or hit the round cap. With only the pass exit, a stubborn reviewer spins forever.
5. Watch it run
app.stream(inputs, stream_mode="values") yields the full state each step; "updates" yields only per-node deltas, which makes cleaner logs.
6. Checkpoints and human approval
from langgraph.checkpoint.memory import MemorySaver
from langgraph.types import interrupt, Command
def approve_gate(state):
return {"approved": bool(interrupt({"draft": state["draft"], "question": "publish?"}))}
app = g.compile(checkpointer=MemorySaver())
cfg = {"configurable": {"thread_id": "job-001"}}
app.invoke(inputs, cfg) # pauses at interrupt
app.invoke(Command(resume=True), cfg) # human said yes
MemorySaver is in-process only; use a database-backed checkpointer in production.
7. When not to use it
Single-turn Q&A with no branching, plain RAG chains, or teams without a state-machine mindset. LangGraph pays off when the workflow itself is genuinely complex.
FAQ
Node returns None? State is unchanged and nothing errors, which usually means a missing return — always return a dict.
Concurrent writes? Nodes writing the same field compete; attach a reducer such as Annotated[list, operator.add] when writes should accumulate.
One graph per agent? Either subgraphs for isolation or several role nodes in one graph for shared context.
Debugging? Start with stream_mode="values" logs, then look at the rendered graph.
vs CrewAI / AutoGen? LangGraph for precise control and human checkpoints; CrewAI or AutoGen for fast prototypes where the model picks the next speaker.
Related
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.