A low-level orchestration framework and runtime for building, managing, and deploying long-running, stateful AI Agents.
LangGraph is a low-level orchestration framework open-sourced by LangChain Inc., designed specifically for building AI Agents with robust state management and complex control flows. Built on the Pregel computation model, it allows developers to define Agent logic either as graphs (nodes and edges) or as functions.
Its core advantages lie in exceptional runtime control capabilities: it supports Durable Execution for precise recovery after task failures; provides a Time Travel mechanism to revert to any historical checkpoint; and features built-in Human-in-the-loop interrupt capabilities to meet enterprise-level human approval requirements. Additionally, through the Subgraphs mechanism, LangGraph elegantly enables the orchestration and composition of Multi-Agent systems.
The framework does not force a dependency on LangChain and can run independently, but it is deeply integrated with the LangChain toolchain and the LangSmith observability platform. Typical application scenarios include multi-step tool calling, complex RAG pipeline orchestration, and long-running automated workflows. It has been adopted in production environments by major enterprises such as Klarna, Uber, and J.P. Morgan.
State & Persistence#
- Durable Execution: Supports persistent Agent state with automatic recovery from failure, resuming precisely from interruption points.
- Comprehensive Memory: Provides both short-term working memory (ongoing reasoning) and long-term persistent memory (cross-session) for truly stateful Agents.
- Time Travel: Supports reverting to any historical state for inspection or re-executing from specific checkpoints.
Flow Control & Orchestration#
- Human-in-the-loop: Execution can be paused at any node via interrupt mechanisms, supporting human inspection and modification of Agent state.
- Subgraphs: Supports decomposing complex Agent logic into composable subgraph modules, the core mechanism for Multi-Agent collaboration.
- Dual Definition Modes: Offers Graph API (graph structure: nodes + edges) and Functional API (single function definition) for defining Agents.
Runtime & Observability#
- Streaming: Supports real-time streaming of intermediate results during Agent execution.
- LangSmith Integration: Native LangSmith integration providing execution path visualization, state transition capture, and detailed runtime metrics.
- Production-ready Deployment: Supports enterprise-grade deployment and visual prototyping via the LangSmith Deployment platform.
Architecture & Implementation#
- Computation Model: Built on the Pregel computation model (inspired by Pregel, Apache Beam), with nodes as processing units and edges defining execution order and data flow.
- Interface Design: Public API design inspired by NetworkX, using intuitive graph theory interfaces (
add_node,add_edge). - State Management: State is essentially a
TypedDict. Node functions receive the full state and return partial updates; the runtime automatically controls state merge strategies viaAnnotatedtypes andoperator. - Core Runtime: The underlying core runtime is named
Pregel, fully responsible for graph scheduling, state persistence, interrupt handling, and fault recovery.
Installation & Quick Start#
pip install -U langgraph
from langgraph.graph import StateGraph, MessagesState, START, END
def mock_llm(state: MessagesState):
return {"messages": [{"role": "ai", "content": "hello world"}]}
graph = StateGraph(MessagesState)
graph.add_node(mock_llm)
graph.add_edge(START, "mock_llm")
graph.add_edge("mock_llm", END)
graph = graph.compile()
graph.invoke({"messages": [{"role": "user", "content": "hi!"}]})