AI Coding Agents
Reversible Compression for Agent Tool Output
Reversible compression for agent tool output sends a smaller result first and keeps the omitted information available through a decoder, retained original, or search index. It pays when the input charges avoided across a task exceed storage-related overhead and the cost of extra model calls that recover details. Test what the agent can restore before relying on it for exact evidence.
Choose what recovery needs to return
A compressed test result might show a failing test, its assertion, and a handle to the full output. An index might instead return passages matching the failing test’s name. Both can reduce the immediate model input, but the agent needs different procedures to recover the original evidence. For diagnosis, a matching excerpt can be enough. For a decision that depends on exact order, a complete file, or the absence of a warning, specify which representation the agent must see before it decides.
| Approach | What the agent sees first | What it can ask for later |
|---|---|---|
| Headroom CCR | Compressed content with a path to retrieval | Original content through headroom_retrieve, subject to configured retention |
| Tokenfold Core | An eligible folded payload, with retrieval markers if opted-in pruning removes content | Application-side decode for lossless formats, or retrieval of stored omissions on the pruning path |
| context-mode | Selected output or a result from a local query | Relevant chunks through ctx_search over SQLite FTS5 |
| Billion Context | Summaries of folded conversation ranges | Range restoration through decompress, or keyword search of summaries and visible messages |
| Caveman proxy | A smaller tool result, with annotations for folded content where applicable | Stored originals through the documented recovery path |
These mechanisms describe project behavior in the captured READMEs. Treat recovery as an end-to-end feature of the configuration you run. A full original on disk gives the agent little immediate help if it lacks the reference, the retrieval tool is out of scope for a subagent, or the session no longer has access to the data.
Stored originals and search serve different jobs
Headroom describes Compress, Cache, and Retrieve, or CCR, as keeping originals locally for a configured lifetime. The model can ask for the original with headroom_retrieve. This lets you give the model a compact result first while retaining the output it can inspect if a key datum is missing. Test an ordinary recovery call and a request made after the expected retrieval window. Record what message the agent gets if the reference is no longer available. Headroom CCR
Caveman’s proxy README describes writing an original to disk before sending the cut result. It describes a query-aware trim-2 path and includes caveman_retrieve calls in its own benchmark accounting. The terse-output skill changes what the model writes. For a trial of recoverable input compression, verify that the proxy’s input feature is the one engaged and record its recovery calls separately. Caveman proxy and recovery
context-mode’s README describes retaining output in a local SQLite full-text index while returning the parts the agent asks for. A query can pull a useful excerpt from a long log without making the next prompt carry the whole log. Search quality depends on the query and what the index returns. Test a distinctive error string and also a case where adjacent lines supply meaning. An open feature request asks for a way to return an entire stored source. That makes full replay a separate requirement to validate if the task needs it. context-mode indexing · Whole-source retrieval request
Billion Context works on message ranges. Its README describes a proxy that lets the model fold consumed conversation into incremental summaries and later restore a range using decompress. A search over summaries and visible messages helps locate relevant context. If the model recalls a decision but needs the exact command or original result that supported it, restoration can require bringing more context back than a narrow search hit. Measure the resulting request size and cache usage. Billion Context
Check where lossless decoding happens
Tokenfold Core’s README describes folding repeated structure, such as moving common JSON keys into a column list shared by rows. It says the lossless transforms pass an exact decode round trip before the folded result is emitted. A consumer seeing folded JSON still needs to interpret the representation correctly. If an application needs native objects, decode at the boundary where that shape is required. If you send the folded representation to a model, check its ability to answer about row values and field names before relying on savings. Tokenfold review
The same README distinguishes opt-in pruning, which stores omissions before removing them and emits retrieval markers. That path can add a tool call later. Structural folding can keep the information in the representation itself and allow programmatic decoding without a model round trip. Ask whether recovery is a deterministic decoder, a lookup based on a retained reference, or a model’s decision to search. Compare overheads using the path your product actually exposes.
Price the first send and the extra retrieval turn
For an estimate, take the committed Anthropic claude-sonnet-5-5 rates checked November 30, 2026. Fresh input costs $2, cache reads cost $0.10, cache writes cost $2.50, and output costs $10 per million tokens. For any billed request, multiply each bucket’s token count by its rate, sum the products, and divide by 1,000,000. Current provider rates
Assume sending a raw result takes 10,000 fresh tokens. The compact response, including the reference, takes 2,000 fresh tokens. Hold all other work constant until the agent decides whether to recover details. On an assumed extra request for a targeted recovery, suppose the provider bills 100,000 tokens as a cache read and 2,000 as fresh input, including the returned excerpt. Assume 1,000 generated tokens across the retrieval call arguments and the additional continuation, and no cache writes. The read and fresh figures describe the extra request rather than the original turn. These are scenario assumptions.
| Event | Estimated charge |
|---|---|
| Raw result, fresh input | 10,000 × $2 ÷ 1,000,000 = $0.020 |
| Compact result, fresh input | 2,000 × $2 ÷ 1,000,000 = $0.004 |
| Extra recovery request and generation | (100,000 × $0.10 + 2,000 × $2 + 1,000 × $10) ÷ 1,000,000 = $0.024 |
With no recovery the compact path saves an estimated $0.016 on the first send. With that recovery the path costs $0.028 for the measured events, or $0.008 more than the raw result. With the same assumptions across a task mix, multiply the extra recovery estimate by the fraction of tasks that need it. Break-even is the first-send saving divided by the extra recovery cost, which is two-thirds here. A whole-original retrieval with more fresh input, an additional cache write, or multiple follow-ups would lower the tolerated retrieval rate. Further cheap reuse of the compact representation can increase the savings.
Use the whole task ledger in production. A recovery request may reuse only part of a prefix or arrive after a cache miss. The next ordinary request may also carry the recovered material. Tool calls that fetch several excerpts can sometimes share a continuation, while a dependency between queries can force more turns. Meter the actual model output spent deciding how to recover, along with the tool execution and waiting time. Context compression versus prompt caching
Decide how much to recover
For a noisy test log, start with the result and the immediate failure context. If the agent next needs to identify an upstream warning, a search that returns adjacent lines can be cheaper than restoring the entire log. If the task is to audit whether any other failures occurred, require enough coverage to support that conclusion. A search that returns no matches establishes only what was queried and what the index could find. Keep complete output in the trial for tasks that depend on examining every line.
Match the retrieval operation to the source. Use a source reference tied to the original invocation if exact evidence is needed. A fresh file read can be appropriate for a task that needs current code, while restoration is appropriate for reasoning about what the original run saw. If the tool restores a whole conversation range, check which later requests carry that range. A narrow excerpt returned from an index can have a different lifetime in the transcript than a restored history segment.
Compare compressed recovery with a deliberately bounded original read. For a short file or a dense diff, requesting the relevant line range at the start may fit the task and avoid the extra query. For a verbose output with repeated headers, preserving a compact result and a pointer can keep the basic diagnosis cheap while retaining a path to exact text. Measure the turns the agent actually takes to follow that pointer.
When the cost of being wrong is high, compare accepted outputs as well as usage. An agent can arrive at a correct edit with a broad summary while giving an unsupported account of why it worked. Require a reference to source evidence in the rubric if that is important to the workflow. Count the model turns needed to produce the citation, and check that the retrieved excerpt and its provenance survive to the final answer.
Make recovery part of the acceptance test
Build one diagnostic where the first summary should suffice and another where a decisive line lies outside it. Include a case where the raw source is required in order and one where an excerpt is enough. Start each attempt from the same task state. Compare against sending the full result and check which apparent successes still depend on claims the model cannot support from the text it saw.
Verify that an agent can tell it received a compact representation. A short fragment that looks complete can prevent the model from knowing it should retrieve anything. It should have a usable reference or search query and a clear fallback when the original expires. Test with the exact adapter, subagent scope, and session lifecycle you plan to use. If your setup retains outputs across a restart, verify references in a restarted session. Otherwise check the failure behavior when the store disappears.
Decide who can read retained artifacts and when they expire. A compressor can reduce what the model sees while leaving a fuller local copy in storage. Test whether the store is scoped to the right task and workspace, and whether recovery returns the version of the source that produced the compact result. In a changing repository, rereading the current file may return different evidence. In an index with similar output from several attempts, including the source identity and run can help the agent pick the right excerpt.
Use a compact first response when details are usually unnecessary, the recovery mechanism is reliable, and the savings outlast any extra calls. Keep dense, decision-critical evidence in the first response when the agent repeatedly has to request it anyway. Evaluate long sessions on both cost and usable context, since a recovery path can let a task continue under the context limit even when the immediate dollar savings are small.
Sources
- Headroom local originals and CCR (GitHub, accessed 2026-11-30)
- Tokenfold structural folding and opt-in pruning (GitHub, accessed 2026-11-30)
- context-mode local full-text indexing (GitHub, accessed 2026-11-30)
- Billion Context range folding and restoration (GitHub, accessed 2026-11-30)
- Caveman proxy and stored originals (GitHub, accessed 2026-11-30)
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
Reversible Compression for Agent Tool Output. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/reversible-context-compression/