Manuscript Offprint

arXiv:2609.31430

Compress What You See, Not What You Say: Anchored Context Distillation for Latent-Observation Software Engineering Agents

Zhensheng Zou, Guoqing Wang, Dan Hao

ABSTRACT

Tool observations dominate the context of software-engineering agents, making long interaction histories costly to maintain. Existing context compression methods can discard information needed by later actions, while adapting agents to soft-token representations can compromise their original behavior. To reduce context while preserving action-critical information and agent behavior, we combine Latent Observations, Hard Actions (LOHA), a context layout that separates compressed history from text needed for exact reference, with Anchored Context Distillation (ACD), a training method that enables latent reading while constraining behavioral drift. LOHA compresses older tool observations into soft tokens while retaining the agent's own turns and the last K observations in text, providing compact access to historical information and exact access to recent content. To enable the agent to use this representation, ACD distills the base model's full-text predictions into the latent view while anchoring its behavior on plain-text inputs to the same base model. On SWE-bench Verified, K=3 reduces context per call by 43% for Qwen3-4B and 57% for SWE-Master-4B-RL, with resolve rates of 12.1% and 21.8% versus 14.5% and 27.5% for their uncompressed bases. A single-run recency sweep reaches 14.4% and 23.0% at K=8, with larger windows generally favoring task performance over compression. Under a 32K-token limit, Qwen3 with K=3 resolves 21.1% of a 199-instance subset versus 11.1% for the same adapted agent using full text. In concurrent single-GPU serving, it achieves 1.9× that full-text agent's instance throughput.

1 INTRODUCTION

Large language models are increasingly used as software-engineering agents. To address a GitHub issue, an agent uses tools to inspect the repository, modify source code, and test its changes, refining the patch based on the results (Jimenez et al., 2024; Yang et al., 2024a; Xia et al., 2025; Wang et al., 2025). These interactions produce tool observations, such as file contents, search results, stack traces, and test logs, that accumulate in the agent's context. In CoderForge trajectories (Ariyak et al., 2026), tool observations account for 69% of trajectory tokens on average.

Existing approaches reduce context through observation masking (Lindenbauer et al., 2025), history summarization (Packer et al., 2023; Kang et al., 2026), sub-task folding (Sun et al., 2025; Ye et al., 2025), or selective pruning of tool outputs (Wang et al., 2026a;b; Ren et al., 2026; Chen et al., 2026). These methods shorten interaction histories, but deciding what to discard is difficult when later actions may depend on details in earlier observations. Coding agents also require more than a semantic summary: a str_replace edit, for example, requires an exact match to the source text. Information omitted during compression may therefore have to be retrieved again before the agent can act. Source-code compressors (Shi et al., 2025; Wang et al., 2024) exploit program structure to guide compression, but are less suited to the search results, stack traces, and test logs that also occupy a substantial portion of an agent's context.

Soft-token compression (Mu et al., 2023; Ge et al., 2024; Li et al., 2025; 2026) offers an alternative by encoding text into a shorter sequence of continuous embeddings that the decoder reads directly. For coding agents, however, a useful compressed representation must support both understanding

Figure

Figure 1: LOHA retains recent text and compresses older observations; ACD adds latent reading with a full-text behavioral anchor. Only the adapter, reading patch, and normalization gains are trained.

past observations and reproducing specific details for tool calls. These requirements are distinct: retaining enough information to reason about a file does not necessarily preserve the exact strings needed to edit it. Adopting soft-token representations also requires the decoder to learn a new input representation while retaining its existing ability to reason, invoke tools, and modify code. This raises two closely related questions: how should an agent combine compressed history with access to exact text, and how can it learn to use that history without compromising its ability to act?

We address these questions with a framework that combines context compression with behavior-preserving adaptation (Figure 1). Its two components, Latent Observations, Hard Actions (LOHA) and Anchored Context Distillation (ACD), determine how the agent's history is represented and how the agent learns to use it. LOHA follows a simple principle: compress what the agent sees, not what it says. It represents older tool observations as soft tokens while keeping the agent's own turns, the system prompt, and the task description in ordinary text. To support actions that require exact strings, it also retains the K most recent observations in raw text. This layout provides a compact representation of historical observations while preserving direct access to recent content for precise tool calls. ACD then enables the agent to read the compressed observations while limiting changes to its existing behavior. It combines two complementary objectives: a distillation term aligns predictions from the latent view with those of the frozen base model given the full text, while an anchor term constrains the adapted model's predictions on full-text inputs to remain close to the same base model. Together, LOHA and ACD address the representation and adaptation challenges of using compressed observations in coding agents.

We evaluate LOHA + ACD on SWE-bench Verified with Qwen3-4B-Instruct and its RL-fine-tuned derivative, SWE-Master-4B-RL. At their full context windows, K=3K=3 reduces context per call by 43% and 57%, with resolve rates of 12.1% and 21.8% versus 14.5% and 27.5% for their uncompressed bases. In the single-run recency sweep, K=8K=8 resolves 14.4% and 23.0%, versus 13.6% and 22.2% at K=3K=3, with more text retained and higher compute cost (Table 3a). On SWE-Master, K=3K=3 also outperforms masking (17.6%). Under a 32K-token limit, Qwen3 with K=3K=3 resolves 21.1% of a 199-instance subset versus 11.1% for the adapted full-text agent. Concurrent single-GPU serving achieves 1.9×1.9\times that agent's instance throughput. Our contributions are:

• A context layout for latent-observation coding agents. LOHA combines soft-token representations of older tool observations with uncompressed agent turns and a recent-observation window, providing compact historical context alongside exact text for actions involving recent content.

• Anchored Context Distillation for behavior-preserving adaptation. ACD combines cross-view distillation with a self-anchoring objective to teach latent reading while limiting behavioral drift. Our experiments show that better read-back performance alone does not ensure better agent behavior and identify self-anchoring as an effective way to balance the two.

• An empirical evaluation of the performance–efficiency trade-off. We compare task success and context usage on both an instruction-tuned agent and an RL-fine-tuned agent, and examine context limits and serving throughput. The results characterize the performance cost of compression and the settings in which it provides practical benefits.

References (100)

Couldn't load all references. Reload the page to try again.