LangGraph
Simple LLM agents are loops: call the model, run the tools it asks for, repeat. Production agents need more control than that. They must pause for a human to approve a refund, survive a process restart halfway through a long task, retry a flaky tool without redoing everything, branch deterministically on business rules, and show users progress as they work. LangGraph, from the LangChain team, models agent workflows as explicit graphs of steps over shared state, with built-in checkpointing so any run can be paused, inspected, resumed, or replayed.
LangGraph is low-level by design: you decide which steps exist, which are LLM calls and which are ordinary code, and how control flows between them. That makes it a good fit when reliability and oversight matter more than minimal code.
TL;DR
- A
StateGraphdefines typed state, nodes (functions that return state updates), and edges (including conditional routing). - Reducers control how updates merge into state, such as appending messages.
- A checkpointer saves state after each step; a thread ID identifies a run you can resume.
interrupt()pauses a run for human input;Command(resume=...)continues it.- Configure retry policies per node, stream progress, and compose subgraphs and parallel branches.
- Nodes may re-execute on resume, so side effects must be idempotent or placed after the interrupt.
Quick Example
A refund workflow with a human approval step:
The pause can last minutes or days: with a database-backed checkpointer, the run resumes from saved state in any process.
Core Concepts
State, Nodes, and Edges
Because routing is explicit, business rules — "refunds over $500 always need approval" — live in ordinary code instead of prompts.
Checkpointing and Threads
When compiled with a checkpointer (in-memory for tests; SQLite or PostgreSQL for production), LangGraph saves a checkpoint after each step. A thread is a sequence of checkpoints identified by thread_id. This enables:
- Resumption after crashes, deploys, or long pauses.
- Conversation memory across invocations on the same thread.
- Time travel: inspect past states, edit them, and fork new runs from earlier checkpoints.
- Fault tolerance: completed steps are not repeated when a later step fails.
See Durable Execution.
Human-in-the-Loop
interrupt(value) stops the run and surfaces value to the caller — a question, a draft, a proposed tool call. The application shows it to a person, then resumes with Command(resume=answer); the interrupt() call returns that answer. Common patterns are approve or reject a proposed action, edit a draft before it is used, and review tool calls before execution.
Reliability and Control
- Retry policies per node handle transient failures with backoff.
- Streaming modes emit state values, per-node updates, LLM tokens, or custom progress events to the UI.
- Subgraphs encapsulate reusable workflows with their own state.
- Parallel fan-out (the
SendAPI) runs a node for many items, such as summarizing each document, then gathers results. - Recursion limits stop runaway loops.
LangGraph and Other Approaches
Testing
- Test nodes as plain functions with fixed state inputs and fake model or tool clients.
- Test routing functions directly — they are pure functions of state.
- Run the compiled graph with an in-memory checkpointer and scripted model responses to test whole paths, including interrupt and resume.
- Evaluate LLM-dependent steps with datasets and graders. See LLM Evaluation.
Best Practices
Keep Deterministic Logic Out of Prompts
Use conditional edges and plain code for rules, thresholds, and permissions; reserve LLM calls for language understanding and generation.
Make Side Effects Idempotent
Use idempotency keys (the thread ID plus step) for payments, emails, and writes, because steps can run again on resume or retry. See Idempotency.
Use a Durable Checkpointer in Production
In-memory checkpoints vanish on restart. Use a database-backed checkpointer and plan retention for old threads.
Guard Tool Calls
Interrupt for approval before high-impact actions and validate tool arguments in code. See Agent Security and AI Guardrails.
Common Mistakes
Side Effects Before an Interrupt
Overwriting Accumulated State
Reusing Thread IDs Across Users
FAQ
What is LangGraph?
A framework for building stateful LLM applications and agents as graphs of steps over shared state, with checkpointing for persistence, human-in-the-loop interrupts, streaming, and fault tolerance.
How is LangGraph different from LangChain?
LangChain provides components and high-level abstractions for LLM applications — models, prompts, tools, retrievers, agents. LangGraph is the lower-level orchestration layer for building controllable, durable workflows, and can use LangChain components or none at all.
How does human-in-the-loop work in LangGraph?
A node calls interrupt() with information for a reviewer. The run pauses and its state is checkpointed. When the application resumes the thread with Command(resume=...), the interrupt returns the reviewer's answer and execution continues.
Do I need a checkpointer?
For interrupts, memory across invocations, and recovery from failures, yes. Use an in-memory checkpointer for tests and a database-backed one in production.
Can LangGraph run steps in parallel?
Yes. Nodes with edges from the same predecessor run in parallel within a step, and the Send API fans out a node over many inputs, with reducers merging the results.
Related Topics
- AI Agent Frameworks — Comparing agent frameworks
- AI Agents — Agent concepts and architectures
- Durable Execution — Resumable workflows in general
- Agent Design Patterns — Planning, reflection, and routing patterns
- Tool Calling — How models invoke tools
- Multi-Agent Systems — Coordinating several agents