AI

LangGraph: Building Stateful Multi-Agent Workflows with LangChain

LangGraph is a framework for building stateful, multi-actor agent workflows as graphs, extending LangChain for complex agent orchestration.

Keeping this site alive takes effort — your support means everything.
無程式碼也能輕鬆打造專業LINE官方帳號!一鍵導入模板,讓AI助你行銷加分! 無程式碼也能輕鬆打造專業LINE官方帳號!一鍵導入模板,讓AI助你行銷加分!
LangGraph: Building Stateful Multi-Agent Workflows with LangChain

The first generation of LLM agents followed a simple, predictable loop – the ReAct pattern of Thought, Action, Observation. But real-world applications require more sophisticated orchestration: multiple agents working together, conditional branching, human oversight, persistent state across complex workflows, and the ability to loop back for refinement. LangGraph provides the graph-based architecture that makes these patterns possible.

LangGraph extends LangChain’s agent capabilities from linear chains to directed graphs, where each node is a computational step and edges define the control flow. This deceptively simple generalization – from chains to graphs – enables an enormous range of previously impractical agent architectures.

The framework was born from the recognition that complex agent workflows cannot be expressed as simple sequences. A research assistant that reflects on its own findings, a coding agent that runs tests and iterates on failures, a multi-agent debate system where agents challenge each other’s conclusions – these all require graph-based execution models with cycles, branching, and persistent state.


How Does LangGraph’s Graph Architecture Work?

LangGraph models agent workflows as stateful graphs where nodes are computations and edges define flow.

graph TD
    A[START] --> B[Agent Node\nLLM Reasoning]
    B --> C{Decision Edge}
    C -->|Need Tool| D[Tool Execution Node]
    C -->|Complete| E[Generate Response]
    D --> B
    E --> F[END]
    B --> G[Human-in-the-Loop\nInterrupt Point]
    G -->|Approved| D
    G -->|Modified| B

The graph structure supports cycles (agents looping back to gather more information), branching (conditional execution paths), and parallel execution (multiple nodes running concurrently).


What Workflow Patterns Does LangGraph Support?

LangGraph’s flexibility enables a wide range of agent orchestration patterns beyond the basic ReAct loop.

PatternDescriptionUse Case
Simple ReActStandard agent loop (think-act-observe)Basic Q&A, simple tasks
SupervisorOne agent delegates to specialist agentsResearch assistant, customer support
Agent-as-toolAgents can invoke other agents as toolsNested problem decomposition
Hierarchical teamsManager agent coordinates sub-agentsSoftware development team simulation
Map-reduceMultiple agents in parallel, results mergedData analysis, document review
ReflectionAgent generates output, then critiques itselfContent generation, code review
Human-in-the-loopWorkflow pauses for human approvalSensitive operations, content moderation

Each pattern can be implemented by defining the appropriate graph structure, nodes, and edge routing logic.


How Does State Management Work in LangGraph?

LangGraph’s state management is a first-class feature that persists across the entire workflow.

State FeatureDescriptionAPI
Typed stateDefine state schema with Pydantic or TypedDictState = TypedDict(...)
ReducersCustom logic for state updates (append, overwrite)Annotated[list, add_messages]
CheckpointsAutomatic state persistence for fault toleranceCheckpointer
Thread-level isolationSeparate state per conversation threadthread_id parameter
State visualizationDebug state transitions at each stepBuilt-in visualization

The checkpointing system is particularly important for production deployments, enabling workflows to survive restarts and providing full auditability of agent decisions.


How Do You Build a Multi-Agent System with LangGraph?

Building a multi-agent system involves defining agents as graph nodes and orchestrating their interactions.

ComponentLangGraph ElementExample
Agent definitionsNode functionsResearch agent, writing agent, review agent
Inter-agent communicationShared stateResearch results, drafts, feedback
Routing logicConditional edges“If research is complete, route to writing”
Resource sharingGlobal stateShared context, knowledge base access
TerminationEND nodeAll tasks complete, max cycles reached

The result is a system where agents collaborate autonomously, passing work between each other through the shared graph state.


FAQ

What is LangGraph? LangGraph is a framework developed by LangChain for building stateful, multi-actor agent workflows as directed graphs. It extends LangChain’s agent capabilities by modeling agent interactions as nodes and edges in a graph, where each node represents a computation step (LLM call, tool execution, human input) and edges define the control flow. This enables complex, non-linear agent behaviors like loops, branching, and parallel execution.

How does LangGraph differ from standard LangChain agents? Standard LangChain agents follow a linear ReAct loop: Think -> Act -> Observe -> Repeat. LangGraph generalizes this to arbitrary graph structures, allowing cycles (agents that loop back to earlier steps), branching (conditional paths based on agent decisions), parallel execution (multiple agents running simultaneously), and persistent state management throughout the entire workflow execution.

What is LangGraph’s state management model? LangGraph uses a centralized state object that persists across all nodes in the graph. Each node reads from and writes to this shared state, which automatically tracks the context across the entire workflow. State can include conversation history, intermediate results, agent decisions, tool outputs, and any custom data structures. This enables agents to make decisions based on the complete workflow history.

What types of workflows can you build with LangGraph? LangGraph supports a wide range of workflow patterns including single-agent ReAct (for simple Q&A), multi-agent supervisor (one agent coordinates specialists), agent-as-tool (agents call other agents), hierarchical teams (manager agents with sub-agents), map-reduce (parallel agent execution), reflection (agents critique and revise their own output), and custom orchestration patterns.

Does LangGraph support human-in-the-loop workflows? Yes, LangGraph natively supports human-in-the-loop patterns. Any node can be configured to pause execution and wait for human input. The framework provides APIs for interrupting execution, waiting for approval, modifying agent decisions before execution, and resuming workflows. This is critical for production deployments where autonomous agent actions need human oversight.


Further Reading

TAG
CATEGORIES