LangGraph
LangGraph builds AI agents and workflows as graphs of nodes, edges and shared state, with checkpoints and human approval. Learn how it works and when to use it.
Overview
LangGraph is an open-source framework for building AI agents and multi-step workflows as graphs. Each step is a node, the possible paths between steps are edges, and a shared state object carries information from one step to the next. Because the state can be saved after every step, a LangGraph application can pause, wait for a person, survive a crash and resume where it stopped.
A good way to picture it is a metro map. Stations are the steps, lines are the allowed routes, and some stations are junctions where the next line depends on a decision. The passenger carries a ticket that records the journey so far. If service stops, the passenger can continue from the last station rather than starting over. In LangGraph, nodes are stations, edges are lines, conditional edges are junctions and the state is the ticket.
What it is
LangGraph is developed by LangChain, the company behind the LangChain library, and is available for Python and JavaScript. It is lower level than many agent frameworks: instead of giving you one fixed agent loop, it gives you the parts to define exactly how control flows.
| Concept | What it is |
|---|---|
| State | A typed object shared by all nodes, such as messages, documents, flags and results |
| Node | A function that reads the state, does work (call a model, run a tool, apply logic) and returns updates |
| Edge | A fixed transition from one node to the next |
| Conditional edge | A transition chosen at run time based on the state |
| Reducer | A rule for merging updates into state, for example appending messages instead of replacing them |
| Checkpointer | A store that saves state after each step |
| Interrupt | A pause point that waits for external input, often human approval |
| Subgraph | A graph used as a node inside another graph |
Graphs can contain cycles, which is what makes agent loops possible: a model node calls tools, a tool node runs them, and a conditional edge sends control back to the model until it decides to stop.
Where it came from
LangChain became popular in 2023 as a toolkit for chaining model calls, prompts and tools. As teams built more complex agents, they needed loops, branching, persistence and finer control than linear chains offered. LangGraph was released in early 2024 to fill that gap, borrowing ideas from graph-based computation models. It gained features for streaming, persistence, human-in-the-loop and multi-agent patterns, and reached a stable 1.0 release in late 2025. A companion platform offers deployment, monitoring and a visual studio, but the core library is open source and can run anywhere.
How it works
Defining state
You start by defining the state shape, for example a list of messages and a few fields such as customer_id or approved. Reducers specify how updates combine: messages are usually appended, while a status field is overwritten.
Adding nodes and edges
Each node is an ordinary function. One node might call a model with tools bound; another might execute tool calls; another might check a policy. Edges connect them, and conditional edges route based on the state, for example "if the model requested a tool, go to the tool node, otherwise finish".
Compiling and running
The graph is compiled into a runnable object. When invoked, it executes nodes step by step, applying state updates. Results can be streamed: tokens from the model, updates from each node, or custom events.
Persistence
With a checkpointer attached, the state is saved after each step, keyed by a thread id. This enables three things: conversations that continue across requests, recovery after failures, and inspection or replay of any past step, sometimes called time travel.
Human in the loop
An interrupt pauses execution at a chosen point, for example before a tool that sends money. The current state is saved. When a person approves, edits or rejects the action, the graph resumes from that point with the new input.
Key concepts and terms
| Term | Meaning |
|---|---|
| Graph | Nodes and edges defining the control flow. |
| State | Shared data passed between nodes. |
| Node | A step that reads state and returns updates. |
| Conditional edge | A run-time choice of next node. |
| Reducer | How updates merge into state. |
| Checkpointer | Persistent storage of state per step. |
| Thread | One conversation or run identified for persistence. |
| Interrupt | A pause for external input. |
| Subgraph | A nested graph used as a node. |
| Streaming | Sending intermediate output while the graph runs. |
A worked example
A company builds a refund agent.
- State: messages, order details, refund amount, approval status.
- Nodes:
understand(model reads the request),lookup_order(tool),check_policy(code that applies refund rules),request_approval(interrupt),issue_refund(tool),reply(model writes the response). - Edges:
understandgoes tolookup_order, then tocheck_policy. A conditional edge sends small refunds within policy straight toissue_refund, large or unusual ones torequest_approval, and requests outside policy toreplywith an explanation. - Persistence: every step is checkpointed under the customer's thread id.
- Run: a customer asks for a refund over the automatic limit. The graph pauses at
request_approval. A supervisor reviews the order the next morning and approves. The graph resumes from the saved state, issues the refund and replies to the customer.
The model handles language understanding and writing. Deterministic code handles policy. The graph makes the path explicit and auditable.
Strengths and limitations
Strengths
- Explicit control flow. You decide exactly which steps can follow which.
- Durable execution. Checkpoints allow pausing, resuming and recovery.
- Human approval built in. Interrupts fit approval workflows naturally.
- Mix of model and code. Deterministic steps and model steps live in one graph.
- Multi-agent support. Subgraphs and routing support supervisor and handoff designs.
- Model-agnostic. Works with many model providers.
Limitations
- More code. Lower-level design means more setup than one-line agent frameworks.
- Learning curve. State, reducers and graph thinking take time to learn.
- Complex graphs are hard to read. Large graphs need discipline and visual tools.
- Ecosystem coupling. Some conveniences assume other parts of the LangChain ecosystem.
How it compares with alternatives
| Framework type | Example tools | Best for |
|---|---|---|
| Graph-based orchestration | LangGraph | Custom, durable workflows with branching and approval |
| Role-based multi-agent | CrewAI | Quickly defining teams of agents with roles and tasks |
| Provider agent SDKs | Claude Agent SDK, OpenAI Agents SDK, Google ADK | Fast building on one provider's models and tools |
| Type-safe agent libraries | Pydantic AI | Python agents with strong typing and validation |
| Durable workflow engines | Temporal | Long-running business processes with strict reliability |
| Optimisation frameworks | DSPy | Optimising prompts and pipelines against metrics |
Practical guidance and best practices
- Draw the graph first. Sketch nodes and edges on paper before coding.
- Keep state small and typed. Store identifiers and key results, not huge documents.
- Put rules in code nodes. Use models for language, code for policy and arithmetic.
- Add checkpoints in production. Use a durable store, not in-memory persistence.
- Interrupt before side effects. Place approval points before payments, emails and deletions.
- Limit recursion. Set a maximum number of steps for cyclic graphs.
- Trace and test paths. Test every branch, including failure and rejection paths.
Common mistakes
- Putting everything in one model node. You lose the control the graph is meant to give.
- Storing large data in state. Checkpoints become slow and expensive.
- No recursion limit. Cycles can run indefinitely.
- In-memory checkpointing in production. State is lost on restart.
Frequently asked questions
What is LangGraph used for?
Building AI agents and workflows that need loops, branching, persistent state, human approval or several cooperating agents.
Is LangGraph the same as LangChain?
No. Both come from the same company. LangChain provides components for models, prompts and tools; LangGraph provides graph-based orchestration with state and persistence. They can be used together or separately.
Does LangGraph only work with OpenAI models?
No. It is model-agnostic and works with many providers and open models.
How does LangGraph support human-in-the-loop?
Through interrupts. The graph pauses at a chosen point, saves its state, and resumes when a person provides approval or edits.
When should I not use LangGraph?
When a simple single-agent loop or a fixed pipeline is enough. A lighter SDK or plain code can be faster to build and easier to maintain.
Glossary
- Checkpoint: a saved snapshot of state.
- Cycle: a path in a graph that returns to an earlier node.
- Durable execution: running workflows that survive failures and restarts.
- Orchestration: coordinating the order and flow of steps.
- Reducer: a function that merges a state update into existing state.
Summary
LangGraph models agents as graphs of nodes, edges and shared state. Conditional edges and cycles express agent loops; checkpoints make runs durable and resumable; interrupts add human approval. It suits teams that need explicit, auditable control over complex workflows, at the price of more code than higher-level frameworks. Draw the graph, keep state small, put rules in code and checkpoint everything in production.
Related
It belongs to Frameworks in my stack, under Agentic AI. Others in the same group: