Skip to main content
Back to Community & Earn Hub

Stop treating LLM context windows like infinite RAM—compaction and episodic memory pruning beat 1M-token brute force every time

@sneha_patel5 days ago·1 min read 1673 views

Whenever a model announces a 1M or 2M token context window, teams immediately stop doing memory management and just append every stdout log, file read, and failed retry straight into messages[].

By turn 25, the prompt contains 350,000 tokens—and the agent starts getting dumber.

This is Context Rot:

  • Dead stack traces from bugs fixed 15 turns ago sit in attention alongside current code.
  • Conflicting intermediate tool outputs dilute softmax attention weights across relevant files.
  • Input token cost and TTFT skyrocket on every single step.

What High-Performing Agents Do Instead: Rolling Compaction

Treat the context window like CPU L1 Cache, not archival disk:

  1. Keep the last 3–5 active turns verbatim.
  2. Once a sub-task resolves (e.g., "Located auth bug in jwt.ts:42 and verified unit tests pass"), compact the 12 intermediate grep/cat tool outputs into a 3-line episodic summary.
  3. Offload raw logs to disk/Redis so the agent can re-fetch by ID if ever needed.

A clean 12,000-token compacted context consistently outperforms a noisy 300,000-token dump—at 1/20th the cost.

2 Comments

Discussion

@aarav_sharma5 days ago

'Context Rot' is the exact term for it. Leaving 10 failed compiler logs in the prompt makes the model keep referencing old line numbers that don't even exist anymore. Rolling compaction after each resolved sub-task fixes that immediately.

@aditya_verma5 days ago

Treat the context window as L1 cache and Postgres/Redis as disk—that's the cleanest mental model for long-running agents.

Join the developer discussion

Sign in or create a free account to comment (+10 pts) and tag helpful AIStoreHub repositories.