Why Context Windows Don't Scale with Agent Complexity

Bigger context windows were supposed to solve the memory problem for AI agents. They haven't. Despite a roughly hundredfold expansion in token limits since 2020 (from a few thousand tokens to over a million in models like Gemini 1.5 Pro and Claude), agent performance on complex, long-running tasks has not scaled proportionally. The uncomfortable finding from 2024 to 2026 research is that adding context capacity doesn't remove the architectural ceiling; it just raises it before the same set of problems reassert themselves.

Real solutions require deliberate memory strategies: retrieval-augmented generation (RAG), aggressive summarization, and hierarchical multi-agent memory engineering. None of these are free.

This article explains why the scaling illusion exists, what actually breaks down in long agentic contexts, and how practitioners are designing systems that work within these constraints rather than pretending the constraints don't exist.

Context Rot Is Architectural, Not Incidental

The foundational issue isn't one that better hardware will fix. Standard Transformer attention has no built-in mechanism for prioritizing which tokens matter most as the sequence grows. Every token in the context competes equally for the model's attention, and adding more tokens dilutes the signal from each one. A 2025 study (Hong et al.) testing 18 different LLMs found performance degrading measurably as input length grew, often well before the model's advertised context limit was reached.

This is the "lost in the middle" phenomenon in practice. A model given a 100K-token context window doesn't uniformly attend across all 100K tokens; it tends to weight the beginning and end of the sequence more heavily, leaving critical information buried in the middle effectively invisible. If you're running an agent over a large document collection, a multi-step code repair task, or a months-long conversation, the evidence your agent needs is increasingly likely to sit in exactly that lost zone.

Researchers call the accumulated effect "context rot." It isn't a bug in any particular model; it's a consequence of how self-attention distributes its compute budget. More tokens mean more competition for attention, and more competition means important signals get drowned out. The marketing language around 1M-token windows doesn't make this problem disappear; it makes the window in which the problem manifests much larger.

How Agents Actually Burn Through Tokens

The token consumption pattern in real agentic workflows is far more aggressive than most people expect when they first start building. A naive mental model treats context usage as roughly proportional to the amount of useful work being done. The reality is that context accumulates from every layer of the system, including the overhead.

Consider a moderately complex agent loop handling a software engineering task:

# Rough token budget for a single agentic turn
system_prompt:        ~2,000 tokens   # role, instructions, available tools
conversation_history: ~8,000 tokens   # prior turns (growing each iteration)
tool_definitions:     ~3,000 tokens   # function schemas for all available tools
tool_call_results:    ~5,000 tokens   # file reads, search results, API responses
current_reasoning:    ~1,500 tokens   # chain-of-thought / scratchpad
                     ---------
single turn total:   ~19,500 tokens

# After 10 turns (with no pruning): ~80,000–150,000 tokens consumed
# After 20 turns:                   context saturation in most models

Every web search, every file read, every function return value gets appended to the context. In multi-tool workflows involving code execution, file system traversal, and API calls, a single agent session can consume 100K to 500K tokens before task completion. That's not an edge case; that's a routine debugging or refactoring session on a non-trivial codebase.

This creates a race between window size and task complexity. Context windows are growing, but so are the codebases, document corpora, and workflow complexity that agents are being asked to handle. The gap rarely closes, because the workload scales with ambition, not with infrastructure.

Self-Conditioning and the Compounding Error Problem

Token limits are only one dimension of the problem. Long-horizon tasks introduce a more subtle failure mode: self-conditioning error accumulation.

When an agent reasons over many steps, its outputs at step N become inputs at step N+1. Small misunderstandings, wrong assumptions, or slightly hallucinated facts from early in the sequence become embedded in the context as if they were ground truth. The model then builds on those errors, and each subsequent step has a chance to compound rather than correct them. This is not a token-limit issue that a larger window fixes. In fact, larger windows make it worse: the flawed reasoning from ten steps ago remains fully visible and fully weighted in the attention computation.

