Module 2 · Tools, Knowledge, Memory & Research Design · scripted
Compaction: The Handoff to Yourself
The wall approaches
There is a problem we have been walking toward for a while now, and a long-running agent eventually walks into it: the conversation outgrows the wall. Every iteration appends; nothing leaves. Watch the numbers on a real trajectory:
Iteration 41 of a long-running agent
…and the recurrence has been billing that growing wall on every single iteration along the way.
Two different limits can stop the loop, and it matters which one you design for:
The two limits
THE HARD LIMIT the window's edge. The next result physically
cannot land on the wall. No choice remains.
THE CHOSEN LIMIT a budget: "never pay for more than N words per
iteration." A line you draw far inside the
edge — crossed long before the wall is full.
Well-designed agents almost never hit the hard limit,
because they act at the chosen one.So we must remove something. The question is what — and it is a far deeper question than it looks.
The wrong scissors
The obvious move: the conversation is too long, so delete the oldest messages. They're the stalest — surely they're the safest to cut? Watch what happens:
[earlier messages removed]
⟨tool_result⟩
Booking search complete: SAS 07:15 Molde–Oslo–Trondheim, 2,890 kr,
non-refundable. Widerøe 09:40 direct, 4,120 kr, refundable.⟨tool_use⟩
book_flight(option = "SAS 07:15", fare = "non-refundable")⟨tool_result⟩
Booked: SAS 07:15, non-refundable, 2,890 kr.I've booked the cheaper SAS option — 2,890 kr, saving 1,230 kr against the direct flight.
Age is simply the wrong axis. Some of the oldest words are the most load-bearing; some of the newest are already worthless. We need to cut along a different axis entirely — and finding it requires a small revelation about what "efficient" even means.
Efficiency can only be measured from here
Here is the revelation. Take one conversation and judge it twice — once in the middle of its work, once near the end:
The same wall, judged at two moments
Not one word on the wall changed. The DESTINATION changed.
The principle
Signal-to-noise is not a property of the conversation. It is a relation between the conversation and the work that REMAINS. The value of a word on the wall is not what it did — it is what it still does for what is left.
This explains the strange feeling every long conversation produces: it was efficient the whole way along, and yet it is inefficient now. Both are true. Every iteration of the loop moves the destination closer, and every step quietly re-prices every word behind it. The scaffolding around a finished wall was load-bearing during construction — that doesn't make it part of the building.
So run the thought experiment that turns this into a mechanism: if a fresh agent had to start right now and finish only the remaining work — what would you write as its opening prompt? Not the transcript. Nobody briefs a newcomer by reading them the minutes. You'd write the goal, the current state, what was decided and why, what remains. That document — short, forward-facing — is the ideal conversation for this exact moment. And it is not the history.
The core idea
The best prompt for finishing a task is not the history of the task. Compaction is how we trade the one for the other.
The shift change
Humans solved this problem long ago, in places where the work never stops but the workers must. At 07:00 in every hospital, the night nurse hands over to the day nurse — and does not replay the shift:
Two ways to hand over a shift
The handoff report is compaction, performed by professionals every twelve hours. And the move we're about to make is exactly this — with one twist that makes it stranger and simpler at once: the agent is handing off to itself. Same task, same seat — but the incoming worker gets a briefing instead of a transcript.
The compaction call
Now the mechanism, and notice that it's built entirely of parts we already own. Compaction is self-dialogue pointed at the conversation itself: the whole history goes into a disposable exchange, a summary comes back, the loop restarts on it. Here is the prompt that does it — read it closely, because every line is a design decision:
The compaction prompt
"Below is the full conversation of an agent mid-task. Rewrite it as a briefing for an agent that must COMPLETE the task, in at most 800 words. Preserve exactly:
Collapse each COMPLETED subtask to one line: what was done → its result. DROP: intermediate attempts, corrected errors, superseded drafts, and the contents of tool results whose conclusions are already captured above."
That keep-list is where the judgment lives — it is the axis the scissors should have cut along all along: not old versus new but still-load-bearing versus scaffolding. Watch it run:
⟨tool_use⟩
compact_conversation(max_words = 800)⟨tool_result⟩
BRIEFING (replacing 41 iterations):
GOAL: reconcile the department's Q3 travel expenses; constraint
(user, verbatim): "flag anything over policy rather than fixing it
silently."
DONE: (1) 34 receipts extracted → table T1 (12 flagged unusual).
(2) Policy check complete → 9 within policy; 3 over-limit: rows
4, 11, 29 of T1. (3) Rule learned: log_expense requires ISO
currency codes and absolute dates.
REMAINING: draft the summary report; flag rows 4, 11, 29 with
amounts and policy clauses; await user decision on the flagged
three.
OPEN: row 29's receipt was illegible — amount is OCR's best guess.[new loop, iteration 1 — the briefing above is the conversation] Continue the task.
⟨tool_use⟩
draft_report(source = "T1", flag_rows = [4, 11, 29])- Which line of the keep-list protects against Example 1's disaster?
- "Collapse each completed subtask to one line" — when is that rule wrong? Find a case where an intermediate step still matters after its subtask succeeded.
- Who wrote this compaction prompt? Who should write it — the agent's designer, or the agent?
The archive: nothing lost, merely not loaded
Compaction is judgment, and judgment is fallible: the summarizer cannot perfectly predict what the future will need. Row 29's uncertainty made the briefing — but what about the vendor name the summary dropped, the one the user suddenly asks about? The answer is a pattern you already know from designing results: don't delete the past — archive it behind a handle, and say so on the wall:
The compaction marker — a result that instructs
[COMPACTED: 41 iterations (118,000 words) archived as conv-88. The briefing above summarizes them. If you need a detail it omits: search_history(conv, pattern) · read_turns(conv, from, to) · ask_history(conv, question) are available.]
The conversation's own past has become a document among documents — and the whole retrieval ladder applies to it: search it, page it, ask it.
Wait — which hotel was row 11? My department head is asking.
The briefing flags row 11 as over-limit but doesn't name the vendor. That detail is in the archived conversation.
⟨tool_use⟩
ask_history(conv = "conv-88", question = "For expense row 11 of
table T1: vendor name, amount, and dates?")⟨tool_result⟩
Row 11: Hotel Union Geiranger, 6,840 kr, 12–14 July (extracted at
iteration 19).Row 11 is Hotel Union Geiranger — 6,840 kr for two nights in July, which is what put it over the lodging limit.
The price of rewriting
One honest complication. The caching lesson taught append-never- rewrite: identical prefixes are cheap, so never edit history. Compaction deliberately breaks that rule — the new briefing shares no prefix with the old wall, so the first iteration after compacting pays full price, plus the cost of the summarization itself. This is a real trade, not a free lunch:
Two cost curves
The curves cross. Before the crossing, compaction is premature. After it, every iteration without compacting is a small overpay — and the crossing is exactly where the CHOSEN limit belongs.
This is why the chosen limit from the start of the lesson isn't timidity — it's arithmetic. You compact when the toll beats the compounding, not when the wall forces your hand.
What must survive — and what may safely die
Look once more at the keep-list's fourth line: rules learned along the way. The conversation spent real money learning them — an error taught the ISO-code rule; a manual taught the calibration protocol. Compact carelessly and the agent forgets — and re-errs, and re-pays.
But notice what we built earlier, and how it catches this exact fall: if the tools teach their rules at the moment of violation, then a forgotten rule costs one corrected error, not a derailed task. The two designs are partners:
A symbiosis
Instructive errors make forgetting SURVIVABLE — the world re-teaches any rule the summary dropped. Compaction makes remembering AFFORDABLE — the wall stays small enough to keep running. Design both, and the conversation can stay light precisely because the world around it is instructive.
- Rank the five keep-list items by the cost of losing each. Which loss is caught cheaply by an instructive error — and which one is caught by nothing at all?
- A conversation's tone — caution learned from a near-miss, the user's irritation at verbosity — rarely survives a briefing. Does that matter? When?
The trajectory, unburdened
End where the threads meet. A conversation is a trajectory — but a trajectory is a path, not a cargo hold. Its obligation is to reach the destination, not to carry every step that came before. The agent cannot see its own wall, so the loop's designer manages it on the agent's behalf: a chosen limit, a compaction prompt whose keep-list encodes what "still matters" means for this task, a marker that instructs, and an archive with handles. The conversation becomes, at intervals, its own editor — pausing to write the briefing it wishes it had, and then becoming it.
The one-liner
A trajectory is not obliged to carry its whole past. It is obliged to reach its destination.
Take the longest agent transcript you have — or one we provide. (1) Draw the cut line where you would compact, and defend it with the two-limits arithmetic. (2) Write the compaction prompt for this task: your keep-list, your drop-list, your word budget. (3) Produce the briefing and restart the task from it. (4) Audit the run: what did the compacted agent do differently, what did it reach into the archive for — and what got lost that neither the briefing nor the archive brought back?