LangGraph
LangGraph is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. It extends the LangChain ecosystem with graph-based orchestration primitives.
Overview
LangGraph models agent workflows as directed graphs where:
- Nodes represent computation steps (LLM calls, tool invocations, or custom logic)
- Edges represent transitions between steps (conditional or unconditional)
- State is passed between nodes and persisted across interactions
This graph-based approach gives you fine-grained control over agent behavior, including cycles, branching, and human-in-the-loop patterns.
Key Features
- Stateful Graphs: First-class support for persistent state across graph executions
- Cycles and Branching: Model complex agent reasoning with loops and conditional edges
- Human-in-the-Loop: Pause execution for human review and resume from checkpoints
- Streaming: Stream node outputs, LLM tokens, and intermediate state updates
- Persistence: Built-in checkpointing for fault tolerance and conversation memory
- Multi-Agent: Compose multiple agents as subgraphs within a parent graph
Installation
pip install langgraph
Quick Start
from langgraph.graph import StateGraph, END
from typing import TypedDict
class AgentState(TypedDict):
messages: list
next_step: str
def call_model(state: AgentState) -> AgentState:
# LLM call logic
return {"messages": state["messages"] + [response]}
def should_continue(state: AgentState) -> str:
if state["next_step"] == "end":
return END
return "call_model"
# Build the graph
graph = StateGraph(AgentState)
graph.add_node("call_model", call_model)
graph.add_conditional_edges("call_model", should_continue)
graph.set_entry_point("call_model")
app = graph.compile()
result = app.invoke({"messages": ["Hello"], "next_step": "continue"})
Architecture Patterns
ReAct Agent
The most common pattern: the agent reasons about what tool to call, executes it, and loops until done.
Plan-and-Execute
The agent first creates a plan, then executes each step, revising the plan as needed.
Multi-Agent Collaboration
Multiple specialized agents coordinate through a supervisor agent that routes tasks.
Documentation
License
MIT License