# Stateless Iteration Keeps Loop Cost Linear While Stateful Iteration Compounds
## Claim
An agent loop that rebuilds a narrow context each iteration keeps per-iteration cost roughly constant, while a loop that carries full history forward pays for every prior turn again, so cost grows faster than iteration count.
<!-- atomicity: 1 idea ✓ -->
## Scope & conditions
- Holds for token-billed LLM loops where each call resends context.
- Doesn't apply where a provider charges by wall-clock or a flat per-call rate regardless of context size.
- The recommended practice is to measure one iteration's cost and multiply by `MAX_ITER` before launching, not to estimate after the fact.
## Evidence
The roadmap's Step 7 cost formula: cost ≈ iterations × (state + work tokens) × price. Stateless loops keep the "state + work tokens" term roughly flat per iteration; stateful loops reread accumulated history each turn, so the term grows with iteration count — producing quadratic total cost.
## Links
- [[AI Agent Safety MOC]] — the loop design decision that determines whether long-running agents stay affordable
- [[3. Resources/MOCs/AI Cost & Tokenomics MOC]] — because applies-in
- [[3. Resources/Permanent Notes/Loop Isolation Should Bound Blast Radius Before Scoping the Task]] — because evidence-for; both are pre-launch engineering decisions in the same roadmap.
## Tests / falsifiers
- Instrument a running loop's token spend per iteration; if a stateless loop's cost still grows superlinearly, the claim is wrong for that implementation (likely a context-budget leak).
- Compare measured cost curves for a matched stateless vs. stateful loop on the same task.
## Maintenance
- Last tended: 2026-08-16
- Next review: 2026-11-16
## Source
- [[3. Resources/Literature Notes/Loop Engineering — A Technical Roadmap for an Autonomous Loop (h100envy)]] — Step 7, nonlinear cost accounting.