LangGraph

On this page 7

LangGraph is an open-source orchestration library for building stateful, multi-step applications around large language models, in which the control flow is expressed as a graph of nodes and edges that read and update a shared state. Among AI frameworks & tools, it occupies the low-level orchestration layer: it does not wrap a model or define prompts, but decides which step runs next, what data each step sees, and how a long-running process pauses, resumes and recovers.

The library was released by the team behind LangChain and is available for Python and JavaScript/TypeScript. It can be used with or without LangChain components, and it is most often chosen for agent loops, human-in-the-loop approval and multi-agent systems where a simple linear chain is not enough.

How LangGraph executes a graph

A LangGraph application is defined as a StateGraph: a state schema, a set of nodes that are ordinary functions, and edges that connect them between the special START and END markers. Each node receives the current state and returns a partial update, which the runtime merges into the state before the next step.

Execution follows a model inspired by Pregel and bulk synchronous processing. The graph advances in discrete super-steps: all nodes scheduled for a step run, possibly in parallel, their updates are applied together, and the edges then decide which nodes run in the next step. Because routing is evaluated after every step, the graph may contain cycles, which is what allows an agent to call a tool, inspect the result and decide to call another one.

The following table lists the core building blocks and the role each one plays at runtime.

ComponentWhat it isRole at runtime
State schemaTypedDict, dataclass or Pydantic modelDefines the shared data every node reads
ReducerMerge function attached to a state keyCombines updates, for example appending messages
NodePython or JavaScript functionPerforms one unit of work and returns an update
Normal edgeFixed connection between two nodesAlways routes to the same next node
Conditional edgeRouting function over the stateChooses the next node or ends the run
CheckpointerPersistence backendSaves a snapshot after every super-step
Core building blocks of a LangGraph application

Reducers are a frequent source of confusion. Without a reducer, a node update overwrites the key; with a reducer such as add_messages, the update is appended or merged into the existing value. Choosing the wrong behavior is a common cause of lost conversation history or duplicated messages.

Persistence, interrupts and memory

LangGraph treats persistence as a first-class feature rather than an add-on. When a graph is compiled with a checkpointer, the runtime writes a checkpoint of the full state after every super-step and groups those checkpoints under a thread_id, so a conversation or job can be continued later from exactly where it stopped.

This mechanism enables several capabilities that are difficult to build by hand. The table summarizes them.

CapabilityHow it worksTypical use
Durable executionResumes from the last saved step after a failureLong jobs that call slow or unreliable APIs
Human-in-the-loopThe interrupt function pauses and waits for inputApproving a payment or an email before it is sent
Time travelReplays or forks from an earlier checkpointDebugging a wrong decision in an agent run
Short-term memoryThread-scoped state reloaded on each callMulti-turn chat with full message history
Long-term memorySeparate key-value store shared across threadsUser preferences remembered between sessions
Capabilities built on checkpointing

Checkpointers exist for in-memory, SQLite and PostgreSQL backends, among others. The in-memory saver is suitable only for tests, because all state disappears when the process stops. For production, a database-backed checkpointer is the expected choice, and its storage growth must be planned, since every step of every thread produces a snapshot.

LangGraph is a low-level, explicit orchestration framework, whereas many neighboring agent tools offer higher-level abstractions with less control. The table contrasts it with frequently compared options in the same category.

FrameworkMain abstractionControl over flowBest fit
LangGraphExplicit graph with shared stateHighCustom agents with branching and approvals
LangChainComponents and prebuilt agentsMediumModel, tool and retriever integrations
CrewAIRole-based crews and tasksLowerQuick multi-agent prototypes
AutoGenConversing agentsMediumResearch on agent dialogue patterns
OpenAI Agents SDKAgents with handoffsMediumLightweight agents on one provider
Positioning against related agent frameworks

The relationship with LangChain is complementary, not competitive. Current LangChain agent constructors run on the LangGraph runtime, while LangGraph itself can call any model client. Observability is usually added through LangSmith or an open alternative such as Langfuse, which record each node, model call and token count as a trace.

Common patterns and when to use them

Most LangGraph applications are built from a small set of recurring patterns, and choosing the simplest one that fits the problem keeps the graph readable and testable. The decision table below maps typical situations to a pattern.

SituationRecommended patternReason
Model must call tools until doneReAct-style tool loopA conditional edge returns to the model after each tool call
Fixed sequence of known stepsLinear workflowNo routing logic is needed
Many independent subtasksMap-reduce with SendFans out parallel nodes, then aggregates results
Specialized agents for different jobsSupervisor with subgraphsA router delegates to compiled child graphs
Risky or irreversible actionsInterrupt before the actionA person approves or edits the pending step
Choosing a graph pattern

A practical rule is to start with a deterministic workflow and add model-driven routing only where the decision genuinely requires judgment. Graphs in which every edge is chosen by a model are harder to test and costlier to run than graphs that combine fixed edges with a few well-defined decision points.

Limitations and common mistakes

LangGraph gives precise control at the cost of more code and a steeper learning curve than higher-level agent frameworks. Teams that need only a single prompt or a short retrieval chain gain little from a graph runtime.

  • Unbounded loops: a cycle without a clear exit hits the recursion limit, which defaults to 25 super-steps in many versions and raises an error rather than stopping silently.
  • Oversized state: storing large documents in state inflates every checkpoint; storing references or identifiers is safer.
  • Side effects before an interrupt: when a run resumes, the interrupted node runs again from its start, so non-idempotent calls placed before the interrupt may execute twice.
  • Missing thread identifiers: invoking a checkpointed graph without a thread_id breaks conversation continuity.
  • Version drift: APIs changed noticeably before the 1.0 release, so older tutorials may use deprecated imports.

A plain-language summary

LangGraph is a tool for programmers who want an AI assistant to work through a task in clear, controlled steps. Instead of asking a model one question and hoping for a good answer, the developer draws a kind of flowchart: one box gathers information, another calls a calculator or a database, another checks the result, and arrows decide what happens next.

The key benefit is that the process remembers where it is. It can stop and wait for a person to approve something, survive a crash, and continue later without starting over. In short, LangGraph turns an unpredictable chatbot into a reliable, step-by-step worker.

An example from practice

An insurance company builds a claims assistant that handles about 2,000 small property claims per week. The LangGraph application has five nodes: one extracts details from the claim form, one retrieves the policy terms, one asks a language model to assess coverage, one drafts the decision letter, and one sends it. A conditional edge routes any claim above a set amount, for example 5,000 dollars, to an interrupt that waits for a human adjuster.

Because every step is checkpointed in PostgreSQL, adjusters can open a paused claim days later and continue it with one click, and engineers can replay a disputed decision from the exact state the model saw. After rollout, the team reports that routine claims are processed in minutes rather than days, while every high-value payout still receives human approval, which satisfies the internal audit requirement.