Why a Graph? State, Nodes & Edges
Build a LangGraph agent from scratch: StateGraph, TypedDict state, the add_messages reducer, and the decision table for when a graph beats a plain while-loop.
Last updated
After this section you can
- Decide between a while-loop, LangGraph and the Claude Agent SDK for a given run
- Build and run a StateGraph from scratch
- Choose a reducer so parallel writes merge instead of clobbering
Why a Graph? State, Nodes & Edges
A LangGraph app is three things: a state shape, functions that return updates to it, and edges that decide what runs next. Persistence, approval gates and streaming are then one flag each.
A node never mutates state — it returns an update, and a reducer decides how that update merges. Because every merge happens at a known point between two nodes, the runtime has somewhere to write a checkpoint. That one rule is what buys you resume-after-crash, human approval and time travel later.