Core Architecture: A State Machine Perspective
LangGraph is an Agent orchestration framework from the LangChain team. Its core idea is to model Agent workflows as stateful directed graphs. Unlike traditional DAGs, each LangGraph node not only executes logic but also reads and writes a shared State object, giving the flow memory and branching capabilities.
Nodes
Nodes are the basic execution units of the graph. Each typically maps to a function that receives state and returns updates (or a full replacement). Common node types include:
- LLM nodes: Call large language models for responses or planning
- Tool nodes: Execute search, computation, API calls
- Human nodes: Pause and wait for user input (human-in-the-loop)
- Router nodes: Decide the next hop based on conditions
Edges
Edges define flow between nodes:
- Regular edges:
add_edge(A, B)means A unconditionally proceeds to B - Conditional edges:
add_conditional_edges(A, router_fn)routes to the next node based onrouter_fn(state)return value - Entry and exit:
add_noderegisters nodes;set_entry_pointandset_finish_pointdefine graph entry and exit
State
State is the shared data structure that flows through the graph, usually defined with TypedDict or Pydantic. Nodes can:
- Append: e.g., add new messages to a
messageslist - Overwrite: e.g., update a
current_stepfield - Merge: LangGraph supports reducer functions for custom state merge strategies when nodes run concurrently
Checkpointers
Checkpointers persist state snapshots during graph execution to storage (memory, Redis, Postgres). This enables:
- Time travel: Revert to any historical step and re-execute
- Checkpoint resume: Resume long-running tasks from the last checkpoint after interruption
- Human-in-the-loop: Pause at a human node, then continue from that checkpoint after user response
Typical Patterns
llm → tools → llm forms a cycle; conditional edges decide whether to keep calling tools or finishSummary
Mastering LangGraph's nodes, edges, state, and checkpointers is key to building observable, recoverable, and scalable Agent systems. Its state machine model naturally supports cycles and branches, making it more flexible than linear Chains and well-suited for complex multi-step task orchestration.