LangGraph has crossed 40k stars on GitHub and now ranks among the most widely adopted frameworks for orchestrating agents. Its core idea fits in one sentence: model an agent's execution flow as a directed graph. Loops, branches, state persistence, human approval—everything happens on top of that graph structure.
The walkthrough below covers the problem it solves, how to use it, the architecture, strengths and weaknesses, a hands-on test, and who should pick it up.
The Problem It Solves
Traditional chains only move forward: prompt → llm → parser → next. The moment an agent needs a loop (think ReAct calling tools repeatedly until it has an answer), a branch (call a tool this step, answer directly the next), or human approval (pause for confirmation before continuing), the chain structure hits a wall.
LangChain's Runnable sequence has the same limitation at heart: it's synchronous, directed, and single-pass. Rollback, pause, cross-session memory—Runnable chokes on these.
LangGraph fills that gap. It uses StateGraph to make the execution flow explicit:
- Node — a unit of computation (one LLM call, a tool, a function)
- Edge — a transition condition (unconditional or conditional)
- State — a shared data structure that flows between nodes automatically
Because graphs support cycles natively, iterative agent patterns like ReAct feel natural to express.
How to Use It
Three steps to get started:
- Define the State (a
TypedDictor Pydantic model) - Write node functions that take state and return state updates
- Assemble the graph with
StateGraph, add a checkpointer, and compile
The core API is small: add_node, add_edge, add_conditional_edges, compile.
Here is a runnable minimum example demonstrating a 3-step loop with a conditional edge:
from typing import TypedDict, Literal
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import MemorySaver
class State(TypedDict):
messages: list[str]
step: int
def agent(state: State) -> State:
return {
"messages": state["messages"] + [f"step {state['step']} done"],
"step": state["step"] + 1,
}
def should_continue(state: State) -> Literal["agent", END]:
return END if state["step"] >= 3 else "agent"
graph = StateGraph(State)
graph.add_node("agent", agent)
graph.add_edge(START, "agent")
graph.add_conditional_edges("agent", should_continue)
app = graph.compile(checkpointer=MemorySaver())
result = app.invoke(
{"messages": [], "step": 0},
config={"configurable": {"thread_id": "1"}},
)
print(result)
# {'messages': ['step 0 done', 'step 1 done', 'step 2 done'], 'step': 3}
Install with one line:
pip install langgraph
Call invoke to get the final result, or stream to watch the state evolve at each superstep—the latter is invaluable when debugging agents.
How It Works (Architecture)
Three core concepts:
- State — the global schema (
TypedDictor Pydantic) that every node reads and writes - Node — a pure function or LangChain Runnable with the signature
(state) -> dict - Edge — a fixed transition, or a
conditional_edgesfunction that picks the next node from the current state
At runtime, LangGraph runs a Pregel-style superstep loop (a nod to Google's Pregel graph-computation system). Each superstep:
- Decides which nodes to activate based on current state and edges
- Runs the eligible nodes in parallel—so node functions should never assume global ordering
- Merges node outputs back into State through a Channels mechanism that resolves concurrent writes
- Moves to the next superstep until no node remains active
Checkpointing is LangGraph's killer feature. After each superstep, the framework serializes state to a backend:
MemorySaver— in-memory, lost on restart; good for testsSqliteSaver— local filePostgresSaver— the production default, with time-travel debugging
Pass the same thread_id on a subsequent invoke and the framework resumes from the last checkpoint instead of starting over. Time-travel debugging falls out of this: replay any past superstep to see exactly what the agent did.
Human-in-the-loop is even simpler. Insert an interrupt before a node, and execution halts there. The state is exposed for user input, and once the user responds, execution picks up from the pause. Approval flows, confirmations, rewrites—LangGraph handles them cleanly.
Strengths and Weaknesses
Where it shines:
- The graph model sits at a lower level than CrewAI's role-collaboration abstraction and offers more control than AutoGen's group-chat model. It's just a graph—what nodes do and where edges lead is entirely up to you.
- Checkpointing is genuinely production-grade. The Postgres backend's time-travel debugging makes incident triage much easier.
- Compatible with the LangChain ecosystem (Runnable, tools, message schemas all work) but not coupled to it—you can install
langgraphalone. - Documentation is top-tier for an open-source project, with official cookbooks covering common patterns.
Where it falls short:
- The learning curve is steeper than a plain LLM wrapper or a simple chain. A poorly designed state schema with chaotic conditional edges quickly becomes spaghetti—one node fanning out to a dozen others that nobody can trace.
- Local debugging with
streamis noisy. Every superstep prints the full state, which overwhelms newcomers. - The post-v0.2 API changed significantly. Parameter order in
set_entry_point,add_edge, and others shifted, so older tutorials often error out. Check dates before copying code. - Compared with CrewAI's out-of-the-box experience, LangGraph hands you something closer to a Turing-complete graph machine. Flexible, yes, but the topology design is on you.
Hands-On Test
Installed pip install langgraph langgraph-checkpoint-sqlite and ran the official tutorial's ReAct agent example. Five rounds of tool calls on MemorySaver finished in roughly 12 seconds.
Switching to SqliteSaver with checkpointing on, a second invoke with the same thread_id resumed from the checkpoint and returned in about 0.5 seconds. That latency gap matters: when long tasks get interrupted, when networks hiccup, when retries happen, the user experience is completely different.
A few edge cases worth noting:
StateGraph.compile()runs cycle detection, which catches obvious infinite loops (self-loops plus unconditional edges).- But real safety nets come from a
max_stepsconfig—buggy conditional logic won't be saved by the framework alone. - Compared with CrewAI 0.80 running the same ReAct task, LangGraph's startup overhead is slightly higher (around 200ms, the cost of Pregel scheduling plus checkpoint initialization), but its state visibility and recovery are substantially stronger.
Two other frameworks come up in community comparisons: AutoGen (Microsoft's group-chat multi-agent model) and LlamaIndex Workflows (event-driven). AutoGen's abstraction feels more natural-language-ish (agents message each other); LlamaIndex Workflows is lighter. LangGraph sits between them—more structured than either, and more programmer-friendly.
Who Should Use It
Good fit when you need:
- Long-horizon execution (multi-turn tool calls, multi-step reasoning)
- Human approval (finance, healthcare, compliance agents that demand HITL)
- Cross-session memory (chatbots, continuously learning agents)
- Observable, replayable production agents (so you can inspect historical checkpoints when something goes wrong)
Not worth it when:
- Single-turn Q&A: just call the LLM directly
- One-off scripts: a graph is overkill
- Latency-critical real-time interactions under 100ms: graph scheduling overhead is too much
For those cases, a raw LLM call or a LangChain Runnable does the job. LangGraph isn't a chain replacement—it's the next step when chains can't keep up.
Wrap-Up
LangGraph gives agents an explicit, persistent, interruptible execution model. It's not the easiest tool to pick up, but for production-grade agents—especially those needing loops, approvals, long memory, or replay—it's currently the most mature option available.
40k stars didn't happen by accident. The repo is at https://github.com/langchain-ai/langgraph—the README and examples/ directory are the fastest way to start.