arXiv:2601.16746cs.SEcs.CL2026-01被引 37

让编程大模型自动精简上下文,省算力还提效果

SWE-Pruner: Self-Adaptive Context Pruning for Coding Agents

  • 根据任务目标动态筛选代码行,像人一样有重点地阅读
  • 在SWE-Bench上减少23%-54%的令牌数,成功率还提升
  • 适合需要处理长代码的AI编程助手,尤其看重效率的场景

大语言模型代理在软件开发中表现卓越,但长上下文导致高API成本和延迟。现有压缩方法如LongLLMLingua依赖固定指标(如PPL),忽略代码理解的任务特性,常破坏语法与逻辑结构,丢失关键实现细节。本文提出SWE-Pruner,一种面向编程代理的自适应上下文剪枝框架。受人类程序员在开发与调试时“有选择性地快速浏览”代码的启发,SWE-Pruner基于当前任务形成明确目标(如“聚焦错误处理”)作为提示,指导剪枝方向。一个轻量级神经预览器(0.6B参数)被训练为根据目标动态选取上下文中的相关代码行。在四个基准测试和多个模型上的评估表明,SWE-Pruner在各类场景中均有效,于SWE-Bench Verified任务中实现23%-54%的令牌缩减,甚至提升成功率;在LongCodeQA单轮任务中可达14.84倍压缩,性能损失极小。

原文摘要 · Abstract (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 while even improving success rates, and up to 14.84x compression on single-turn tasks like LongCodeQA with minimal performance impact.

代码生成上下文压缩大模型优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。