LangChain chains excel at linear RAG. Real agents need loops, branches, retries, and checkpoints. LangGraph models that as a stateful graph—the control plane for agentic workflows that Volume 15 explores in depth (agent loops, HITL).
Learning Objectives
By the end of this lesson, students should be able to:
- Define LangGraph as graph-based, stateful orchestration for agents.
- Describe nodes, edges, state, and conditional routing.
- Sketch a retrieve → generate → critique loop as a graph.
- Explain checkpoints / persistence for long-running runs.
- Contrast LangGraph with plain LangChain chains and CrewAI multi-agent.
- Connect graph design to Volume 15 agent patterns.
LangGraph is a library for building durable, stateful multi-actor applications with LLMs. You define a shared state schema and a graph of nodes (steps) connected by edges—including cycles—so agent behavior is explicit, inspectable, and resumable.
Why Graphs Beat Hidden Loops
| Need | Chain | LangGraph |
|---|---|---|
| Linear RAG | Ideal | Possible but heavier |
| Retry / reflect cycles | Awkward | Native edges |
| Human approval gates | DIY | Interrupt + resume |
| Durable state | Limited | Checkpointers |
| Debuggability | Nested runnables | Visible graph topology |
Minimal Graph Sketch
Bridge to Volume 15
Shared memory
Tools / LLM steps
Plan / reflect
Approve & resume
Strengths
- Explicit control flow
- Cycles and branching
- Persistence / resume
- Fits production agents
Tradeoffs
- More design upfront
- Overkill for one-shot RAG
- State schema discipline
- Learning curve
“More nodes always means a smarter agent.” Extra reflect loops can amplify errors and cost. Measure task success and latency; add cycles only when eval shows benefit.
Knowledge Check
- Short Answer: What does LangGraph add beyond linear chains? Answer: Stateful graphs with cycles, branching, and durable control.
- True/False: LangGraph state is typically a shared schema updated by nodes. Answer: True.
- Multiple Choice: Conditional edges are used to: (a) style HTML, (b) route based on state, (c) train CNNs. Answer: (b).
- Short Answer: Name one Volume 15 concept LangGraph supports well. Answer: Agent loops, HITL, planning/reflection (any).
- True/False: Linear FAQ RAG always needs LangGraph. Answer: False.
- Multiple Choice: Checkpointers help with: (a) font caching, (b) durable/resumable runs, (c) FAISS nprobe. Answer: (b).
- Short Answer: Why make topology explicit? Answer: Debuggability, governance, predictable control flow.
- Short Answer: Contrast CrewAI vs LangGraph briefly. Answer: CrewAI emphasizes role crews; LangGraph emphasizes explicit state graphs (any fair contrast).
- Multiple Choice: Reflect loops can: (a) only reduce cost, (b) raise cost/error if misused, (c) remove embeddings. Answer: (b).
- True/False: Graphs can include retrieve and generate nodes for agentic RAG. Answer: True.
Key Takeaways
- LangGraph is the stateful graph layer for serious agent workflows.
- Nodes mutate shared state; edges (including cycles) define behavior.
- Use chains for simple RAG; graphs when control and durability matter.
- This is the technical bridge into Volume 15 AI Agents.
- Next: LlamaIndex for retrieval- and index-centric orchestration.
Whiteboard: Convert a vague “research agent” into 5 named nodes with halt conditions.
Lab: Add a critique node that appends to state and routes back at most twice.
Recap: LangGraph makes agent control flow visible and durable. Continue with LlamaIndex.