Why LangGraph?
You have built an agent with the Claude Agent SDK. It works. So why would you ever need LangGraph?
The honest answer: for small agents you would not. LangGraph earns its cost when your workflow gets complex enough that a simple loop starts feeling fragile. This lesson explains what "complex enough" means and what LangGraph gives you that a bare loop does not.
What a Simple Loop Gets Wrong at Scale
The agent loop from Module 2 works beautifully until you need any of:
- Branching: if the agent found a customer, do X; if not, do Y
- Cycles with different exits: loop over messages, break early on certain conditions
- Human-in-the-loop: pause, ask a human, wait for approval, then continue
- Checkpointing: save agent state so it can be resumed if the process crashes
- Observability: know exactly which decision points the agent went through
- Multi-agent handoffs: one agent completes, hands off to another
You can build all of these in bare Python, and for a while people did. The code gets ugly fast. LangGraph gives you first-class support for all of them.
The Graph Model
LangGraph models an agent as a directed graph:
- Nodes are units of work. Usually a function that takes state in and returns updated state.
- Edges connect nodes and define what happens next. Edges can be conditional ("if the last message contains a tool call, go to the tool node").
- State is a shared object that flows through the graph and is updated at each node.
You define the graph once. LangGraph runs it, keeps track of state, handles checkpointing and gives you tracing tools.
A Very Small Example
Consider an agent that answers a question, then decides whether to call a tool or return:
from langgraph.graph import StateGraph, END
from typing import TypedDict, Annotated
import operator
class State(TypedDict):
messages: Annotated[list, operator.add]
def call_model(state):
# ... call Claude with state["messages"] ...
return {"messages": [response]}
def call_tool(state):
# ... run the tool ...
return {"messages": [tool_result]}
def should_continue(state):
last = state["messages"][-1]
if last.tool_calls:
return "tool"
return "end"
graph = StateGraph(State)
graph.add_node("model", call_model)
graph.add_node("tool", call_tool)
graph.set_entry_point("model")
graph.add_conditional_edges("model", should_continue, {"tool": "tool", "end": END})
graph.add_edge("tool", "model")
app = graph.compile()
Read the graph:
- Start at
model(calls Claude) - Check its output. If it wants a tool, go to
tool; if it produced a final answer, end. - After
tool, go back tomodel.
That is a ReAct agent expressed as a graph. Two nodes, one conditional edge, one straight edge. And now you have automatic tracing, checkpointing and the ability to add more nodes without turning the code into spaghetti.
What You Get Once You Are in the Graph
Tracing. Every state transition is logged. You can see exactly which nodes ran, which edges were taken and why. LangSmith (LangChain's tracing product) is the standard tool here and is worth learning alongside LangGraph.
Checkpointing. Save state to a database at every step. If the process crashes, restart from the last checkpoint. If a human needs to review, pause at a node and resume later.
Human-in-the-loop. LangGraph has first-class support for interrupts: nodes that pause and wait for external input before continuing. Essential for high-stakes workflows.
Streaming. Stream state updates to the client as the graph runs. Users see progress at each node, not just the final answer.
Time travel. Because state is persisted at every step, you can replay a run from any checkpoint. Debugging becomes much easier.
The Downside
The graph model is more concepts to learn than a bare loop. State, nodes, edges, conditional edges, checkpoints. If your agent has one tool and does one thing, LangGraph is overkill.
The rule of thumb: if your agent's control flow can be drawn on a napkin as a single loop, use the Claude Agent SDK. If it involves branching, human review, multi-step handoffs or you need audit trails, use LangGraph.
What You Will Build in This Module
Over the next three lessons you will:
- Learn the node, edge and state primitives
- Build a graph with conditional routing between two paths
- Add checkpointing so a graph can be resumed after failure
By the end you will have converted your Module 2 agent into a LangGraph implementation and understand what the graph model bought you.
Key Takeaway
LangGraph is a graph-based execution model for agents. It replaces a bare while-loop with nodes, edges and shared state. The tradeoff is more upfront concepts for much better observability, checkpointing, branching and human-in-the-loop support. Reach for it when your agent has real production requirements.