Theory
A linear chain treats an LLM workflow as a rigid sequence of instructions. A state machine, however, models the workflow as a graph of distinct computational states connected by explicit transitions. The moment your agent requires dynamic error recovery, human-in-the-loop validation, or cyclical execution, simple linear chains collapse into unmaintainable boilerplate code.
| Capability | Linear chain | State machine (LangGraph) |
|---|---|---|
| Conditional next step | if inside a step (hidden) | Explicit conditional edge |
| Retry a failed tool | Bespoke try/except in glue code | Loop back to the same node |
| Hand off between agents | Awkward (string-passing) | Native (sub-graphs, shared state) |
| Persist & resume | Custom serialization | Checkpointer = one line of config |
| Visualise the flow | Read the source | Render the graph |
LangGraph is a specialized orchestration framework that treats your agent system as a directed graph. Every node represents a state mutator function (state -> state), and every edge determines the execution path based on the central state object. Everything else—from memory management to step-by-step tracing—is engineered on top of this primitive.
