Every loop turn re-sends the whole growing transcript, so per-turn input scales with step number and the summed cost over N turns is quadratic.
Imagine you hire someone with no memory between minutes. Each time you ask them to do the next part of a job, you must re-read aloud everything that happened so far before they can act. On step one you read one paragraph. On step ten you read all ten paragraphs again, even though only the last one is new. The further you get, the longer your re-reading takes, because the story keeps growing and you always start from the top. An agent loop works exactly like this. The model forgets nothing only because you resend the entire transcript on every turn. Early turns are cheap, late turns are expensive, and the total reading time across a long task piles up far faster than the number of turns alone would suggest.
Detailed answer & concept explanation~8 min readEverything 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. 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.
Start from the stateless model and append-only transcript, show per-turn input scaling with the step index, derive the triangular sum and simplify it to O(N²), rule out pricing and parameter count, then cover prompt caching and the context-trimming techniques that pull cost back toward linear.
Real products, models, and research that use this idea.
- Anthropic and OpenAI both ship prompt caching specifically because agent loops resend a growing prefix; cache reads cut the per-turn dollar cost of that resent context by a large margin.
- LangGraph and the Anthropic SDK expose summarisation and message-trimming hooks so long-running loops can hold per-turn input near constant instead of letting it climb with step count.
- Coding agents like Cursor and Cline keep full file contents in a side store and inject only diffs or referenced spans, avoiding resending entire files on every edit-test turn.
- Tracing tools such as LangSmith and Langfuse attribute token cost per loop step, which is how teams spot the quadratic climb and decide where to trim context.
What an interviewer would ask next. Try answering before peeking at the approach.
QPrompt caching means resent tokens are cheap. Does the quadratic problem go away?
QSummarisation holds per-turn input near constant. What does it cost you?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Blaming per-token pricing or model size. Cost grows because each turn resends the full accumulated context, not because tokens get more expensive as the window fills.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.