Research on long-horizon reasoning agents (including work on InftyThink+ and related architectures) consistently finds that agents lose coherence not because they run out of tokens, but because their accumulated reasoning trajectory diverges from the actual task state. The longer the horizon, the more opportunities for early errors to cascade. This is why researchers have been investing in structured subgoal decomposition and hierarchical reasoning architectures rather than simply pushing context limits higher: the problem they're solving is reasoning coherence, and bigger windows don't buy coherence.

Three Memory Strategies and Their Honest Tradeoffs

Practitioners have converged on three primary approaches to managing context in long-horizon agents. None is universally superior; each makes different tradeoffs across latency, cost, observability, and complexity.

Pure In-Context Learning

Loading everything into the context window is the simplest approach and works well for tasks with bounded scope: answering questions about a single document, summarizing a short meeting transcript, reviewing a small codebase. Recent long-context models have demonstrated that, on well-structured tasks at modest scale, full-context loading can match or exceed RAG in accuracy, because retrieval introduces its own errors (wrong chunk selected, missing cross-references, metadata mismatch).

The costs are significant, though. Inference latency grows with context size, and Transformer attention is quadratically expensive with respect to sequence length, so doubling the context more than doubles the compute. At 100K tokens, latency is noticeable; at 500K tokens, it becomes operationally prohibitive for interactive use cases. The reasoning process is also opaque: there's no way to trace which part of the context drove a particular conclusion, which matters enormously in high-stakes applications.

Retrieval-Augmented Generation

RAG decouples the knowledge store from the inference call. Rather than loading an entire document corpus into context, an embedding-based or keyword-based retrieval system fetches only the chunks most relevant to the current query. The model sees a small, focused context at inference time, which keeps latency predictable and cost manageable regardless of how large the underlying knowledge base grows.

# Simplified RAG pattern for an agent step
def agent_step(query: str, vector_store, llm):
    # Retrieve only what's relevant now, not the entire corpus
    relevant_chunks = vector_store.similarity_search(query, k=5)
    context = "\n\n".join(chunk.content for chunk in relevant_chunks)

    prompt = f"""Use the following context to answer the query.

Context:
{context}

Query: {query}"""

    return llm.complete(prompt)

RAG's real advantage at scale is observability. Because retrieval is a traceable step, you can inspect which chunks were used, rank them by relevance score, and audit why the model produced a particular output. For regulated industries, that traceability is often non-negotiable.

The weaknesses are retrieval failures and cross-chunk reasoning. If the right information wasn't retrieved, or if a correct answer requires synthesizing across many distant document fragments, RAG degrades. It also adds architectural complexity: a vector database, embedding infrastructure, chunking pipelines, and relevance tuning. These are solvable engineering problems, but they're real costs that simple context loading doesn't impose.

Hierarchical Memory Engineering

For genuinely long-horizon tasks, neither pure in-context loading nor simple RAG is sufficient. Production multi-agent systems at scale use hierarchical memory: multiple specialized agents each maintaining their own compact context, with explicit memory management at every layer.

The pattern looks roughly like this: a strategic orchestrator maintains a high-level representation of the task state, current goals, and completed milestones. Tactical subagents handle individual steps with fresh, focused contexts. Completed work is compressed via summarization before being handed back up the hierarchy, so the orchestrator's context stays small even as the total work grows.

Engineering teams building these systems describe the core requirement as an explicit "memory layer" on top of the model: conversation summarization with entity extraction, structured agent profiles tracking goals and recent outputs, and hierarchical abstraction using subgoals to compress history. The infrastructure pieces (vector store, summarizer, entity registry) are distinct from the model itself and must be engineered separately.

