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

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:

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

LangGraph and Other Approaches

Testing

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

References