Lesson 24 / 31

LangGraph: Stateful Workflows

Model complex flows as a graph with shared state.

Nodes, edges, state

LangGraph (a separate library from the LangChain team) models an application as a graph: nodes are functions (an LLM call, a tool, a check), edges define what runs next (including conditional edges and loops), and a typed state is passed along and updated. Benefits over a free-running agent: explicit control flow, checkpointing (save and resume state, enabling memory and fault recovery), human-in-the-loop pauses for approval, streaming of intermediate steps and easier testing of each node. Use it when you need loops, branching, long-running tasks or approvals; use a simple chain when you do not.

A support-agent graph (sketch)

A conceptual map, not code from a specific version. Shows nodes, a conditional edge and a human approval step.

START -> classify ----billing----> lookup_invoice -> draft_reply --+
                 \--technical--> search_docs ----> draft_reply --+
                 \--other------> draft_reply --------------------+
                                                                v
                                              [human approval if refund > 100]
                                                                v
                                                         send_reply -> END
state = {question, category, evidence, draft, approved}   # saved at each step (checkpoint)

Quick check: What does checkpointing enable?

  • Hiding prompts
  • Training a model
  • Saving and resuming state, for memory and fault recovery
  • Removing nodes
Answer

Saving and resuming state, for memory and fault recovery — Checkpoints persist graph state between steps and runs.