Stateful Graph Orchestration — Durable Execution and Checkpoints
Agent is a state machine; nodes are functions; edges are transitions; state is checkpointed after each node. Resume from any failure at the last successful checkpoint. LangGraph is the 2026 reference for this model of low-level stateful orchestration.
Lesson 13 of 54Learn + Build~75 minutesPython (stdlib)
Before this: Lesson 1 of Phase 14 (Agent Loop), lesson 12 of Phase 14 (Workflow Patterns)
On this page
Learning Objectives
- Describe LangGraph's core model: state machine with typed state, function nodes, conditional edges, and post-node checkpoints.
- Name the four capabilities the docs highlight: durable execution, streaming, human-in-the-loop, comprehensive memory.
- Explain the three orchestration topologies LangGraph supports: supervisor, peer-to-peer (swarm), hierarchical (nested subgraphs).
- Implement a stdlib state graph with typed state, conditional edges, and a checkpoint/resume cycle.
The Problem
Agents and workflows share a problem: when a 40-step run fails at step 38, you want to resume from step 38, not start over. Second-class state models leave operators hacking retries around a library that assumes fresh runs.
LangGraph's design answer: state is a first-class typed object, mutations are explicit, and checkpoints persist after every node. Resume is a load_state(session_id) call.
The Concept
The graph
A graph is defined by:
- State type. A typed dict (or Pydantic model) that every node reads and mutates.
- Nodes. Pure functions
(state) -> state_update. Updates are merged into state after return. - Edges. Conditional or direct transitions between nodes.
- Entry and exit.
STARTandENDsentinel nodes mark the boundary.
Example: an agent with classify, refund, bug, sales, done nodes — a routing workflow as a graph.
Durable execution
After each node returns, the runtime serializes the state and writes it to a checkpointer (SQLite, Postgres, Redis, custom). On failure at step N, the runtime can resume(session_id) and pick up from step N+1 with exact state.
The LangGraph docs explicitly highlight production users where this matters: Klarna, Uber, J.P. Morgan. The claim isn't the graph shape; it's that the graph shape plus checkpointing makes recovery cheap.
Streaming
Every node can yield partial output. The graph streams per-node-delta events to the caller so UIs update as the graph runs.
Human-in-the-loop
Inspect and modify state between nodes. Implementations: pause before a critical node, surface state to a human, accept modifications, resume. The checkpointer makes this easy because state is already serialized.
Memory
Short-term (within a run — conversation history in state) and long-term (across runs — persistent via the checkpointer plus a separate long-term store). LangGraph integrates with external memory systems (Mem0, custom) via tools.
Three topologies
- Supervisor. Central router LLM dispatches to specialist subagents.
create_supervisor()inlanggraph-supervisor(though the LangChain team in 2026 recommends doing this through tool calls directly for more context control). - Swarm / peer-to-peer. Agents hand off directly via a shared tool surface. No central router.
- Hierarchical. Supervisors managing sub-supervisors, implemented as nested subgraphs.
Where this pattern goes wrong
- Checkpoints too small. Only checkpointing conversation turns leaves tool state and memory writes unrecoverable. Full state must serialize.
- Non-deterministic nodes. Resume assumes node inputs produce the same state update. Random seeds, wall-clock, external APIs must be captured.
- Over-use of conditional edges. A graph with every edge conditional is a state machine that cannot be reasoned about. Prefer linear chains with occasional branches.
langgraph-state
Build It
code/main.py implements a stdlib stateful graph:
State— a typed dict withmessages,step,route,output,human_approval.Node— callable taking state and returning an update dict.StateGraph— nodes + edges + conditional edges + run + resume.SQLiteCheckpointer(in-memory fake) — serializes state after every node;load(session_id)restores.- A demo graph: classify -> branch(refund / bug / sales) -> human gate -> send.
Run it:
python3 code/main.py
The trace shows the first run failing at the human gate, persistence, then resume producing the final output.
Use It
- LangGraph — the reference, production-ready. Use
create_react_agent,create_supervisor, or build your own graph. - AutoGen v0.4 (Lesson 14) — actor model alternative for high-concurrency scenarios.
- Claude Agent SDK (Lesson 17) — managed harness with built-in session store.
- Custom — when you need exact control over state shape or checkpointer backend.
Ship It
outputs/skill-state-graph.md generates a LangGraph-shaped state graph in any target runtime with checkpointing and resume wired in.
Exercises
- Add a conditional edge from
classifytoendwhen classification confidence is below a threshold. Resume the run after a human setsroutemanually. - Swap the SQLite-like fake for a real SQLite checkpointer. Measure per-step serialization overhead.
- Implement parallel edges: two nodes run concurrently, merge by a custom reducer. What does immutable state buy here?
- Read
langgraph-supervisorreference. Port the toy tocreate_supervisor. Compare the trace shapes. - Add streaming: each node yields partial state while it runs. Print the deltas as they arrive.
Key Terms
| Term | What people say | What it actually means |
|---|---|---|
| State graph | "Agent as state machine" | Typed state + nodes + edges + reducers |
| Checkpointer | "Persistence backend" | Serializes state after every node; enables resume |
| Reducer | "State merger" | Function that combines current state with a node's update |
| Conditional edge | "Branch" | Edge chosen by a function of state |
| Subgraph | "Nested graph" | A graph used as a node inside another graph |
| Durable execution | "Resume from failure" | Restart at the last successful node with exact state |
| Supervisor | "Router LLM" | Central dispatcher for specialist subagents |
| Swarm | "P2P agents" | Agents hand off via shared tools; no central router |
Further Reading
- LangGraph overview — the reference docs
- langgraph-supervisor reference — supervisor pattern API
- AutoGen v0.4, Microsoft Research — actor-model alternative
- Claude Agent SDK overview — session store and subagents
Check yourself
Quick quiz
What does LangGraph treat as the core unit of the agent?
- A vector index
- A state machine with typed state, function nodes, and conditional edges
- A single tool registry
- A free-form LLM call
Show the answer
B. A state machine with typed state, function nodes, and conditional edges LangGraph models the agent as a state graph: nodes are pure functions, edges are transitions, state is typed and immutable.
Which problem does durable execution solve?
- Reducing inference cost
- Generating embeddings faster
- Resuming a 40-step run from step 38 when it fails, with exact state, instead of starting over
- Translating between providers
Show the answer
C. Resuming a 40-step run from step 38 when it fails, with exact state, instead of starting over Checkpoints after every node let the runtime resume from the last successful step.
Which of these is NOT one of the three topologies LangGraph supports?
- Gradient ring
- Hierarchical (nested subgraphs)
- Supervisor
- Swarm (peer-to-peer)
Show the answer
A. Gradient ring Topologies are supervisor, swarm, and hierarchical. Gradient ring is not a LangGraph topology.
Why must nodes be deterministic for resume to work cleanly?
- It is required by the GIL
- Determinism reduces token cost
- Resume assumes the same inputs produce the same state update; random seeds, wall-clock, and external APIs must be captured
- Providers require determinism
Show the answer
C. Resume assumes the same inputs produce the same state update; random seeds, wall-clock, and external APIs must be captured If a node depends on uncaptured nondeterminism, resume cannot reconstruct the post-step state.
What is a conditional edge?
- An edge with a TTL
- An edge chosen by a function of state, used to branch the graph
- An edge that runs only on GPUs
- An edge weighted by training loss
Show the answer
B. An edge chosen by a function of state, used to branch the graph Conditional edges branch based on state; overusing them makes the graph hard to reason about.
What goes wrong when checkpoints are too small?
- The disk fills up
- The graph cannot reach END
- Tool state and memory writes are not recoverable; full state must serialize
- The model produces shorter answers
Show the answer
C. Tool state and memory writes are not recoverable; full state must serialize Only checkpointing conversation turns leaves tool state and memory writes outside resume's reach.
Where does human-in-the-loop fit into LangGraph's design?
- Pause before a critical node, surface serialized state to a human, accept modifications, resume; the checkpointer makes this cheap
- Only at START and END
- Through a separate provider API
- It requires a fork of the runtime
Show the answer
A. Pause before a critical node, surface serialized state to a human, accept modifications, resume; the checkpointer makes this cheap Because state is already serialized between nodes, human review and edit is a natural pause-and-resume pattern.
Questions people ask
What is LangGraph used for?
LangGraph is a framework for building agents as graphs of steps with shared state. It saves checkpoints so runs can pause, resume after errors, or wait for human approval. Teams use it when they want tight control over agent flow.
How do you add human approval to an AI agent?
Put a pause point before risky steps, such as sending money or emailing a client. The system saves its state, shows the proposed action to a person, and continues only after approval. Checkpointed frameworks make this easy to build.
Lessons from AI Engineering from Scratch by Rohit Ghumare and contributors, MIT license. Notes for owners by Lozo. License