SWE-Pruner:編程代理的自適應上下文剪枝技術
SWE-Pruner: Self-Adaptive Context Pruning for Coding Agents
January 23, 2026
作者: Yuhang Wang, Yuling Shi, Mo Yang, Rongrui Zhang, Shilin He, Heng Lian, Yuting Chen, Siyu Ye, Kai Cai, Xiaodong Gu
cs.AI
摘要
大型語言模型代理在軟體開發領域展現出卓越能力,但其性能常受冗長交互上下文制約,導致API成本與延遲居高不下。儘管已有如LongLLMLingua等多種上下文壓縮方案應對這一挑戰,這些方法通常依賴PPL等固定指標,忽略了程式碼理解的任務特定性,往往破壞語法邏輯結構並遺失關鍵實作細節。本文提出SWE-Pruner——專為編程代理設計的自適應上下文修剪框架。受程式設計師在開發除錯時「選擇性略讀」原始碼的啟發,SWE-Pruner能對長上下文執行任務感知的自適應修剪。代理根據當前任務制定明確目標(如「聚焦錯誤處理」)作為提示來引導修剪方向,並透過訓練輕量級神經略讀器(0.6B參數)實現根據目標動態篩選上下文相關程式碼行。在四項基準測試與多重模型驗證中,SWE-Pruner於各場景均展現顯著效能:在SWE-Bench Verified等代理任務實現23-54%的token削減,於LongCodeQA等單輪任務更達成14.84倍壓縮率,且對性能影響微乎其微。
English
LLM agents have demonstrated remarkable capabilities in software development, but their performance is hampered by long interaction contexts, which incur high API costs and latency. While various context compression approaches such as LongLLMLingua have emerged to tackle this challenge, they typically rely on fixed metrics such as PPL, ignoring the task-specific nature of code understanding. As a result, they frequently disrupt syntactic and logical structure and fail to retain critical implementation details. In this paper, we propose SWE-Pruner, a self-adaptive context pruning framework tailored for coding agents. Drawing inspiration from how human programmers "selectively skim" source code during development and debugging, SWE-Pruner performs task-aware adaptive pruning for long contexts. Given the current task, the agent formulates an explicit goal (e.g., "focus on error handling") as a hint to guide the pruning targets. A lightweight neural skimmer (0.6B parameters) is trained to dynamically select relevant lines from the surrounding context given the goal. Evaluations across four benchmarks and multiple models validate SWE-Pruner's effectiveness in various scenarios, achieving 23-54% token reduction on agent tasks like SWE-Bench Verified and up to 14.84x compression on single-turn tasks like LongCodeQA with minimal performance impact.