Part 3 of 16 · 2 min read
Compaction is a deterministic stub; summarisation is a lossy model call
One of these two ways to shrink the history costs nothing and can be undone; the other costs a model call and cannot.
Think of a receipt. Compaction puts the receipt in a labelled folder: the whole thing kept but out of the way, fetchable later. Summarising writes a note about the receipt and throws the receipt away instead. The note is shorter, but it can leave out the one number you later need.
In plain words: compaction replaces content that has already been processed with a lightweight, deterministic stub and no model call, which makes it reversible in principle and cheap. Summarisation replaces a span of history with a model-written rewrite instead. That rewrite is lossy, non-deterministic in what it keeps, and costs an extra model call on both its input and its output.
A worked example. clear_tool replaces an old tool result with a stub stating exactly how many tokens were removed and how to restore it -- no model is called, and the original is still fetchable by re-running the tool. rolling, by contrast, folds the oldest 40% of the budget plus the previous summary into a new model-written summary capped at 25% of the budget, at a real cost: 24,349 summariser tokens across 21.4 rounds per task, for a strategy that ends up only 42% accurate against structured state's 96%, at nearly the same total token cost.
The key lines. From code/mini-compact/compact.py:
# from code/mini-compact/compact.py
def _clear_tools(self) -> None:
for i, t in enumerate(self.buffer[:-self.keep_recent]):
if t.role == "tool" and not t.text.startswith("[tool output cleared"):
self.buffer[i] = Turn(t.step, "tool", f"[tool output cleared: {tokens.count(t.text)} tokens; re-run the step {t.step} tool to restore]")
self.cleared += 1
Read it as: the stub's own text states the size removed and how to restore it, and no summariser is called anywhere in this function. Compaction's defining property is right there in the code. It is a pure, local rewrite of one item, not a model call over a span. That is exactly why it is both free and reversible in a way summarisation structurally cannot be.
Compaction, summarisation
Compaction replaces content that has already been processed with a lightweight reference or stub, deterministically and without a model call; it is reversible in principle and cheap. Summarisation replaces a span of history with a model-written summary; it is lossy, non-deterministic in what it keeps, and costs a model call.
Example: a tool result replaced by a stub that says "re-run the step 12 tool to restore" is compaction you can reverse by actually re-running that tool -- there is no equivalent sentence you could write for a summary that silently dropped one of five decisions, which is the practical difference between the two.