Every long-running agent eventually faces the same arithmetic: the context window is finite, the task history is not. What separates agents that degrade gracefully from agents that quietly lose the plot is what they choose to keep — because compaction is not a storage problem, it is a judgment call about which information still constrains future behavior.
Keep what still binds, drop what's spent
Anthropic's context-engineering guide frames context as a budgeted resource where every token competes for the model's attention. The keep-list is shorter than most teams expect: the system policy, the current objective, unresolved constraints ("never push to main", "the user chose option B"), recent actions and their results, exact error messages, and the identifiers future tool calls will need. The drop-list is everything already spent: duplicated prose, superseded attempts, tool outputs whose conclusions have been extracted, exploratory dead ends.
The subtle failure is dropping something that looked spent but still binds — a commitment made 40 turns ago, a constraint stated once. This is why compaction summaries must separate verified facts from hypotheses, and why they should link to durable artifacts (files, PRs, notes on disk) instead of paraphrasing critical code or numbers — a paraphrase drifts; a path does not.
Why more context isn't the answer
Long-context models tempt teams to skip compaction entirely. Measurement says otherwise: Chroma's context-rot study ran 18 models across needle-retrieval and long-conversation tasks and found performance degrades non-uniformly as input grows — even on tasks a short context handles perfectly. Distractors accumulate, attention dilutes, and the model starts answering from the wrong region of history. Relatedly, agents that re-read their whole raw history each turn pay the cost problem on top of the accuracy one.
Compact early, resume honestly
Trigger compaction before the window forces it — a compaction under pressure has no room to be careful. And treat resumability as a testable property: after compacting, can the agent state its current objective, its open commitments, and what it must NOT redo (side effects already executed)? An agent that re-sends an email after compaction because the "already sent" fact got summarized away is the canonical failure. Sliding windows preserve recent local detail; periodic summaries compress the old; durable state (task lists, decision logs, memory files) lives outside the window entirely and gets re-read on demand — the pattern every production harness converges on.
Sources: Anthropic — Effective context engineering for AI agents · Chroma — Context rot.
Related: context rot, agent memory tiers, token budgets, cost control.