LangGraph — Build Stateful AI Agents as Graphs
LangChain framework for building resilient, stateful AI agents as graphs. Supports cycles, branching, persistence, human-in-the-loop, and streaming. 28K+ stars.
Ready-to-run agent install
This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.
npx -y tokrepo@latest install cc1a6ed2-0d82-4379-94f4-15632b4d4967 --target codexRun after dry-run confirms the install plan.
Why graphs beat chains for agents
LangChain's original Chain abstraction assumed linear sequences: step A → step B → step C. But real AI agents loop ("retry until valid"), branch ("if answer is long, summarize"), and wait ("ask human for approval"). LangGraph drops the linear assumption and models agents as directed graphs with state, borrowing from dataflow systems and actor models.
The hello world
from langgraph.graph import StateGraph, START, END
from typing import TypedDict, List
class State(TypedDict):
messages: List[str]
def chatbot(state: State):
return {"messages": [llm.invoke(state["messages"])]}
graph = StateGraph(State)
graph.add_node("chatbot", chatbot)
graph.add_edge(START, "chatbot")
graph.add_edge("chatbot", END)
app = graph.compile()
The state flows through nodes. Each node mutates or enriches state. Edges route based on conditions you define.
Core features that make it production-ready
Persistence
State is automatically checkpointed. If a node crashes mid-execution, you resume from the last checkpoint. Supports PostgreSQL, SQLite, and Redis checkpointers.
Human-in-the-loop
interrupt_before and interrupt_after pause execution at any node, waiting for external input (approval, edit, rejection) before continuing.
Streaming
Stream state updates, tokens, or both. Built-in support for Server-Sent Events (SSE) means your UI updates in real time as the agent works.
Time travel
Replay past executions with different inputs. Critical for debugging complex multi-step agents.
LangGraph vs LangChain (the relationship)
LangChain is the library of building blocks (LLM wrappers, tool schemas, prompt templates). LangGraph is the orchestrator for connecting those blocks into a running agent. Since 2024 LangChain's official recommendation for agents has been "use LangGraph, not Chains."
Real-world patterns
Pattern 1: ReAct agent with validation loop
plan → execute tool → validate output → [loop back to plan if invalid]
Pattern 2: Multi-agent team with supervisor
supervisor → {researcher | coder | reviewer} → supervisor → END
Pattern 3: Human approval gate
research → draft → interrupt_before(publish) → publish | reject → END
Pattern 4: Parallel branch + merge
research → {search_google, search_docs, search_memory} → merge → synthesize
Deployment options
- LangGraph Cloud (LangChain-hosted) — $39/mo starting, includes observability.
- Self-hosted via Docker — single-command deploy, Postgres checkpointer recommended.
- Inline in your app — just
pip install langgraph, compile your graph, call.invoke()or.stream().
Observability via LangSmith
Every node execution is traced in LangSmith (LangChain's observability platform). Token usage, latency, tool calls — all visible in a timeline view. Costs $0 for small projects, scales with usage.
When LangGraph is overkill
If your agent is:
- 1 tool call and done — use the provider SDK directly
- A single LLM completion — use LangChain's simpler
LLMChain - Purely reactive (no state) — use an event queue
But once you need retries, branching, or human intervention, LangGraph pays off fast.
Frequently Asked Questions
Use LangChain for the building blocks — LLM wrappers, tool definitions, prompt templates. Use LangGraph to orchestrate those blocks into agents with loops, branching, or human approval. Since 2024 LangChain's official recommendation for any non-trivial agent is to use LangGraph rather than the deprecated Chain abstractions.
Yes. State is automatically checkpointed between nodes, with backends for PostgreSQL, SQLite, and Redis. If a node crashes or your server restarts, the agent resumes from the last checkpoint rather than from scratch.
Use interrupt_before or interrupt_after on any node. Execution pauses, returns control to your application, and resumes when you provide input. This is how you build approval gates, edit-then-continue flows, or rejection branches.
Every node execution is automatically traced to LangSmith when a LANGCHAIN_API_KEY is set. You get token usage, latency per node, tool call traces, and a timeline view. LangSmith has a free tier for small projects.
Yes, technically. LangGraph only depends on langchain-core (which is lightweight). You can model any stateful graph without using LangChain's full LLM or prompt abstractions. However, most users pair the two.
Citations (3)
- LangGraph GitHub— 28K+ GitHub stars
- LangChain Docs— LangChain official recommendation since 2024 is LangGraph for agents
- LangGraph Persistence Docs— Persistence backends: PostgreSQL, SQLite, Redis
Related on TokRepo
Source & Thanks
Created by LangChain. Licensed under MIT. langchain-ai/langgraph — 28,000+ GitHub stars
Discussion
Related Assets
LangGraph — Build Stateful AI Agent Workflows
Framework for building stateful, multi-step AI agent workflows as graphs. LangGraph enables cycles, branching, human-in-the-loop, and persistent state for complex agent systems.
LangGraph — Stateful AI Agent Graphs by LangChain
Framework for building stateful, multi-actor AI agent applications as directed graphs. Supports cycles, branching, persistence, and human-in-the-loop patterns. By LangChain. 8,000+ stars.
Letta — Stateful AI Agents with Memory
Letta builds stateful AI agents that learn and self-improve with advanced memory. 21.8K+ stars. CLI, Python/TS SDKs, skills, subagents. Apache 2.0.
LangChain — Build LLM-Powered Applications
The most popular framework for building applications with large language models. Chains, agents, RAG, memory, tool use, and integrations with 700+ providers.