An agent's context window is working memory. It is fast, volatile and finite, and the model itself keeps nothing between API calls, so the memory layer has to write and retrieve deliberately per this Redis overview. The MemGPT paper made the operating-system analogy concrete: a small main context (system instructions, a writable working block, a FIFO of recent messages) backed by external storage, with paging in and out as the window fills in the arXiv abstract. An explainer of the architecture notes that recursive summarization fires when the prompt nears capacity and evicted messages stay searchable in this Emergent Mind summary.
Truncation is the crude version of that idea: drop the oldest turns and keep going. It works until the oldest turn held something the agent still needs, such as the order id a user gave forty turns ago or the exact constraint a reviewer imposed. Folding is the alternative. When a segment of work closes (a task completes, a time window ends, a ticket resolves), you replace its raw entries with one short record that keeps the load-bearing facts and summarizes the narrative around them.
The case for discipline is measurable. A study of the compaction cliff reports that on 20 production agent configurations, Claude Code's /compact prompt on Sonnet 4.6 preserved 53% of safety rules after one compaction round and 10% after five from the paper's abstract. The authors' point is about fairness: an episodic log and a safety rule compete for the same tokens, but only the rule needs exact wording to remain enforceable. Their Knowledge Triage framework classifies each item by type and routes each type through its own retention policy, preserving two to four times more safety rules than the strongest single-shot LLM compactor at every compression ratio in the same paper.
That is the whole design principle in one sentence: compaction is not a uniform squeeze, it is a triage with per-type fidelity.



