Compress What You See, Not What You Say: Anchored Context Distillation for Latent-Observation Software Engineering Agents
Organizations: Peking University
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 times that full-text agent's instance throughput.
Figures & tables
| Qwen3 | SWE-Master | |||
|---|---|---|---|---|
| res. | dec PF | res. | dec PF | |
| 80 | 1.47 | 128 | 2.99 | |
| 8 | 72 | 2.10 | 115 | 8.37 |
| 4 | 76 | 2.08 | 108 | 4.49 |
| 3 | 68 | 1.67 | 111 | 3.74 |
| 2 | 65 | 1.40 | 103 | 2.93 |
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
| Family / condition | additional run | main runs, per seed | mean sd |
| Qwen3-4B-Instruct-2507 family (Table 1 ) | |||
| Uncompressed anchor | — | 73 / 75 / 69 | 72.3 3.1 (14.5%) |
| LOHA plain text | 80 | 64 / 68 | 66.0 2.8 (13.2%) |
| LOHA Hard-Last-3 | 68 | 60 / 61 | 60.5 0.7 (12.1%) |
| Masking ( ) | — | 63 / 65 / 55 | 61.0 5.3 (12.2%) |
| SWE-Master-4B-RL family (Table 2 ) | |||
| Qwen3-4B family | SWE-Master family | |||
|---|---|---|---|---|
| Policy | res. | dec PF | res. | dec PF |
| plain text ( ) | 80 | 1.47 | 128 | 2.99 |
| Hard-Last-8 | 72 | 2.10 | 115 | 8.37 |
| Hard-Last-4 | 76 | 2.08 | 108 | 4.49 |
| Hard-Last-3 | 68 | 1.67 | 111 | 3.74 |
| Hard-Last-2 | 65 | 1.40 | 103 | 2.93 |
LLM Context Management
Large language model context management studies how to select, compress, retrieve, and organize information within bounded model inputs.
See all 250 papers