The Research Report
Why Your Production Agent Is Burning 80% of Its Tokens on Stale Context
Every token in your agent's context window gets re-processed on every single API call. That is the simple fact that makes context bloat the silent cost killer of production AI systems. Redis documented a customer where 80% of consumed tokens were stale context, not the actual task at hand. The agent was not failing. Its context was.
How Prompt Bloat Happens
Context windows fill up through a predictable accumulation pattern. Each turn adds system prompts, conversation history, tool outputs, and retrieved documents to the same shared budget. A session that retrieves ten documents at 500 tokens each burns 5,000 input tokens before the model generates a single character. Tool calls return long JSON payloads. Chat history grows linearly. Retrieved documents pile up. Without intervention, every subsequent inference call works through everything that came before.
The result is a compounding cost curve. A session that keeps growing costs more per turn the longer it runs. Long agent sessions accumulate token costs that scale worse than linearly with each additional tool call. The model is not just slower. It is also paying full freight to re-read its own history.
The Real Numbers on Cost and Latency
Bigger context windows do not automatically mean better results. GPT-4.1 supports up to 1M tokens. Claude Sonnet 4 offers 200K standard. Gemini 1.5 Pro processes up to 2M. But just because you can stuff a million tokens into a request does not mean you should.
One study found over 7x latency increase at 15,000 words of context. Quality degrades well before you hit the maximum window. The "lost-in-the-middle" problem is well-documented: models pay more attention to information at the beginning and end of long contexts, often missing what is buried in the middle. Fill your context with marginally relevant documents, and you are paying for tokens that actively hurt your results.
Context rot is another documented failure pattern. Models perform well on simplified benchmarks but degrade as input length increases in complex tasks that require reasoning across multiple documents. Reported accuracy drops range from 14% to 85% as contexts grow. Effective context length, the range where the model maintains strong performance, can be much shorter than the advertised maximum.
Unmonitored retrieval strategies drive up costs that systematic token tracking exposes. Production systems often include redundant context in every call without realizing the impact. Redis benchmarks show that semantic caching via Redis LangCache can cut inference costs by up to 73% and deliver up to 15x faster responses for cache hits.
Why Stale Context Dominates the Window
The root cause is structural. The context window is a single budget shared across five categories: system prompts, retrieved context, conversation history, user query, and generated response. Each category expands without bound unless you enforce boundaries.
Tool outputs are a major offender. A single API call can return thousands of tokens of JSON. If the agent only needs three fields, the other 97% is dead weight. Retrieved documents suffer from the same problem. Ten documents retrieved at 500 tokens each sounds reasonable until you realize the agent only needed two sentences from one of them.
Conversation history is the slowest threat. It grows linearly with every turn. A 40-turn debugging session can easily push the agent past its effective reasoning window. Then, around turn 45, it forgets everything it learned and starts investigating from scratch.
Strategies for Keeping Context Lean
1. Context Compaction
The most powerful strategy is compaction: condensing accumulated conversation into a structured, high-fidelity representation, then reinitiating a new context window with that condensed form in place of the raw history. Think of it as a senior engineer's handoff note after a two-week sprint. The raw Slack export is gone, but every decision, open issue, and current system state is preserved.
Good compaction preserves active constraints the agent is still bound by, open decisions not yet acted on, and completed-task state. It discards the exploratory process that led to decisions, redundant tool outputs already reflected in agent state, and verbose intermediate steps.
Princeton researchers built Slipstream, a trajectory-grounded compaction system that validates candidate summaries against the agent's continued reasoning. It improves task accuracy by up to 8.8 percentage points while reducing end-to-end latency by up to 39.7%. Anthropic recommends compacting at as little as 5-20K tokens for some workloads.
2. Tool Output Offloading
Write large tool results to an external store and leave a reference pointer plus a short preview in the context. Nothing is destroyed. The agent can pull the full content back when it needs it. This is a good fit when tool calls return long payloads the agent only occasionally needs in full.
3. Sliding Windows and Selective Eviction
Keep the last N conversation turns and drop everything older. Context size stays predictable and bounded. This works best for stateless or short-horizon tasks where early turns genuinely do not matter later.
4. Staged Compaction Under Pressure
Graduate through progressively more aggressive strategies instead of jumping straight to lossy summarization. Lighter moves like masking unused fields or pruning stale turns often free up enough space on their own. Lossy summarization becomes a last resort instead of a default.
5. Smart Retrieval and Chunking
Split documents into chunks with strategic overlap to preserve context at boundaries. Use hybrid retrieval that combines semantic and keyword search. Fewer highly relevant documents often outperform more marginally relevant ones. You get better answers faster while spending less.
6. Two-Tier Memory Architecture
Separate working memory from long-term memory. Working memory holds session-scoped events bounded by a configurable time to live. Long-term memory persists cross-session knowledge as vector embeddings retrieved through semantic search. Active context stays bounded in the session while high-signal information lives separately and gets pulled in when the agent needs it.
Redis's Recommendations
Redis has published extensive guidance on context architecture for production AI agents. Their core message: compaction, RAG, and bigger windows are complementary, not competing. RAG retrieves external knowledge. Larger windows provide ceiling capacity. Compaction manages accumulated session state within that ceiling.
Redis Iris, their real-time context engine, bundles five tools into one runtime: Redis Context Retriever, Redis Agent Memory, Redis Data Integration, Redis LangCache, and Redis Search. The shared idea is one runtime for vectors, caching, memory, retrieval, and operational data, instead of stitching together a separate system for each layer of the context stack.
Redis also emphasizes monitoring. Track retrieval quality (context precision and recall), generation quality (faithfulness and answer relevancy), and resource use (latency, token consumption, cache hit rates). You cannot optimize what you do not measure.
What Production Teams Should Do Today
Start by measuring. Categorize your token spending across system prompts, retrieved context, conversation history, user query, and generated response. The budget framework forces a simple question: does this token improve the response enough to justify its cost?
Then implement compaction before you need it. Do not wait for the context window to hit its limit. Compact proactively at predictable thresholds. Preserve signal. Drop noise. The 80% stale context problem is not a model limitation. It is a design choice that teams can fix with the right architecture.
Sources
- Redis, "Context Compaction for AI Agents: A Complete Guide," redis.io/blog/context-compaction/, May 2026
- Redis, "Context Window Management for LLM Applications: Speed & Cost Optimization," redis.io/blog/context-window-management-llm-apps-developer-guide/, February 2026
- Liu et al., "Lost in the Middle: How Language Models Use Long Contexts," arXiv:2307.03172, TACL 2023
- Chandran and Hossain, "Context Discipline and Performance Correlation: Analyzing LLM Performance and Quality Degradation Under Varying Context Lengths," arXiv:2601.11564, December 2025
- Chen et al., "Slipstream: Trajectory-Grounded Compaction Validation for Long-Horizon Agents," arXiv:2605.08580, Princeton University, 2026
- Redis, "Context Architecture for Production AI Agents," redis.io/guides/context-architecture-for-production-ai-agents/
- Redis, "Redis Agent Memory," redis.io/agent-memory/
- Redis, "Context Retrieval for AI Agents," redis.io/blog/context-retrieval-for-ai-agents/, May 2026
- Zylos Research, "AI Agent Context Window Management: Compaction, Continuity, and Cost Trade-offs," zylos.ai/research/2026-05-05-ai-agent-context-window-management-compaction-continuity-cost, May 2026
- Zylos Research, "Agent Context Compaction for Long-Running Sessions: Techniques and Tradeoffs," zylos.ai/research/2026-04-21-agent-context-compaction-long-running-sessions, April 2026