← Master Index
Vol. 14 Module 14.3 Lecture

LangGraph

LangChain & Orchestration Frameworks

How This Lesson Fits the Module & Volume

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.
Definition

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

NeedChainLangGraph
Linear RAGIdealPossible but heavier
Retry / reflect cyclesAwkwardNative edges
Human approval gatesDIYInterrupt + resume
Durable stateLimitedCheckpointers
DebuggabilityNested runnablesVisible graph topology

Minimal Graph Sketch

from typing import TypedDict, Annotated from langgraph.graph import StateGraph, START, END import operator class State(TypedDict): question: str context: str draft: str critiques: Annotated[list[str], operator.add] def retrieve(state: State) -> dict: # call vector store / retriever return {"context": "SSO requires Okta admin role..."} def generate(state: State) -> dict: # LLM draft using state["context"] return {"draft": "To enable SSO, open Admin > Security..."} def should_revise(state: State) -> str: return "generate" if len(state.get("critiques", [])) < 1 else END graph = StateGraph(State) graph.add_node("retrieve", retrieve) graph.add_node("generate", generate) graph.add_edge(START, "retrieve") graph.add_edge("retrieve", "generate") graph.add_conditional_edges("generate", should_revise) app = graph.compile() print(app.invoke({"question": "How do I enable SSO?", "critiques": []}))

Bridge to Volume 15

State

Shared memory

Nodes

Tools / LLM steps

Edges

Plan / reflect

HITL

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
Common Misconception

“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

  1. Short Answer: What does LangGraph add beyond linear chains? Answer: Stateful graphs with cycles, branching, and durable control.
  2. True/False: LangGraph state is typically a shared schema updated by nodes. Answer: True.
  3. Multiple Choice: Conditional edges are used to: (a) style HTML, (b) route based on state, (c) train CNNs. Answer: (b).
  4. Short Answer: Name one Volume 15 concept LangGraph supports well. Answer: Agent loops, HITL, planning/reflection (any).
  5. True/False: Linear FAQ RAG always needs LangGraph. Answer: False.
  6. Multiple Choice: Checkpointers help with: (a) font caching, (b) durable/resumable runs, (c) FAISS nprobe. Answer: (b).
  7. Short Answer: Why make topology explicit? Answer: Debuggability, governance, predictable control flow.
  8. Short Answer: Contrast CrewAI vs LangGraph briefly. Answer: CrewAI emphasizes role crews; LangGraph emphasizes explicit state graphs (any fair contrast).
  9. Multiple Choice: Reflect loops can: (a) only reduce cost, (b) raise cost/error if misused, (c) remove embeddings. Answer: (b).
  10. 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.
Trainer’s Guide

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.