Memory Metabolism
Provide explicit ways to forget working debris: sub-agent isolation, viewport closing, and structured compaction contracts that minimize Handoff Loss.
Halfway through a library migration, a coding agent is moving 112 call sites from an old billing client, legacy-billing, to its replacement, billing-v3. It's the kind of task teams hand to agents gladly: long, repetitive, and easy to check with tests.
The first thirty turns are exploration. The agent greps for every call and gets 400 matches back. It reads the 3,100-line generated types file for the new SDK. It spends a while on a compatibility shim that turns out to be a dead end. It runs the test suite three times and reads three long stack traces.
At turn 31, reading the SDK source, the agent finds the one thing that matters. In billing-v3, amount is an integer number of cents. The old client took decimal dollars. The agent writes one line in its reasoning ("v3 amount is cents, so convert with toCents()") and migrates the first 40 call sites correctly.
At turn 58 the context window is full, and the harness compacts it automatically: it replaces the whole session with a short summary. The summary mentions the shim, the test failures and the import fixes. It doesn't mention cents. The agent picks up from the summary and migrates the remaining 72 call sites, passing dollars where the new client expects cents. Both versions are plain numbers, so the type checker is happy. The unit tests mock the billing client, so they pass too.
The pull request looks clean and consistent. Merged, it would charge a customer on a $49.00 plan 49 cents. The agent learned the right answer, used it, and then lost it, buried under its own exploration.
Why it happens
A context window is the agent's entire working memory, and it only grows. Every tool result stays in it until the session ends or something removes it. The total amount of text competing for attention at any moment is the window's context loadLexicon · 13Context LoadTotal tokens competing for attention inside the context window.. In the hook, nearly all of it was debris: two full reads of a 38,000-token file, a 12,000-token grep, three test logs and a 20,000-token dead end. The cents fact was about 40 tokens.
A person doing the same migration has a natural metabolism. They skim the types file and forget most of it by lunch. They close the tab with the grep results. They write "amounts are in CENTS" on a sticky note and put it on the monitor. People forget the noise on their own and keep the signal on purpose. An agent does neither unless the system around it is built to.
Size is a problem even before anything is forgotten. Large blocks of text pull the model's attention and its next words toward themselves, so the most voluminous material tends to dominate what the agent thinks about next. The Guide calls this pull token gravityLexicon · 16Token GravityBulky or salient tokens warping subsequent next-token probabilities toward themselves.. A 38,000-token file has a lot of it. A one-line observation buried between two such files has very little.
Then the window fills, and the harness has to make room. The usual way is context compactionLexicon · 45Context CompactionLossy compression of a session ribbon to reclaim window capacity.: the harness asks a model to compress the session into a summary and starts over from it. Compaction is always lossy, and a free-text summary loses things in a predictable direction. The summarizer feels the same gravity, so it writes about what took up the most space. The shim dead end produced 20,000 tokens and earns a sentence. The cents fact produced 40 and earns nothing.
A free-text summary records what took the most space. The fact that mattered took the least.
The figure below shows the hook's context window as a ribbon of blocks, each as wide as its token count. Start with the window full and find the cents fact, then compact it under each of the three strategies and see which ones keep the fact.
Turn 57: window 97% full. The fact is 40 of 193,540 tokens. Main window 97% full. Fact survives: not yet compacted.
Watch the summary in the first strategy. Each topic gets space in rough proportion to how much text it produced. Nothing in that process asks which facts later steps depend on. The other two strategies fix that in two different places. One decides what to keep before compaction runs. The other keeps the debris from entering the window at all.
When a verified fact or a decision's rationale vanishes across a compaction, or across a handoff from one agent to another, the Guide calls it handoff lossLexicon · 46Handoff LossDisappearance of verified facts and rationale across compaction or delegation.. It's quiet by nature. The agent after the handoff doesn't know what it lost, so it doesn't ask. It fills the gap with the most plausible guess, and for a number with no unit attached, the plausible guess is "same as before."
What it costs
Wrong work that looks right. Handoff loss rarely produces an error. It produces work that is consistent, confident and built on an old assumption. In the hook, 72 of 112 changes were wrong in the same way, and the clean, uniform pattern made them easier to approve.
Paying twice for the same knowledge. An agent that half-remembers something often goes looking for it again. Re-reading the types file after compaction costs another 38,000 input tokens, and it puts the same debris right back into the window. Compaction then has to run sooner. Long sessions without a way to shed debris end up compacting more and more often, losing a little each time.
Reviewers who can't trust long sessions. If the only defense is a human checking every change from turn 58 onward, the long task you delegated comes back to you as a long review. Teams respond by keeping agents on short tasks, which is exactly where they're least useful.
Rationale that disappears. Free-text summaries tend to keep decisions and drop their reasons. A summary that says "abandoned the shim" without the why invites the next agent, or the next human, to try the shim again.
The fix
In plain words: forgetting has to be designed. Give the agent explicit ways to drop what it no longer needs, and a protected place to keep what it must not lose. That takes three mechanisms.
- Explore in a disposable context. Send noisy foraging, like reading a 3,000-line file to answer one question, to a sub-agent with its own fresh window. It reads everything and returns a short answer with evidence. Its debris is thrown away with it.
- Close what you've finished reading. Let the agent fold a file read, a log or a search result into a one-line stub with a handle to reopen it. Debris that is still useful later can live outside the window, a call away.
- Compact into a contract. Replace the free-text summary with a typed record of goals, verified facts with evidence, invariants, progress and ruled-out paths. Better still, let the agent write facts into it the moment it verifies them, so compaction never has to decide whether they matter.
This rhythm of taking in context to work, then deliberately shedding it, is what the Guide calls an inhale / exhale loopLexicon · 44Inhale / Exhale LoopsAlternating between acquiring working context and deliberately shedding debris.. Most harnesses are very good at inhaling. Exhaling usually happens only when the window overflows, which is the worst possible moment to decide what matters.
Here is the compaction from the hook, before and after. The left side is a typical free-text summary. The right side is a handoff contract the agent filled in as it worked.
Summary of work so far: Migrating billing calls from legacy-billing to billing-v3. Explored the v3 SDK. Spent time on a v2 compatibility shim; abandoned it because the shim does not support idempotency keys. Ran the test suite several times and fixed import errors in checkout and invoices. 1 Migrated 40 of 112 call sites. 2 Next: continue migrating the remaining files. 3
- 1Most of the summary describes the shim and the test runs, because they produced the most text. Their outcome is useful, but they crowd out the one fact every remaining edit depends on.
- 2Progress is a count without a list. The agent has to rediscover which 72 call sites are left, which means another 12,000-token grep.
- 3"Continue migrating" sounds like a complete instruction. It invites the agent to repeat the pattern from memory, and the memory no longer contains the conversion.
{ "goal": "Move all 112 billing calls to billing-v3", "verified_facts": [ 1 { "fact": "v3 amount is integer cents; v2 took dollars", "evidence": "billing-v3/src/charge.ts:88", "turn": 31 } ], "invariants": ["convert every amount with toCents()"], 2 "progress": { "done": 40, "total": 112, "remaining": "worklist://billing/3" }, 3 "ruled_out": [ 4 { "path": "v2 compat shim", "why": "no idempotency keys" } ], "open_questions": [], "debris": "notes/migration-log.md" 5 }
- 1The fact survives word for word, with the file and line that prove it and the turn it was verified. A later agent can trust it or recheck it in one call.
- 2The invariant turns the fact into a rule for every remaining edit. It's the sticky note on the monitor, and it is easy to check in review.
- 3Progress points to a worklist handle instead of restating it. The agent reopens the list of 72 remaining files instead of grepping again.
- 4Dead ends are kept with their reason, so neither the agent nor a human retries the shim.
- 5The raw exploration goes to a file outside the window. A human can audit it later and the agent can reopen it, but it no longer costs tokens on every turn.
Walk through the pins in order. Pin 1 is the whole heuristic in one field. A verified fact is a different kind of thing from a note about what happened, and the contract gives it its own slot. The evidence pointer matters as much as the fact. It lets the next reader confirm the fact cheaply instead of taking it on faith.
Pin 2 converts knowledge into a rule. "Amounts are cents" is a fact about the SDK. "Convert every amount with toCents()" is a property of every remaining edit, and both the agent and a reviewer can check it line by line.
Pins 3 and 5 are about exhaling without losing access. The worklist and the exploration log both live outside the window, behind short handles. Nothing is truly deleted. It just stops costing attention on every turn. Pin 4 keeps the conclusion of the dead end and drops its 20,000 tokens of process.
The contract costs about 40 more tokens than the summary it replaces. The bigger change is when it gets written. A contract filled in at turn 31, when the fact was verified, doesn't depend on a summarizer at turn 58 recognizing its importance.
The same pattern in other places
The contract shape travels well beyond compaction. Anywhere context crosses a boundary, the same three questions apply: what is verified, what is still open, and what was ruled out.
| Boundary | Lossy version | Metabolic version |
|---|---|---|
| Sub-agent returns | the full transcript, or "done" | a short answer, evidence pointers, what it did not check |
| Agent hands off to agent | the parent's chat history | goal, verified facts, open questions, ruled-out paths |
| File read finished | 3,000 lines stay in the window | a one-line stub: path, what was learned, a handle to reopen |
| Session ends | nothing, or a chat log | the contract written to the task tracker or the repo |
| Human takes over | "see the trace" | the same contract, which doubles as a status report |
The sub-agent row deserves a closer look. A sub-agent is the cheapest way to exhale, because its debris never enters the main window at all. The Guide calls agents that fork into several helpers parallel selvesLexicon · 11Parallel SelvesA single agent user forking into multiple concurrent sub-agents.. Their value depends on the return trip: a sub-agent that dumps its full transcript back into the parent has moved the debris without shedding any of it.
In MCP terms
Compaction happens in the host, so MCP has little to say about it. What an MCP server can do is make debris cheap to put down and easy to pick back up.
- Resource links (
resource_link). A tool can return a link to a resource instead of its body. The resource'ssizein bytes is there, in the MCP spec's words, to help hosts "estimate context window usage." Aread_filethat answers the question and links the 3,100-line types file lets the host decide whether the whole file ever enters the window. - Handles (the spec's stateful-tools guidance). To the protocol, a handle is an ordinary string in one tool result and an ordinary argument to the next call, which is exactly what the contract's worklist pointer is. The guidance asks you to state a handle's lifetime in the description of the tool that creates it, and to return a tool error that says so when one has expired.
- Content priority (
annotations.priority). Any content block can carry a priority from 0 ("entirely optional") to 1 ("effectively required"). A host could drop low-priority blocks first, though the spec never mentions compaction. - Not in the protocol. Compaction, summaries, handoffs and sub-agents all belong to the host, and so does the handoff contract. A server's part is summary-first results and handles that bring back anything compaction dropped in one call.
Spot it in your traces
Here is the hook session around the compaction, as it would appear in a trace log. Watch turns 1 and 3: the fact enters the window and then silently leaves it.
- T1
read_file("billing-v3/src/charge.ts")→ 3,100 lines (about 38,000 tokens)Line 88: amount is integer cents. The old client took dollars, so every call needs toCents().The right conclusion, stored only as one line of reasoning next to 38,000 tokens of source. - T2
edit_file("src/checkout/charge.ts")→ ok: amount: toCents(order.total)The first 40 call sites are migrated correctly. - T3
[harness] compact_session()→ about 195k tokens replaced by a 90-token summaryThe summary mentions the shim and the test runs. The cents fact is not in it. - T4
edit_file("src/subscriptions/renew.ts")→ ok: amount: plan.priceSame pattern as before: swap the client, keep the arguments.Dollars passed as cents. The agent repeats the pattern it remembers, which no longer includes the conversion. - T5
run_tests()→ 412 passed, 0 failedAll green. Migration complete.The tests mock the billing client, so a green suite proves nothing about units.
Every call in that trace succeeded. To find the same failure in your own logs, look for these signals:
- Behavior that changes at a compaction boundary. Diff the agent's edits from just before a compaction against those just after. A pattern that was present before and missing after, like a conversion, a flag or a check, is the signature of handoff loss.
- Facts that appear once and never again. Search the reasoning for verification language ("confirmed", "so it must", "line 88 shows") and check whether that fact appears in the post-compaction summary. If it doesn't, the summary is shaped by volume.
- Re-reading after compaction. The same large file or the same grep, issued again within a few turns of a compaction, means the summary dropped something the agent knew it needed.
- Single results that eat the window. Rank tool results by size as a share of the window. Any one result above roughly 10% is debris the agent had no way to put down.
- Sub-agents that return transcripts. Compare a sub-agent's return size to its own total context. If the return is more than a few percent of what it read, it isn't exhaling for the parent.
Review checklist
Run these against your harness and any tool that returns large results. Most checks need one long test session.
- Give the agent a structured place to record verified facts as soon as it learns them, with evidence and the turn number.How to check Ask the agent to verify one fact from a file early in a session. A
verified_factsentry with a file and line should exist before any compaction runs. - Compact into a typed contract (goal, verified facts, invariants, progress, ruled-out paths, open questions) instead of free text.How to check Force a compaction in a test session. The output should parse against the schema, and every verified fact recorded before should still be in it, word for word.
- Carry the contract forward verbatim on every compaction, outside the part the summarizer rewrites.How to check Run three compactions in a row on one session. Diff the
verified_factssection across all three: nothing should be lost or reworded. - Let the agent close large reads: fold a file, log or search result into a one-line stub with a handle to reopen it.How to check Read a large file, then close it. The window should shrink by roughly the file's size, and the stub should contain the path and a reopen call.
- Route exploration that reads more than it returns to a sub-agent, and cap what the sub-agent sends back.How to check Give the agent a question that needs a 3,000-line file. The parent's window should grow by hundreds of tokens, not thousands, and the answer should cite a file and line.
- Make progress resumable from a handle, not from memory.How to check After compaction, ask the agent what is left. It should open a worklist or tracker by handle instead of searching the codebase again.
When laws collide
Forgetting on purpose saves attention, but it can work against laws that want information kept close at hand.
- Pulls against · H-01Continuous State AnchoringWhere they clashContinuous State Anchoring wants the live state visible on every turn so the agent never reconstructs it. Memory Metabolism wants the window lean. Pinning a large status block to every turn makes it permanent context load that no compaction can shed.How to have bothKeep the pinned state small and overwrite it instead of appending: current branch, budget, the contract's invariants, a handle to the worklist. Anything bigger lives behind a handle. The anchor and the contract can be the same object, refreshed in place.
- Works with · H-03Token Hygiene & High Observation YieldHow they combineToken Hygiene keeps debris from entering the window. Memory Metabolism removes the debris that got in anyway. One is a filter on the way in, the other a drain on the way out.What you getWith lean tool outputs, compaction runs later and has less to discard. With a working drain, the occasional unavoidable firehose, like a full stack trace you really needed, stops being permanent.
- Works with · H-15Temporal Proprioception & Verification GatesHow they combineTemporal Proprioception tells the agent how much budget and window it has used. That is exactly the signal it needs to exhale on its own schedule instead of waiting for an emergency compaction.What you getAn agent that sees "window 70% full" can close finished reads, record its facts and delegate the next exploration before the harness has to step in. Compaction becomes a routine step the agent prepares for.
Model size shifts the balance but doesn't remove the problem. Larger windows delay compaction, but they also hold more debris, so token gravity has more mass to work with when it finally runs. A contract helps every model tier for the same reason a sticky note helps every engineer.
Terms from this page
- 13Context Load
- Total tokens competing for attention inside the context window.
- 16Token Gravity
- Bulky or salient tokens warping subsequent next-token probabilities toward themselves.
- 45Context Compaction
- Lossy compression of a session ribbon to reclaim window capacity.
- 46Handoff Loss
- Disappearance of verified facts and rationale across compaction or delegation.
- 44Inhale / Exhale Loops
- Alternating between acquiring working context and deliberately shedding debris.
- 11Parallel Selves
- A single agent user forking into multiple concurrent sub-agents.