Loops break expensively. Graphs break cheaply.
Everyone's arguing about loops versus graphs for agent architecture. LangGraph people say graphs are more flexible. Loop people say graphs are overkill. Both sides are missing the real decision point.
The architecture choice isn't about flexibility or complexity. It's about where your agent breaks.
Loops break at the loop level. When something goes wrong, you lose the entire cycle. Your agent was halfway through analyzing a document, hit an API timeout, and now it's starting over from scratch.
Graphs break at the node level. When something goes wrong, you lose one step. Your agent was analyzing a document, the summarization node failed, but it kept the extraction results and just retries the summary.
Here's the pattern that matters:
Use loops for cheap, fast operations that you don't mind repeating.
Use graphs for expensive, slow operations that you can't afford to lose.
I learned this the hard way. We had a coding agent running in a simple loop: read requirements → plan → code → test → review. Elegant. Clean. Completely wrong for our use case.
Every time the test step failed (which was often), the agent started over. It re-read the same requirements, re-generated the same plan, re-wrote the same code. We were paying for the same GPT-4 calls over and over.
The fix wasn't switching to LangGraph. It was recognizing that planning and coding were expensive operations we wanted to preserve, while testing and reviewing were cheap operations we could repeat.
So we built a hybrid: expensive operations in a graph with persistent state, cheap operations in loops within each node.
Plan Node (expensive, cached)
↓
Code Node (expensive, cached)
↓
Test Loop (cheap, repeatable)
while tests_failing:
fix_test_issues()
run_tests()
↓
Review Node (moderate, cached)The result: we kept the expensive work when things failed, but still got the simplicity of loops for the cheap retry logic.
The decision framework:
- API calls that cost money? Graph node.
- File operations that take time? Graph node.
- Validation loops that should retry? Loop within node.
- Simple transformations? Loop within node.
Most agent builders pick an architecture first, then force their use case into it. Pick your failure mode first, then choose the architecture that fails gracefully.
Your agent will break. The question is whether it breaks expensively or cheaply.