← home
RESEARCH · TECHNIQUE

Context compaction is a cost lever.

10 July 2026

By the LLM CFO team

A customer support chatbot that remembers 50 turns of conversation with a user pays for all 50 turns as input tokens on every subsequent request. An autonomous agent running for 10 steps accumulates a full transcript that it reads before taking step 11. Both cases can reduce input tokens 50–70% by trimming or compressing the context window—dropping old turns, summarizing history, or replacing raw logs with structured memory. The cost savings are real, but so are the failure modes. Context compaction is a lever, not a free lunch.

Where context compaction wins

Where it breaks

Compaction strategies and their tradeoffs

StrategyCost savingsRisk
Drop turns older than N steps20–40%Loses history ; good for simple chats, bad for reasoning.
Summarize old turns into 1–2 sentences40–60%Lossy ; depends on summarization quality.
Extract facts into structured memory (JSON)50–70%Requires schema design ; hallucination risk if memory is incomplete.
Retrieval instead of full context60–80%High latency ; misses context if retrieval query is weak.
Prompt caching (OpenAI / Anthropic)90% on cached tokensOnly helps if context repeats ; cache invalidation is a new cost.

How to measure the tradeoff

Offline eval. Take 100 real conversations, apply your compaction strategy, and re-run the model with the compacted context. Have an LLM-as-judge score whether the response quality changed (no change, degraded, or better). Sample 20 for human review. If <5% show degradation, the strategy is safe to deploy.

Production canary. Route 5% of traffic to the compacted path. Track latency, error rate, and user satisfaction metrics (thumbs-up/down, conversation completion rate). If no difference over 1 week, expand to 50%. If worse, rollback.

Cost accounting. Track input tokens, output tokens, and cost separately for both paths. A 50% reduction in input tokens might save $100 / day but cost $5 / day in extra summarization calls. The net is still positive, but the real savings is lower than the token count suggests.

Combining with prompt caching

Prompt caching (OpenAI `$0.90 / 1M` for cached input vs `$3.00 / 1M` for regular input; Anthropic ~90% discount on cache-read tokens) is context compaction for the static parts. If your agent always starts with the same system prompt + 50 KB of operational guidelines, cache those. Then use live context compaction for the conversation history that's unique to each request.

The combination is powerful: cache the steady-state context (system prompt, retrieval docs, business rules) at 90% discount, then trim the conversation history aggressively. You end up with 80–95% savings on input tokens for multi-turn flows.

Common implementation mistakes

Related

← Back to llmcfo.com