← Table of Contents · Page 218 of 868

COMPACTION AND SUMMARIZATION

Part 2 of 10

WHAT IS COMPACTION Compaction means summarizing older history to reclaim space. The word comes from compacting trash or soil, meaning squeezing it into a smaller volume. Here is the idea in everyday terms. Imagine you are a manager who has been reading a long email thread with forty messages. A new person joins the project and asks what has happened. You do not forward all forty emails. You write a short briefing: what was asked, what was tried, what failed and why, and what is being attempted now. The newcomer can then continue the work with only that briefing plus the last few emails. Compaction does exactly this for an agent. The harness takes the older part of the conversation, asks a model to write a compact briefing of it, and replaces the original messages with the briefing. The window shrinks, but the thread of the work continues. It is important to understand that compaction is lossy. Lossy means some information is lost, as when you shrink a photo and fine details disappear. A summary can never contain everything. So the art of compaction is deciding what to keep, and the engineering of compaction is protecting against losing something vital. Summarization is the general act of writing a shorter version of a text. Compaction is summarization applied to an agent's own history in order to free up space. The two words are closely related, and in practice people often use them together. WHEN TO COMPACT: TOKEN-THRESHOLD TRIGGERS When should the harness compact? If it waits until the window is completely full, it is too late, because there is no room left to even perform the summarizing step, and the model's answer also needs space. If it compacts too early and too often, it wastes effort, loses detail unnecessarily, and spends money on summarization calls. The usual solution is a token-threshold trigger. A token-threshold trigger is a rule that starts compaction automatically when the context reaches a chosen fraction of the maximum window. For example, the rule might say, "When the context reaches 80 percent of the window, begin compaction." Think of the low-fuel light in a car. It does not wait for the tank to be empty. It warns you early enough that you can reach a gas station. Choosing the threshold involves trade-offs. A low threshold, such as 50 percent, compacts frequently, keeps contexts small and sharp, and lowers cost, but loses detail more often. A high threshold, such as 95 percent, preserves more raw detail, but risks failure if a single large tool result arrives and pushes the window over the limit. Many teams choose something in the range of 70 to 85 percent as a starting point, then adjust after measuring. The right number depends on how large a single step can be. If one step can add 20,000 tokens, then the margin below the limit must be at least that big, plus room for the answer and the summarization call itself. A helpful formula is: threshold equals window size, minus the largest expected single addition, minus the reserved answer space, minus the room needed for the summary step, all divided by the window size to give a percentage. You do not need to memorize the formula, but you should understand its logic: the trigger must fire early enough that the worst plausible next step still fits. There are also other kinds of triggers. A step-count trigger compacts every fixed number of turns. An event trigger compacts at natural breakpoints, such as when a subtask finishes. A combination is common: compact at a natural breakpoint if one occurs after the context passes a soft threshold, and compact immediately at a hard threshold regardless.
Advertisement
Read Aloud:
0:00 / 0:00