English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

SWE-Pruner Pro: The Code Agent LLM Already Knows What to Prune

Forum topic · ✨步子哥 · 2026-07-21

Summary

Researchers from Shanghai Jiao Tong University and Shanghai AI Laboratory show that coding agents possess an internal signal for context pruning, eliminating the need for external scoring models. Their experiments on Qwen3-Coder-Next reveal that frozen hidden states can already distinguish task-relevant code lines from noise (AUC 0.83 via logistic regression probing). Building on this, SWE-Pruner Pro trains a lightweight pruning head on the agent's own representations, augmented with a length-aware embedding, while keeping the backbone frozen. Across two open-source backbones and four multi-turn benchmarks, the method saves up to 39% of prompt/completion tokens without degrading quality—and even improves SWE-Bench Verified resolution by +3.8% on MiMo-V2-Flash. The work echoes BERT-era probing studies and mechanistic interpretability: models encode more task-relevant knowledge internally than they explicitly express. Limitations include reliance on Claude Sonnet 4.6 line-level annotations, validation on only two open-source backbones, and untested transfer beyond code scenarios. Paper: https://arxiv.org/abs/2607.18213; code: https://github.com/Ayanami1314/swe-pruner-pro

SWE-Pruner Pro: The Code Agent LLM Already Knows What to Prune

Imagine you are debugging a tricky bug. Your AI coding assistant runs a grep and floods the screen with 500 lines of results. You glance over them—most is noise, and only the block around line 47 is what you actually need.

You skip the other 499 lines.

The question is: can the AI assistant make that judgment itself?

A team from Shanghai Jiao Tong University and the Shanghai AI Laboratory gives a surprising answer in the SWE-Pruner Pro paper: yes—and the model already knew.

Paper: https://arxiv.org/abs/2607.18213 Code: https://github.com/Ayanami1314/swe-pruner-pro

---

1. Context explosion: the hidden tax on coding agents

First, the problem. When a coding agent works in a repository, it repeatedly calls tools—cat to view files, grep to search keywords, ls to list directories, python to run tests. Each interaction produces large tool outputs that accumulate in the context window.

Measurements show that the vast majority of the token budget in a task trajectory is spent on tool outputs, much of it duplicated content that is never referenced again. This redundancy not only inflates costs but triggers a repeatedly verified phenomenon: long-context degradation. Models get "lost" in very long contexts, forgetting what to attend to; accuracy drops as context length grows.

So pruning long contexts has become a necessity for coding agents.

2. Two prior approaches

Previous methods fall into two camps:

Camp one: generic compression. Score tokens with fixed metrics like perplexity or syntactic structure, then trim by score. The problem: it doesn't know what the agent currently cares about—you're looking for a function definition, but it's busy preserving comment blocks.

Camp two: task-aware pruning. Exemplified by SWE-Pruner, an extra scoring model decides what to keep based on the "goal-hint" the agent writes each turn. Better results, but at a cost: an additional external model, and the agent must write a goal-hint every single turn—slow and awkward.

3. Key finding: the answer was already inside the model

The team ran a simple but elegant experiment. They froze Qwen3-Coder-Next, mean-pooled the last-layer hidden states for each line of tool output, and used logistic regression to test one question: can the model's internal representations distinguish lines that should be kept from lines that should be pruned?

Answer: yes, with an AUC of 0.83.

What does this mean? When the agent reads a grep output, its hidden states already encode "this line matters / this line doesn't" signals. While reading code, the model internally "knows" which lines are relevant to the current task—that knowledge just never gets explicitly extracted.

It's like your brain automatically highlighting key paragraphs as you read a paper—you don't need a separate "reading comprehension assistant" to tell you what matters. Neither does the model.

4. SWE-Pruner Pro: letting the model prune itself

Based on this finding, the team proposed SWE-Pruner Pro. Core design:

1. No external scoring model. The pruning signal comes directly from the agent's own internal representations. 2. A small pruning head. It reads the agent's hidden states, plus a "length-aware embedding" (encoding the number of lines in the tool output), and outputs a keep/prune label for each line. 3. Frozen backbone, train only the head. The agent itself is untouched; only the small head is trained, so inference overhead is minimal.

The pipeline is like attaching a probe to the agent's "reading process"—reading what it's thinking, then helping it strike out the irrelevant parts.

5. Results: fewer tokens, higher scores

Across two open-source backbones (Qwen3-Coder-Next and MiMo-V2-Flash) and four multi-turn benchmarks:

  • Token savings: up to 39% of prompt + completion tokens. On Qwen3-Coder-Next, three benchmarks saved 34.7%, 39.4%, and 13.9% respectively.
  • No quality loss: on SWE-QA/Pro, other pruning methods (SWE-Pruner, Self-Prune) drop judge scores by 0.14–0.65, while SWE-Pruner Pro preserves quality (+0.02, +0.24, -1.4pp).
  • Even gains: on MiMo-V2-Flash, SWE-Pruner Pro raises SWE-Bench Verified resolution by +3.8% and long-context Oolong accuracy by +2.2 points.
  • Pruning didn't hurt task quality—it actually improved it. This directly validates the long-context degradation hypothesis: redundant information really does hold models back, and cutting it makes them more focused.

    6. Why this matters

    1. "The model already knows" is a recurring pattern.

    This evokes BERT-era probing experiments: train a classifier to probe hidden states, and you find the model already encodes part-of-speech, syntax trees, semantic roles—none explicitly trained, all byproducts of pretraining. SWE-Pruner Pro brings this idea to the coding agent setting: while reading tool outputs, internal representations already contain a "relevance" signal.

    2. A paradigm shift from "external supervision" to "internal reading."

    The earlier SWE-Pruner needed an external model to say "is this line important?" SWE-Pruner Pro says: no need—the model knows; we just have to read the signal out. This is in the same spirit as mechanistic interpretability—rather than imposing explanations from outside, extract representations already present inside.

    3. Engineering simplicity.

    Frozen backbone + a small head means:

  • No need to retrain the agent
  • Controllable inference overhead
  • Plug-and-play across different models
  • 7. Limitations and an honest assessment

    The paper candidly notes its limitations:

  • Training data relies on Claude Sonnet 4.6 for line-level annotation; annotation quality is itself a bottleneck
  • Validated on only two open-source backbones; whether closed-source models (GPT, Claude) replicate the effect is unknown
  • The "the model knows what to prune" conclusion currently holds only in code scenarios—whether it transfers to other domains (e.g., dialogue, reasoning) is an open question

8. The bigger picture

What SWE-Pruner Pro does, at its core, is install a "metacognitive" interface for the agent—reading its own internal state to make decisions. It resembles the human switch between skimming and close reading: as your eyes sweep a page, your brain has already unconsciously flagged important passages, and you consciously return to read them closely.

Future agents may have more such "internal signal reading" modules: reading out "am I confused?", "am I repeating myself?", "am I close to the answer?"—all signals already present in hidden states but unused.

The model knows more than it says. SWE-Pruner Pro just narrows that gap a little.

---

Paper: SWE-Pruner Pro: The Coder LLM Already Knows What to Prune Authors: Yuhang Wang, Yuling Shi, Shaoqiu Zhang, et al. (Shanghai Jiao Tong University) arXiv: https://arxiv.org/abs/2607.18213 Code: https://github.com/Ayanami1314/swe-pruner-pro

Tags

#llm-agents#context-pruning#probing#hidden-states#swe-bench#long-context#mechanistic-interpretability#paper-review

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/178446985