Paper: 2607.18213 Authors: Yuhang Wang, Yuling Shi, Shaoqiu Zhang, Jialiang Liang, Shilin He, Siyu Ye, Yuting Chen, Kai Cai, Xiaodong Gu Categories: cs.CL, cs.SE
The Gap
Coding agents like SWE-Bench solvers call tools (grep, find, cat) and get back long outputs — sometimes thousands of lines. Most of that output is irrelevant to the current task. Feeding it all into the context window wastes tokens, slows inference, and can actually hurt performance due to “lost in the middle” effects.
The prior art here is SWE-Pruner (same group’s earlier work), which trains a separate code classifier — an external model that reads tool output and decides which lines to keep. The problem: you need to train and run a whole extra model, it adds latency, and it can’t see what the agent is actually “thinking” at the moment it reads the output.
The key finding of this paper is observational: when a coding agent processes tool output, its own internal hidden states already encode relevance signals. The agent “knows” which lines matter — you just need to extract that knowledge. This eliminates the need for a separate classifier entirely.
Problem: Tool outputs are huge, context windows are finite
|
v
Prior approach (SWE-Pruner): Train separate classifier to predict relevance
|
v
Limitation: Extra model = extra cost, can't see agent's internal state
|
v
Insight: Agent's own hidden states already encode line-level relevance
|
v
Method: Small head on agent representations + length-aware embedding
|
v
Evidence: 39% token savings, +3.8% resolve rate on SWE-Bench Verified
|
v
Conclusion: The agent itself is the best judge of what to prune
The Increment
One sentence: Before this paper, you needed a separate model to decide what context to cut; after this paper, the coding agent’s own internal representations serve as that judge, making pruning cheaper, faster, and more accurate.
Core Mechanism
SWE-Pruner Pro has three components: (1) a line-level feature extractor that reads hidden states from the agent’s transformer layers for each token in a tool output, (2) a length-aware embedding that encodes how many total lines the tool output has (so the pruning head adapts its behavior to different output sizes), and (3) a lightweight classification head that outputs a keep-or-prune probability for each line.
The data flow is straightforward. The agent reads a tool output as usual, producing hidden states at every token position. The method pools these hidden states to get one vector per line. It concatenates each line vector with the length-aware embedding (which is looked up from a small learned table keyed to the output’s line count, bucketed into ranges). The classification head — a two-layer MLP — then scores each line. Lines below a threshold get pruned from the context before the next agent turn.
Tool output (N lines)
|
v
Agent processes normally (hidden states at each token)
|
v
Pool hidden states --> one vector per line
|
v
Concatenate with length-aware embedding
(length embedding = lookup table, bucketed by N)
|
v
Classification head (2-layer MLP)
|
v
Keep / Prune label per line
|
v
Pruned context fed to next agent turn
Think of it like a building superintendent deciding which boxes to move out of storage. Previously (SWE-Pruner), you’d hire an outside appraiser to walk through the storage unit and tag each box as “keep” or “toss.” The appraiser has never met the tenant and doesn’t know what they’re working on. Now, SWE-Pruner Pro says: skip the appraiser. Instead, watch the tenant’s face as they walk past each box. Their expression — the hidden states — tells you exactly which boxes they care about. The length-aware embedding is like the superintendent noting “this is a small closet” vs. “this is a warehouse” — the decision policy shifts depending on how much stuff there is. The classification head is just the superintendent reading the tenant’s expression and stamping “keep” or “toss” on each box.
Key Concepts
-
Internal representations as implicit relevance signals: When a transformer model reads a passage, its hidden layers don’t just “process” text uniformly — attention patterns and residual activations vary by token, reflecting how much each part matters to the model’s current task. This paper’s insight is that you don’t need to build a relevance detector from scratch; you can read the agent’s own “body language.” Concrete example: if the agent is trying to fix a bug in
utils.py, its hidden states when reading lines ofutils.pywill look fundamentally different from when it readsREADME.md— and a simple linear probe can pick that up. -
Length-aware embedding: A small learned vector that conditions the pruning head on how long the current tool output is. The intuition: if a tool output has 50 lines, you might keep 30; if it has 5000 lines, you might keep 200. The threshold should be adaptive. The authors implement this by bucketing output lengths into ranges and learning one embedding per bucket, concatenated to each line’s hidden-state vector before classification.
-
In-context pruning vs. pre-processing pruning: SWE-Pruner (the predecessor) prunes tool outputs *before they enter the agent’s context, using an external classifier. SWE-Pruner Pro prunes inside the agent — the agent sees the full output, and then the pruning head operates on the agent’s own representations. This is architecturally different: the pruning decision happens after the agent has “read” the output, not before.
Framework Shift
Before (mainstream approach): After (this paper):
Tool output Tool output
| |
v v
Separate classifier model Agent processes output normally
(trained independently) |
| v
v Agent's own hidden states
Keep/Prune labels |
| v
v Small learned head
Pruned context |
| v
v Keep/Prune labels
Agent processes pruned output |
v
Pruned context
(for next turn)
From “outsourcing the pruning decision” to “the agent judges its own reading,” the core shift is that the model doing the understanding is now the same model doing the pruning — eliminating the gap between comprehension and selection.
Expert Assessment
Problem choice: This is a real, practical gap. Context management for coding agents is a genuine bottleneck — everyone working on SWE-Bench-style systems deals with it. The observation that hidden states encode relevance is not surprising in hindsight (probing studies have shown this for years), but applying it to tool-output pruning for agents is a clean, useful contribution. It sits at the intersection of efficient inference and agent design, which is a hot trajectory.
Method maturity: This is a clever insight executed with minimal machinery — a 2-layer MLP head and a lookup table. That’s a strength, not a weakness. The simpler approach being overlooked? Possibly just truncating tool output by recency or keyword matching, which might get you 60% of the benefit at 0% overhead. But the paper does show meaningful quality improvements, not just savings, which elevates it above simple heuristics.
Experimental integrity: The baselines are reasonable — they compare against SWE-Pruner (the predecessor) and no-pruning baselines across multiple benchmarks (SWE-Bench Verified, Oolong, and others) and two backbones (Qwen2.5-Coder and MiMo-V2-Flash). The +3.8% resolve rate improvement on SWE-Bench Verified with MiMo-V2-Flash is notable — it’s rare for a pruning method to *improve accuracy, which suggests the original context was actually hurting via noise. One concern: the paper tests on a limited set of backbones. Would this generalize to GPT-4-class closed models where you can’t access hidden states? Probably not without API changes, which limits applicability.
Writing quality: The paper is clearly written and well-structured. The related work section is thin — it doesn’t engage deeply with the broader probing/interpretability literature that motivated the approach. The ablation study could be stronger: how much does the length-aware embedding matter vs. just using a fixed threshold? That’s the kind of detail that would elevate the paper from good to solid.
Verdict: weak accept — Clean idea, practical results, but the insight (agents encode relevance internally) is more evolutionary than revolutionary, and the experimental scope could be broader.
Takeaways
Three things you can steal:
-
Probe before you build: Before training a separate model for any selection/filtering task, check whether the main model’s hidden states already encode the signal you need. A quick linear probe can save you months of classifier engineering. This transfers to RAG (retrieval), summarization, multi-document QA — anywhere you’re filtering context.
-
Length-aware conditioning is cheap and effective: If your downstream decision depends on the size of the input, add a bucketed embedding. It’s a 10-line change that gives you adaptive behavior without complex architectures.
-
Pruning can improve quality, not just save cost: The MiMo-V2-Flash results show that removing noisy context *helps the agent reason better. This is a strong argument for aggressive pruning — you’re not just saving tokens, you’re reducing distraction. If you’re building coding agents, test whether shorter context actually beats longer context.
论文: 2607.18213 作者: Yuhang Wang, Yuling Shi, Shaoqiu Zhang, Jialiang Liang, Shilin He, Siyu Ye, Yuting Chen, Kai Cai, Xiaodong Gu 分类: cs.CL, cs.SE
缺口
编码智能体在调用工具(grep、find、cat)后,会收到大量输出——动辄数千行。 其中大部分与当前任务无关,全部塞进上下文窗口既浪费token、拖慢推理,又会因”中间遗忘”效应损害性能。
前代工作 SWE-Pruner 的做法是训练一个独立的代码分类器——一个外部模型,读取工具输出后判断哪些行该保留。 问题在于:你需要额外训练和运行一整个模型,增加了延迟,而且这个外部模型根本看不到智能体此刻在”想什么”。
本文的关键发现是一个观察性结论:编码智能体处理工具输出时,其内部隐状态已经编码了相关性信号。 智能体”知道”哪些行重要——你只需要把这种知识提取出来。 这就彻底消除了对独立分类器的需求。
问题:工具输出巨大,上下文窗口有限
|
v
前代方案(SWE-Pruner):训练独立分类器预测相关性
|
v
局限:额外模型 = 额外成本,且无法感知智能体内部状态
|
v
洞见:智能体自身隐状态已编码行级相关性
|
v
方法:在智能体表示上加小分类头 + 长度感知嵌入
|
v
证据:节省39% token,SWE-Bench Verified解决率+3.8%
|
v
结论:智能体本身就是最佳的裁剪决策者
增量
一句话: 在此之前,你需要一个独立模型来决定裁剪什么上下文; 在此之后,编码智能体自身的内部表示就是那个裁判,让裁剪更便宜、更快、也更准。
核心机制
SWE-Pruner Pro 有三个组件: (1)行级特征提取器,从智能体的Transformer层读取工具输出中每个token的隐状态; (2)长度感知嵌入,编码工具输出的总行数(让裁剪头根据输出规模自适应调整行为); (3)轻量分类头,对每行输出保留或裁剪的概率。
数据流很直接。 智能体像往常一样处理工具输出,在每个token位置产生隐状态。 方法将这些隐状态池化,得到每行一个向量。 将每个行向量与长度感知嵌入拼接(长度嵌入来自一个小型学习查找表,按输出行数分桶)。 分类头——一个两层MLP——然后为每行打分。 低于阈值的行在下一个智能体回合前被裁剪掉。
工具输出(N行)
|
v
智能体正常处理(每个token的隐状态)
|
v
池化隐状态 --> 每行一个向量
|
v
拼接长度感知嵌入
(长度嵌入 = 查找表,按N分桶)
|
v
分类头(两层MLP)
|
v
每行 保留 / 裁剪 标签
|
v
裁剪后的上下文送入下一回合
用一个结构性比喻来理解:想象一栋楼的管理员要清理储藏室。 以前(SWE-Pruner)的做法是请一个外部鉴定师走进储藏室,给每个箱子贴”保留”或”扔掉”的标签。 鉴定师不认识住户,也不知道住户在做什么。 SWE-Pruner Pro 说:别请鉴定师了。 直接观察住户走过每个箱子时的表情——隐状态就是表情,它精确地告诉你住户在意哪些箱子。 长度感知嵌入就像管理员注意到”这是个小壁柜”还是”这是个大仓库”——决策策略会随存储量变化。 分类头就是管理员读取住户的表情,然后在每个箱子上盖章”保留”或”扔掉”。
关键概念
-
内部表示作为隐式相关性信号:Transformer模型读取文本时,隐层不是均匀”处理”每个token的——注意力模式和残差激活因token而异,反映了每部分对当前任务的重要程度。 本文的洞见是:你不需要从头构建相关性检测器,可以直接读取智能体自身的”肢体语言”。 具体例子:如果智能体正在修复
utils.py中的bug,它读取utils.py各行时的隐状态,与读取README.md时的隐状态会有本质不同——一个简单的线性探针就能捕捉到这种差异。 -
长度感知嵌入:一个小型学习向量,用来根据当前工具输出的长度调节裁剪头。 直觉是:如果工具输出50行,你可能保留30行;如果有5000行,你可能只保留200行。 阈值应该是自适应的。 作者通过将输出长度分桶、每桶学习一个嵌入向量、拼接到每行隐状态向量上来实现这一点。
-
上下文内裁剪 vs. 预处理裁剪:SWE-Pruner(前代)在工具输出进入智能体上下文之前用外部分类器裁剪。 SWE-Pruner Pro 在智能体内部裁剪——智能体先看到完整输出,然后裁剪头在智能体自己的表示上操作。 这是架构层面的不同:裁剪决策发生在智能体”读完”输出之后,而不是之前。
框架转变
之前(主流方法): 之后(本文方法):
工具输出 工具输出
| |
v v
独立分类器模型 智能体正常处理输出
(独立训练) |
| v
v 智能体自身隐状态
保留/裁剪标签 |
| v
v 小型学习头
裁剪后上下文 |
| v
v 保留/裁剪标签
智能体处理裁剪后输出 |
v
裁剪后上下文
(用于下一回合)
从”外包裁剪决策”到”智能体自己判断读了什么”, 核心转变是:做理解的模型和做裁剪的模型现在是同一个——消除了理解与选择之间的鸿沟。
专家评审
选题眼光: 这是一个真实且实用的缺口。 上下文管理是所有做SWE-Bench类系统的人都要面对的瓶颈。 “隐状态编码相关性”这个观察在事后看来并不意外(探针研究多年前就证明了这一点),但将其应用于智能体工具输出裁剪,是一个干净、有用的工作。 它处在高效推理与智能体设计的交叉点,这个方向正热。
方法成熟度: 巧劲而非蛮力——一个两层MLP头加一个查找表,就是全部。 这是优点。 有没有更简单的方案被忽略了? 也许直接按最近性或关键词截断工具输出就能获得60%的收益、零开销。 但论文确实展示了有意义的质量提升,不仅仅是节省,这把它拔到了启发式方法之上。
实验诚意: 基线合理——与前代SWE-Pruner和无裁剪基线对比,覆盖多个基准(SWE-Bench Verified、Oolong等)和两个骨干模型(Qwen2.5-Coder和MiMo-V2-Flash)。 MiMo-V2-Flash上SWE-Bench Verified解决率+3.8%很亮眼——裁剪方法能提升准确率很罕见,说明原始上下文确实在通过噪声伤害性能。 一个疑虑:论文只测试了有限的骨干模型。 这能泛化到无法访问隐状态的GPT-4级闭源模型吗? 大概率不能,除非API有变化,这限制了适用范围。
写作功力: 论文写得清晰,结构也好。 但相关工作部分偏薄——没有深入对接驱动此方法的更广泛的探针/可解释性文献。 消融实验可以更强:长度感知嵌入相比固定阈值到底贡献了多少? 这种细节是把论文从”不错”提升到”扎实”的关键。
判决: 弱接收——干净的思路,实用的结果,但核心洞见(智能体内部编码相关性)是演进式的而非革命性的,实验广度也有提升空间。
要点总结
三件可以”偷走”的东西:
-
先探针,再建模:在为任何筛选/过滤任务训练独立模型之前,先检查主模型的隐状态是否已经编码了你需要的信号。 一个快速的线性探针能省下数月的分类器工程。 这个思路可以迁移到RAG、摘要、多文档问答——任何需要过滤上下文的场景。
-
长度感知嵌入便宜又好用:如果你的下游决策依赖于输入规模,加一个分桶嵌入。 这是一个10行代码的改动,就能带来自适应行为,无需复杂架构。
-
裁剪能提升质量,不只省成本:MiMo-V2-Flash的结果表明,去除噪声上下文**有助于*智能体更好地推理。 这是激进裁剪的有力论据——你不只是在省token,你在减少干扰。 如果你在构建编码智能体,试试更短的上下文是否真的比较长的更好。