Ch 6 — LangGraph: Stateful Agent Flows
State machines with cycles, conditional routing, checkpoints, and human-in-the-loop
High Level
-
Click play or press Space to begin...
AWhy LangGraph?LCEL chains are linear — agents need loops
1linear_scale
LCEL ChainA → B → C → done
no loops, no branches
vs
account_tree
LangGraphNodes + edges + cycles
conditional routing
=
smart_toy
Real AgentsReason → Act → Observe
→ loop until done
2arrow_downward The three building blocks: State, Nodes, Edges
BThe Three Building BlocksState holds data, Nodes do work, Edges route
data_object
StateTypedDict with
messages, data fields
read/write
settings
NodesFunctions that take
state, return updates
route
call_split
EdgesFixed, conditional,
or entry/exit
3arrow_downward Building a basic StateGraph step by step
CBuilding a StateGraphDefine state → add nodes → add edges → compile
data_object
Define StateTypedDict with
Annotated reducers
→
add_circle
Add Nodesgraph.add_node
("name", fn)
→
route
Add EdgesFixed + conditional
routing logic
→
play_circle
Compilegraph.compile()
→ runnable app
4arrow_downward The ReAct agent pattern: reason → act → observe → loop
DThe ReAct Agent PatternThe most common agent loop in LangGraph
login
STARTUser message
enters graph
→
psychology
Agent NodeLLM decides:
tool or respond?
tools?
5build
Tool NodeExecute tools,
return results
loop
logout
ENDNo tools needed
→ final answer
6arrow_downward Checkpointing: save and resume graph state
ECheckpointing & MemoryPersist state across turns — conversation memory built in
save
CheckpointState saved after
every node execution
enables
history
Multi-TurnResume from last
checkpoint (thread_id)
+
undo
Time TravelReplay or rewind
to any past state
7arrow_downward Human-in-the-loop: interrupt, review, approve
FHuman-in-the-LoopPause the graph, let a human review, then resume
psychology
Agent DecidesWants to call
send_email tool
interrupt
front_hand
Pauseinterrupt_before
= ["tools"]
approve
8check_circle
ResumeHuman approves →
graph continues