Core Concepts
State Graph
Define your workflow as a directed graph:
graph = StateGraph(AgentState)
graph.add_node("plan", plan_step)
graph.add_node("execute", execute_step)
graph.add_node("review", review_step)
# Conditional routing
graph.add_conditional_edges("review", decide_next, {
"revise": "execute", # Loop back if needs revision
"approve": END # Finish if approved
})Cycles (Agent Loops)
LangGraph supports loops — agents can iterate until satisfied:
plan → execute → review → execute → review → approve → END
↑___________|
(revision loop)Human-in-the-Loop
Pause execution for human approval:
from langgraph.checkpoint import MemorySaver
graph.add_node("human_review", interrupt_before=True)
# Agent pauses here, human reviews, then continues
app = graph.compile(checkpointer=MemorySaver())Persistence
Checkpoint state for resuming later:
from langgraph.checkpoint.postgres import PostgresSaver
checkpointer = PostgresSaver(connection_string="...")
app = graph.compile(checkpointer=checkpointer)
# Resume from any checkpoint
result = app.invoke(None, config={"thread_id": "task-123"})Multi-Agent Patterns
# Supervisor pattern: one agent delegates to specialists
supervisor = create_supervisor(
agents=[researcher, coder, reviewer],
model="claude-sonnet-4-20250514"
)
# Each agent is a subgraph node
graph.add_node("supervisor", supervisor)
graph.add_node("researcher", researcher_graph)
graph.add_node("coder", coder_graph)Key Stats
- 8,000+ GitHub stars
- By LangChain team
- Cycles and conditional branching
- Persistent checkpointing
- Human-in-the-loop support
FAQ
Q: What is LangGraph? A: LangGraph is a framework for building stateful AI agent applications as directed graphs with support for cycles, branching, persistence, and human-in-the-loop workflows.
Q: Is LangGraph free? A: Yes, open-source under MIT license. LangGraph Platform (managed hosting) is paid.
Q: How is LangGraph different from CrewAI? A: LangGraph uses graph-based control flow with explicit state management. CrewAI uses role-based agents with implicit orchestration. LangGraph offers finer-grained control.