Why does LangGraph expose the agent loop as a graph instead of a while loop?
LangGraph is LangChain's StateGraph library; it exposes the agent loop as an inspectable graph of nodes, edges, and shared state, with checkpointers for pause/resume and human in the loop interrupts.
Picture two flowcharts taped to a wall. The first one is a single black box labeled "run the agent" with an arrow looping back to itself, you have no idea what happens inside. That is LangChain's AgentExecutor. The second flowchart has labeled boxes for each step, arrows showing which box leads to which, save points where you can pause the whole thing, and a way for a human to step in mid-process. That is LangGraph. Same agent behavior, but every step is visible, pausable, and resumable instead of buried inside a hidden loop.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
LangGraph is the answer to a specific question: "How do I take a LangChain agent that works in a notebook and run it in production without it being a black box?" The library reframes the agent loop as an explicit graph of typed state transitions, layered on top of the same LCEL Runnable interface every other LangChain component uses.
Understanding LangGraph cleanly means understanding its five primitives, the relationship to LangChain (layered, not competing), and the production needs that make graph-based control flow worth the verbosity. This explanation walks each in turn.
The five primitives that make a graph
Nodes are the units of work. Each node is a function (or any LCEL Runnable) that takes the current state and returns a partial state update. A node can call an LLM, invoke a tool, run arbitrary Python, or wrap another compiled graph (subgraphs are first-class).
Edges declare forward transitions: "after node A runs, go to node B". This is the simple case, used for fixed pipelines.
Conditional edges declare routing: "after node A runs, call this routing function on the state, and go to whichever node it names". This is how the graph expresses branching and cycles. The routing function is plain Python that inspects state and returns a node name (or END).
State is a typed object, usually a TypedDict with declared Annotated reducers. The state is shared across all nodes in the graph. Reducers say how to merge an update into the canonical state, append to a list, take the max, overwrite, or any custom function.
Checkpointers persist the full state at each step to a backend. InMemorySaver for development, SqliteSaver / PostgresSaver / RedisSaver for production. The checkpointer is what makes pause / resume / interrupt / time-travel work, all of those features build on the durable state substrate.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- LangGraph's official template repo includes a customer-support agent that uses `interrupt_before` to gate refund actions on a human's approval before the agent executes them.
- Replit's Agent product uses LangGraph for its multi-step coding agent because checkpointing lets sessions resume after IDE reconnects.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does a LangGraph checkpointer differ from logging? Why isn't "log the agent state to a database" equivalent?
Checkpointers are the durable substrate the graph runtime uses to resume execution, every node read/write goes through them and they are addressable by thread_id. Logging is observability-only, you can read it but the runtime can't rehydrate execution state from logs. The checkpointer is what makes graph.update_state and graph.get_state_history work.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Describing LangGraph as "a different framework from LangChain". It is built on LangChain's LCEL Runnables, the relationship is one of layering, not competition.
60 second bullets to scan on the way to the call.
The five LangGraph primitives and what each one represents.
Why state reducers matter when multiple updates land concurrently.
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.