Keep the working set alive

Context Window Management

Context window management is the operating discipline around a curated prompt: budget the window, refresh stale state, summarize only with a loss budget, and measure when more context stops helping.

Key facts

Context Window Management

  • Context-window management is a loop: budget, assemble, monitor, compress, refresh, and evaluate.
  • Every long-running agent or chat system needs a policy for what stays active, what gets summarized, what moves to memory, and what is re-retrieved.
  • A context budget should reserve output tokens before adding history or retrieved evidence.
  • Overflow is not only a token-count problem; stale state, duplicates, buried conflicts, and unlabeled snippets can all degrade the working set.

A context window is not managed only when it overflows. It is managed every time a system decides which user history, tool result, retrieved passage, memory, and instruction deserves active attention. The goal is a prompt that remains small enough to inspect and large enough to solve the current task.

"curating and maintaining the optimal set of tokens"
Effective Context Engineering for AI Agents

Start with a budget, not a pile

Treat the context window as a budget with named accounts. Reserve output tokens first, because a system that fills the entire window with input forces the model to answer with too little room. Then allocate input tokens across system instructions, active conversation state, retrieved evidence, examples, durable memory, and tool results.

Each account should have a purpose. System instructions control behavior. History preserves recent intent and unresolved decisions. Retrieved evidence grounds the answer. Examples teach shape or edge cases. Memory carries stable facts. Tool results update the live state. When two accounts contain the same fact, the budget should keep the fresher or more authoritative copy.

Use tiers instead of one memory dump

Long-running systems need tiers. The active prompt should contain current task state and decisive evidence. A short summary can keep recent decisions available. A durable memory store can hold stable preferences, project facts, and source pointers. A retrieval layer can reload detailed documents when the current task needs them.

This keeps old material available without forcing every old token into every new generation. MemGPT made this tiered-memory framing explicit: the active window is one tier among several, not the whole memory system.

Refresh stale context deliberately

Context stales in different ways. A retrieved policy can be superseded. A conversation summary can preserve the old plan but miss a new constraint. A tool result can be accurate when read and wrong ten minutes later. A memory can be true for one project and false for another.

Good systems mark freshness at assembly time: source date, retrieval time, owner, confidence, and why the item was included. When the user asks a current-state question, the system should prefer re-retrieval over trusting a stale active copy.

Compress with a loss budget

Compaction and summarization are context-management tools, but they must be explicit about what cannot be lost. Dates, amounts, permissions, unresolved blockers, source conflicts, exact user constraints, and failing-test text are all common casualties of vague summaries.

A safer summary states what it kept, what it dropped, and which source IDs can recover the original detail. When the next task depends on a high-risk fact, re-open the source instead of trusting a summary.

Watch for context rot signals

Context rot often appears before hard overflow. The model stops citing decisive evidence, follows older instructions over newer ones, repeats stale assumptions, or gives a generic answer despite specific passages being present. These are working-set failures.

Instrument the context assembly, not only the final answer. Log which sources were selected, where they were placed, how many tokens each account consumed, whether conflicts were labeled, and which citations appeared in the answer. Then test whether removing duplicates, moving the decisive source, or compressing a low-signal section improves quality.

A minimal management loop

  1. Reserve output tokens before adding input context.
  2. Classify every candidate token as instruction, task state, evidence, example, memory, tool result, or output contract.
  3. Rank evidence by answer impact, authority, freshness, and conflict coverage.
  4. Compress only after naming what must not be lost.
  5. Re-retrieve stale or high-risk sources instead of relying on old summaries.
  6. Evaluate whether the assembled working set improves the task at acceptable cost and latency.

Sources Used

Cite This Page

Curated Context. "Context Window Management." Accessed July 6, 2026. https://curatedcontext.com/context-window-management

https://curatedcontext.com/context-window-management