# Simplified hierarchical memory pattern
class AgentMemory:
    def __init__(self):
        self.working_memory = []   # recent turns, kept short
        self.episodic_summary = "" # compressed history of completed work
        self.entity_store = {}     # structured facts extracted from history

    def add_turn(self, turn: dict):
        self.working_memory.append(turn)
        if self._token_count(self.working_memory) > WORKING_MEMORY_LIMIT:
            self._compress_oldest_turns()

    def _compress_oldest_turns(self):
        # Summarize the oldest N turns and merge into episodic_summary
        oldest = self.working_memory[:COMPRESSION_BATCH_SIZE]
        summary = summarize(oldest, context=self.episodic_summary)
        entities = extract_entities(oldest)
        self.episodic_summary = summary
        self.entity_store.update(entities)
        self.working_memory = self.working_memory[COMPRESSION_BATCH_SIZE:]

    def build_context(self) -> str:
        # Only present compressed history + fresh working memory to the model
        return f"{self.episodic_summary}\n\n{format_turns(self.working_memory)}"

The cost here is architectural complexity. Hierarchical memory systems require careful design of compression boundaries, summarization quality, and entity resolution. Summarization itself consumes tokens and risks discarding details that turn out to be important later. Naive summarization strategies can introduce the very information loss they're meant to prevent, and getting them right requires iterative tuning of what gets kept versus compressed.

The Quadratic Cost Frontier: Finding the Practical Sweet Spot

Behind all of this is a compute reality that vendors rarely foreground: standard Transformer attention scales quadratically with sequence length. A context that's twice as long doesn't cost twice as much; it costs four times as much in compute, with memory following the same curve. Efficient attention variants (sparse attention, linear attention approximations, sliding window) help, but they make their own tradeoffs: reduced attention scope means reduced ability to integrate information across long distances.

The practical implication is that the advertised capability ceiling (1M tokens, 10M tokens) and the practical operating point for most production systems are very different numbers. Empirical studies from 2025 to 2026 consistently find that the sweet spot for most real-world tasks sits between 32K and 128K tokens. Below that range, context limitations genuinely constrain what the agent can reason about. Above it, the cost-performance curve flattens: you pay quadratically more compute for diminishing reasoning improvements, while attention dilution and context rot continue to erode quality.

This doesn't mean million-token windows are useless. For specific tasks (analyzing a large codebase all at once, or processing a long legal contract without retrieval infrastructure), the extended window is genuinely valuable. But treating it as a general solution to agent scalability is a category error. The research community has largely moved past that framing, even as marketing has not.

Designing for the Constraint

The architects building systems that actually work at scale have internalized a simple reframe: context windows are a design constraint to engineer around, not a resource to maximize. That reframe has practical consequences.

It means choosing RAG not only when the knowledge base is large, but also when observability and latency predictability matter more than raw accuracy on small inputs. It means implementing summarization and entity extraction pipelines before you hit context limits, not after agents start failing in production. It means designing multi-agent systems with explicit handoff protocols and compressed state representations rather than passing full conversation histories between agents.

It also means being skeptical of benchmarks that measure context window capability on needle-in-a-haystack retrieval tasks. Finding a specific string in a long document is not the same as reasoning coherently across a complex multi-step workflow. The former scales with context length, within limits. The latter does not.

Conclusion

The promise that larger context windows would scale AI agent capability has not been borne out by production experience or research evidence. Context rot, attention dilution, quadratic compute costs, and self-conditioning error accumulation are not temporary limitations waiting for a hardware fix; they are architectural properties of the current generation of Transformer-based models.

The practitioners building reliable long-horizon agents aren't waiting for context windows to grow larger. They're investing in retrieval infrastructure to keep context small and focused, summarization pipelines to compress history without losing essential state, and hierarchical multi-agent architectures that multiply effective reasoning capacity by dividing it sensibly. Each of these approaches has real costs in complexity, latency, or fidelity. The job of a thoughtful AI systems engineer is to understand those tradeoffs and choose deliberately, rather than assuming the next model release will make them irrelevant.

Subscribe to Marvin G6 | Engineering, AI & Automation

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe