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.


翻译:大型语言模型(LLM)智能体在软件开发中展现出卓越能力,但其性能受限于冗长的交互上下文,这些上下文会带来高昂的API成本和延迟。尽管已有多种上下文压缩方法(如LongLLMLingua)应对这一挑战,但它们通常依赖固定指标(如PPL),忽略了代码理解的任务特定性。这导致其经常破坏代码的语法与逻辑结构,且无法保留关键实现细节。本文提出SWE-Pruner,一种专为代码智能体设计的自适应上下文剪枝框架。受人类程序员在开发调试过程中“选择性略读”源代码的启发,SWE-Pruner对长上下文执行任务感知的自适应剪枝。针对当前任务,智能体将明确目标(例如“关注错误处理”)制定为提示以指导剪枝方向。我们训练了一个轻量级神经略读器(0.6B参数),使其能根据目标动态从周边上下文中选择相关代码行。在四个基准测试和多个模型上的评估验证了SWE-Pruner在多场景下的有效性:在SWE-Bench Verified等智能体任务中实现23-54%的令牌缩减,在LongCodeQA等单轮任务中达到最高14.84倍的压缩率,且对性能影响极小。

0
下载
关闭预览

相关内容

【斯坦福博士论文】为大型语言模型构建交互学习管道
专知会员服务
19+阅读 · 2025年7月12日
OpenAI 32页《智能体》指南,如何构建首个智能体系统
专知会员服务
50+阅读 · 2025年4月18日
NLP中自动生产文摘(auto text summarization)
机器学习研究会
14+阅读 · 2017年10月10日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
17+阅读 · 2008年12月31日
VIP会员
相关基金
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
17+阅读 · 2008年12月31日
Top
微信扫码咨询专知VIP会员