Manuscript Offprint

arXiv:2608.24188

Paritok-4B: Intent-Conditioned Context Compression for Coding Agents

Jiayu Shi, Luzhuo Chen

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Coding agents re-send large file reads and tool outputs to a frontier LLM on every turn, and this context dominates their token bill. Prompt-compression models can shrink that context, but general-purpose compressors are trained on prose and are not well suited to code: they paraphrase identifiers and drop the exact spans an agent needs to edit. We present PARITOK-4B, a 4B-parameter LoRA compressor trained specifically for coding-agent trajectories under two design commitments: (i) extractive, so the model selects spans rather than rewriting them—measured over the training corpus, 96.0% of emitted identifiers, paths, and numbers already appear in the input (98.3% outside the one kind we rewrite by design), and the same audit run on held-out SWE-bench Lite output gives 96.2% over 212,506 emitted tokens; and (ii) intent-conditioned, so the compressor is told the agent's current task—which we measure to act chiefly inside a retained segment, selecting which lines survive (retained lines are +0.067 more intent-relevant than removed ones, paired 95% CI [+0.056, +0.078]) rather than changing how much is retained. The compressor operates per segment: a gateway splits the agent request into typed segments and compresses each independently, which makes the unit of work small, parallelizable, and individually recoverable. We build the training set by distilling a gpt-4.1-mini teacher over 67,074 real OpenHands agent trajectories through a five-stage funnel, yielding a 45K-segment distillation pool and 40,606 validated examples, and fine-tune a Qwen3-4B backbone with LoRA, selected over 3B and 7B code-pretrained alternatives under a matched protocol. On an out-of-distribution holdout the released checkpoint emits well-formed output on 100% of segments, compresses to 23.7% of input tokens, and—at that budget—shows no degradation in must-keep identifier retention relative to the teacher it was distilled from (0.385 vs. 0.287 on segments both kept; the paired difference is directionally favorable but not significant at n=39). End-to-end on all 300 SWE-bench Lite instances, PARITOK-4B compresses agent context to 25.7% of its size—2.0× harder than a gpt-4.1-mini compressor (50.2%) and 2.4× harder than gpt-5 (61.9%)—while retaining 86.5% of uncompressed single-shot solve quality, on par with the gpt-4.1-mini compressor at less than half the tokens; run instead in the in-distribution cat -n regime that real agents produce, the same 300 instances compress slightly less (27.8%) and retain more (89.3%), where the paired comparison is the informative one: 30 instances are solved only uncompressed and 17 only compressed, an exact McNemar p=0.079—at this sample size, compressing context to roughly a quarter of its size does not significantly reduce the solve rate. We are explicit (§6.2) that this harness measures comprehension under compression, not end-to-end agent cost. The model is a 264 MB LoRA adapter that self-hosts on a single 24 GB GPU with no per-token compressor fee—which, at list prices, is what decides the economics: we show (§6.3) that gpt-5 used as a compressor is net-negative, costing more to run than the downstream tokens it saves. Weights, data pipeline, and evaluation scripts—including the extractiveness audit—are open (Apache 2.0).

1 Introduction

An autonomous coding agent (Claude Code, Cursor, Codex, OpenHands [7]) solves a task through many turns of reading files, running commands, and editing code [8]. Each turn re-sends the accumulated context—file reads, command output, history—to a frontier LLM, so this input, not the model's output, dominates the token bill. Compressing that context with a small model before it reaches the expensive LLM is an attractive lever, and prompt-compression research shows heavy compression can preserve task quality [1, 2, 3].

But a compressor for coding agents faces constraints that general prose compressors were never built for. First, an agent edits code by exact string match: if the compressor paraphrases a function signature or renames a variable, the downstream edit fails. Second, the value of a segment is not intrinsic—it depends on what the agent is currently doing; the function the agent is about to modify must survive even if it looks unremarkable. Third, agent context is strongly heterogeneous: a cat-n file read, a pytest traceback, an ls listing, and a chain-of-thought block have nothing in common, and a single uniform compression ratio is the wrong tool for all four.

We address these with PARITOK-4B, a 4B LoRA compressor trained on real coding-agent trajectories under two commitments:

  1. Extractive. For code and tool output the model selects spans rather than rewriting them, drawing on a closed, fixed vocabulary of structural markers for what it removes ( §3.1§3.1). Identifiers, paths, and error strings are preserved by copying rather than by the model's judgment about how to reword them—96.0% of emitted identifier-like tokens are already present in the input, and 96.2% on held-out SWE-bench Lite output. We audit this claim rather than assert it, and report where it leaks.

  2. Intent-conditioned. The compressor receives the agent’s current task/query and is trained to keep the entities that task names (its highest-priority rule), so “what matters” is defined relative to the agent’s live intent rather than statically.

A third mechanism, a four-level importance label (L0–L3) carrying a per-level compression budget, is part of the pipeline but is not among the commitments we claim: §4.1 shows the distilled targets realize only two effective bands rather than four, so we report it as a design that did not deliver what it was meant to.

Our contributions are: (1) a reproducible five-stage data pipeline (§4) that turns 67,074 raw OpenHands trajectories into a 45K-segment distillation pool and 40,606 teacher-validated compression examples, with intent-conditioned, level-labeled, must-keep-annotated targets; (2) a training recipe reported with its dead ends (§5): a matched three-backbone comparison behind the 4B choice, a drop-supervision weighting that backfired and why we shipped without it, and a deployed checkpoint chosen by an out-of-distribution sweep rather than by training loss—including why the loss-optimal checkpoint was not the one shipped; (3) an intrinsic evaluation (§6.1) on an OOD holdout, reported with confidence intervals, including the finding that the student's must-keep identifier retention is not below its own teacher's at a comparable budget; and (4) an end-to-end evaluation (§6.2) showing PARITOK-4B reaches a 25.7% compression rate—roughly twice as aggressive as strong GPT compressors—at comparable single-shot solve quality, reported in both the raw-source and the in-distribution line-numbered regime—where the trade we predicted (harder compression at equal quality) is not the one we measured (slightly softer compression at higher quality, and no paired degradation resolvable at 300 instances)—with an explicit account of what the harness does and does not measure.