When does LangGraph `create_react_agent` beat a hand-written StateGraph?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
create_react_agent wins on the standard tool-calling loop with a baked-in messages state; reach for a hand-written StateGraph when routing, state, or interrupts get custom.
Imagine ordering coffee. The default menu has espresso, latte, and cappuccino. Three preset orders the barista makes in seconds. If that is what you want, you say 'latte' and you are done. If you want oat milk, half the foam, an extra shot, and a sprinkle of cinnamon on top, you have to spell out each step. The preset menu does not have a button for it. LangGraph's create_react_agent is the preset menu. A standard tool-calling loop with one well-known shape. The hand-written StateGraph is the custom order. More typing, but you can spell out every step the way you want.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: the ReAct loop the prebuilt encodes, what state it locks you into, why customisation forces StateGraph, and how checkpoints carry over on migration.
| Axis | create_react_agent | Hand-written StateGraph |
|---|---|---|
| State schema | Messages-only (fixed) | Any TypedDict you define |
| Topology | model → tools → model | Any nodes and edges you need |
| Custom routing | No | Conditional edges, per-output dispatch |
| Interrupts | interrupt_before_tools toggle | interrupt_before / after any node |
| Parallel branches | No | Yes (super-step + reducers) |
| Best for | Tool-using agent with no custom flow | Multi-agent, plans, structured state, HITL |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Calling create_react_agent deprecated and writing a StateGraph for a vanilla tool-calling loop. 40 lines of boilerplate the prebuilt would have given you for free.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.