We wanted a single agent session to keep working beyond its context window without repeatedly rewriting its history into summaries. Our approach is deterministic, model-free eviction guided by structure the agent declares as it works.
What is CWL?
Context Window Lifecycle (CWL) is a context-management scheme for long-horizon LLM agents. Instead of summarizing history, it evicts content deterministically using agent-declared episodes and dependencies. In our Terminal Bench 2.0 evaluation, a single session handled 89 sequential tasks and over 80 million tokens at approximately $55 per complete run.
This post is about why we think summarization-based compaction is the wrong default, what we built instead, and where the design is honest about its costs. The full paper can be read here (results in §6.3); this is the short version aimed at people who are themselves building agent harnesses and have opinions about context management.
The paper implementation is also open source and can be found in our repository.
Why is compaction the wrong abstraction?
Summarization compaction uses a model call to fix a problem caused by model calls. When the context approaches its limit, older history is handed to an LLM and replaced with a summary. For concrete implementations, see pi’s compaction reference and LangChain’s SummarizationMiddleware. Both document summarizing older messages while retaining recent ones; this is a specific mechanism, not a claim that every framework uses the same policy.
We think this is the wrong default for a structured record of work. In §1 of the paper we identify four risks of summarization-based compaction:
- Lossiness is unpredictable. What the summarizer keeps and drops depends on its instantaneous judgment of salience, which is not the same as what the downstream agent will actually need to continue its work after compaction. The compacted context alone does not reveal what was thrown away.
- Structure is not preserved. The original trajectory has explicit causal structure made of tool calls, agent reasoning blocks, file reads, and executed bash commands and their outputs. Prose summaries collapse this into narrative and can lose the provenance the agent would need to revisit its own reasoning.
- Compression is expensive and blocking. A compaction pass is a full LLM call over a large slice of the context window, paid in seconds of latency and tokens-in-tokens-out.
- Summarization can introduce errors mid-task. A generated summary can add errors just when the agent has less context available to detect and correct them. The benchmark evaluation does not directly measure hallucination rates.
How does CWL compare with summarization compaction?
| Property | CWL | Summarization compaction |
|---|---|---|
| Extra model calls | No model call for eviction; agent supplies annotations. | A model call generates the summary. |
| Determinism | Deterministic eviction given the episode graph. | Retained content depends on the summarizer. |
| Token cost | Annotation overhead during work; no summary-generation tokens. | Input and output tokens for each summary. |
| Information loss | Graduated stripping; fully evicted exploration keeps only its description. Depends on annotation quality. | Lossy prose summary; may omit causal structure or introduce errors. |
| KV-cache | In-place edits invalidate the affected prefix and subsequent cache state; frequent eviction can be net-negative. | Resets cache at compaction, then leaves a stable prefix until the next pass. |
These are design tradeoffs, not a controlled measurement of information loss. The paper’s direct comparison with compaction is a qualitative case study (§6.5): CWL inference cost was 23% lower in sequences on Excalidraw, Redis, and the Linux kernel. Both strategies struggled with QEMU validation; the CWL run needed manual assistance. That result is not a general cost guarantee.
How does CWL evict context without a model call?
The agent can mark structure in its own trajectory as work proceeds: whether it is gathering information or acting on it, and which prior information an action uses. CWL relies on those annotations rather than asking another model to reconstruct the structure later.
Context Window Lifecycle (CWL) uses them. The agent annotates its trajectory through a single tool, delimiter, marking episode boundaries and declaring dependencies between them. The annotations accumulate into a typed dependency graph. When token accounting reports the budget has been exceeded, a deterministic policy walks that graph and evicts content in priority order.
There are two episode types:
Exploratory episodes are where the agent gathers information — search results, file reads, directory listings, retrieved documents. These episodes carry the substantive content the agent reasons over. They are the information layer of the trajectory.
Action episodes are where the agent does work — edits, writes, tool calls that change the environment. Their content in the transcript is thin: the substantive information lives in the exploratory episodes they depend on, and the effects of the action live in the environment, not in context.
When opening an action episode, the agent declares which exploratory episode(s) it’s drawing on. This is the dependency edge, and it’s what makes the eviction policy semantically aware rather than just temporally ordered.
Illustrative delimiter calls look like this (protocol in §4.2):
// Opening an exploratory episode — agent is about to gather information
{ "action": "start", "name": "locate-auth-middleware", "type": "expl" }
// ... tool calls happen here: grep, file reads, directory listings ...
// Closing it — description is the residue kept after full eviction
{ "action": "end",
"description": "Auth lives in src/middleware/auth.ts; uses JWT via jose; token claims validated in verifyToken()." }
// Opening an action episode — must declare which exploration it depends on
{ "action": "start",
"name": "add-refresh-token-rotation",
"type": "act",
"dependencies": ["locate-auth-middleware"] }
// ... tool calls happen here: file edits, bash commands ...
// Closing it — no description, since the effects live on disk, not in context
{ "action": "end" }The eviction policy is a loop. It walks the dependency graph and selects the oldest eligible action episode first, because action episodes carry little information of their own — their content is mostly a record of edits that are already reflected on disk and reconstructible by inspecting the environment. Exploratory episodes are evicted only after the action episodes that depended on them have themselves been evicted. Otherwise the agent would have a decision in context with no access to the reasoning behind it.
Within a selected episode, content is stripped in a specific order, from least to most informative:
- Exploratory reasoning traces first. Extended chain-of-thought is often a small fraction of the episode’s tokens, and its conclusions are by construction reflected in the tool calls that follow it.
- Bulk search outputs next — grep, glob, ls, directory listings. These are the noisiest content in the trajectory: the agent was scanning through them looking for something specific, and most of what they returned was never used and can be quickly re-acquired.
- Intermediate artifacts after that — file reads, bash commands and their outputs. These carry real signal the agent actually wanted, so they go later.
- Full episode removal as the last resort.
User turns are never touched. The prologue and active episodes are also protected. If no eligible eviction can meet the budget, CWL surfaces that condition rather than removing user content (§§3–4).
What does eviction cost in tokens and KV-cache reuse?
CWL is not free. Its in-place evictions invalidate cached state from the affected prefix onward. Under sustained token pressure, repeated cache writes can cost more than uncached inference. In this narrow sense, CWL can be worse than compaction, which leaves a stable prefix between passes (§5).
We capped the active token budget τ at 80,000 tokens in the benchmark configuration. The paper reports 20–70% lower inference cost relative to uncapped sessions, depending on task structure (§5). That is not the same comparison as the fresh-session benchmark baseline, where shorter suites showed little to no cost difference (§6.3).
Budget sensitivity matters (§6.4). Above 120,000 tokens, cost rose without an accuracy improvement. Around 50,000 tokens, inference cost fell by up to 3× relative to the 120,000+ baseline, but wall-clock time per task rose by up to 2× as the agent re-explored evicted material. Those observations concern the evaluated workloads, not a universal optimal budget.
What do the benchmark numbers show?
All experiments used GPT-5.4 in our pi.dev fork (§6.1). We evaluated on Terminal Bench 2.0 (89 tasks, n=5 runs), SWE Bench Lite (50-task sample, n=3), Recovery Bench (n=3), and LongCLI Bench (n=3). The CWL condition runs all tasks of a benchmark sequentially in a single uninterrupted session. The baseline runs each task in a fresh isolated session — the standard protocol for these benchmarks.
This is a deliberately asymmetric comparison (§6.2), not a controlled head-to-head benchmark against summarization compaction or an apples-to-apples leaderboard comparison. We wanted to test whether a session accumulating history could sustain task performance under a fixed budget, not whether CWL improves accuracy.
- CWL · one session
- Baseline · fresh session per task
Mean accuracy was 68.25% vs. 68.40% on Terminal Bench 2.0, 43.00% vs. 40.00% on SWE Bench Lite, 66.80% vs. 69.75% on Recovery Bench, and 20.00% vs. 20.00% on LongCLI Bench (CWL vs. fresh-session baseline; §6.3 and Figure 2).
Recovery Bench was lower with CWL by 2.95 percentage points. The paper describes differences of at most 3 percentage points as within run-to-run variance and cautions against interpreting their direction. These initial runs do not establish exact equivalence or guarantee no degradation on other tasks.
What are the limitations?
We observed behavioral changes in the model that we couldn’t conclusively attribute to CWL. In some sessions the model rushed exploration with less thoroughness than it showed without CWL; in longer sessions it occasionally over-explored, revisiting already-annotated material or looping over actions without apparent progress. These behaviors overlap with ordinary planning failures, and we couldn’t isolate CWL as the cause in individual cases. Our tentative read is that the annotation protocol introduces a layer of meta-reasoning the model has to do alongside the task, and that this is mildly confusing for current models. If that’s right, the effect should diminish as model capability improves.
Dependencies point to whole exploratory episodes, not individual tool calls. Whether that granularity is sufficient remains an empirical question (§7).
The current design assumes a linear stream of episodes with non-linearity expressed only through dependency edges. Whether richer structure (subgraphs, subtask roots) is needed for agents that branch, backtrack, or run parallel subtasks is open.
Annotation has a token and reasoning cost. Misclassifying an episode or omitting a dependency can evict information the agent still needs; deterministic eviction does not make the annotations correct. Maintaining and traversing the graph also has a host-process cost that can become non-negligible with many episodes (§5).
Terminal Bench tasks are independent, so that result alone does not establish preservation of cross-task dependencies. The repository case study probes that question qualitatively, with the manual-assistance caveat above (§6.5). The paper presents initial results from one model and harness; larger evaluations, more runs, and ablations remain future work (scope on p. 3).
Where can you try CWL?
CWL is an initial research implementation, released so others can try and critique the approach. It is open source as a fork of pi.dev: github.com/Kiz8-Team/pi-cwl. The full paper has the architecture, the empirical setup, and the design principles in detail.
If you’re working on this and want to compare notes, we’d be glad to; please reach out to ands@kiz8.team.
Kiz8 — 2026