The Quadratic Explosion of Multi-Turn Agentic Loops
In conversational chat interfaces, context growth is modest. But inside autonomous agentic IDEs like Antigravity, Cursor, and Roo-Code, every single turn compounds. On step 1, the agent submits the system prompt, MCP tool definitions, and your user request. On step 2, it re-submits the entire step 1 request, the step 1 model thought process, the tool call input, and the tool execution output (such as a 300-line file read or git diff).
By step 15, the agent is re-sending the accumulated history of all 14 previous turns. The total input tokens consumed by an $N$-step task scales quadratically:
Total Tokens = N × Base + (N² / 2) × Growth
A task that feels like "one quick refactor" can quietly consume 400,000 input tokens. At 25 tasks per day, an unoptimized frontier model like Claude 3.5 Sonnet burns \$900 to \$1,400 monthly.
How Prompt Caching Amortizes Agent Costs
Both Anthropic (Claude) and Google (Gemini) support prefix prompt caching. When an agent submits a turn where the first $K$ tokens match an existing cached prompt, the provider bills those tokens at an 80% to 90% discount (e.g. \$0.30 per M tokens instead of \$3.00 on Claude Sonnet).
However, Anthropic applies a 25% surcharge on the initial cache write. For prompt caching to pay off, your agent architecture must achieve at least 3 to 4 sequential turns against the identical prefix within the 5-minute cache TTL. If your agent frequently shuffles tool schemas or invalidates system instructions early in the prompt, caching writes will actually increase your cloud bill.