Compaction reads the whole context as input
compaction overhead
compactions
overhead cost
total run cost

Where compaction pays off — sweeping the trigger

Compact too early and you fire many events; compact too late (or never) and every step re-reads a huge context. The total-cost column usually has a minimum in the middle.

Compact atCompactionsOverheadTotal run cost

The housekeeping nobody budgets for

An autonomous agent has no long-term memory of its own run, so it keeps the whole working context in the prompt: the system instructions, the tool definitions, every tool result it has seen and every step it has taken. That context grows monotonically, and long before it overflows the model's window the agent has to compact — hand the entire context to the model, get back a compressed summary, and carry on from the summary. Compaction is what keeps a multi-hour agent alive, but it is not free: summarising a 150,000-token context bills 150,000 input tokens for that one event, and a run that compacts three or four times can spend a fifth to a third of its total tokens on this alone. It is a cost that never appears in a per-call price and never shows up in a naive token estimate, which is exactly why agent bills come in higher than the math on the back of the envelope. The way to control it is to tune when you compact and how small you reset to, and to bill the re-read at a discount with caching or a cheaper summariser. Size the multi-turn side on the multi-turn conversation cost calculator, the whole loop on the agent loop budget calculator, and the caching win on the prompt caching savings calculator.

Host your project:DigitalOcean — $200 free ↗Hostinger VPS
Agent Loop Budget CalculatorMulti-Turn Conversation CostAI Agent Step CostContext Window CostPrompt Caching Savings