$npx skillfedfor your agent
REPO

Deletion beats summarization when your agent needs exact values to survive compaction

on: tamaratran/fast-jev-compaction

Context compaction in long agentic sessions is a real problem, and the usual answer — ask a model to summarize old turns — has a real flaw: summaries drop exact values. A file path, a precise error message, a constraint stated once and never repeated: any of these can vanish in a paraphrase, and the agent proceeds as if it never knew them. This library takes a different position. It never rewrites anything. It only deletes.

The mechanism is surgical. Every tool_use is paired with its tool_result by ID. A separate model — Jev, from TypeSafe's API — is shown the whole conversation (with tool results replaced by short length notes to save space) and asked two binary questions per non-pinned call: does knowing this call was made still matter, and are the verbatim contents of its result still needed? Scores above a configurable threshold (default 0.5) determine whether a call-result pair is kept whole, kept with a truncated result, or dropped entirely. User and assistant text is never touched in the output.

The state-fitting logic is elaborate and honest about it. When the conversation is too large to send, the library applies a cascade of compression stages — truncating tool inputs progressively, abridging long texts to head-plus-tail, collapsing old messages to single-line summaries — and throws if none of it is enough. Token counting is done without a tokenizer, using a character-based heuristic the README describes as deliberately calibrated to land slightly high. That is a real limitation: the estimates are not exact, and the library says so plainly.

The Claude Code integration is the practical entry point for most users. As a function-hook plugin (requiring Claude Code 2.1.274 or later with an opt-in flag), it intercepts /compact and auto-compaction events, runs the Jev scoring, and falls back to the built-in summary if Jev fails or if the reduction is insufficient. The toast message distinguishes the two outcomes, which is a small but useful transparency detail.

The architectural choice to repeat the full state with every request batch is worth noting as a cost consideration: a long history near the state ceiling means multiple round trips, each carrying the same context. The library is upfront about this in its limitations section.

The SwiftUI demo app is a curiosity — a scripted, non-live visualization of the compaction flow built for screen recording. It never calls the API. Its existence suggests this was built with some care for presentation, which is neither a virtue nor a flaw in the underlying library.

For anyone building agents where exact values in tool results matter downstream — and that is most serious agentic work — the deletion-only approach is a principled alternative to summarization. Whether Jev's probabilistic scoring is reliable enough to trust in production is a question the library cannot answer for you; it surfaces the per-call decisions and stats so you can judge.

Deletion-only context compaction that preserves exact values by never rewriting anything — a principled trade-off with real costs worth understanding before deploying.

Install it

Sources & links