ContextSniper: AntTrail's Token-Efficient Code Memory for Repository-Level Program Repair

📄 arXiv: 2607.01916 📥 PDF

作者: Chiwang Luk, Matin Mohammad Najafi, Zhifeng Jia, Wei Yang, Xiuchang Li, Jinwei Zhu, Yang Ren, Lei Chen, Gao Cong

分类: cs.AI

发布日期: 2026-07-05


💡 一句话要点

提出ContextSniper以解决代码修复中的上下文效率问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 代码修复 上下文管理 语言模型 高效检索 软件工程

📋 核心要点

  1. 现有方法在处理代码修复时,往往会消耗过多的上下文预算,导致效率低下。
  2. ContextSniper通过精确的证据选择和意图感知的上下文过滤,提升了代码修复的效率和准确性。
  3. 实验结果显示,ContextSniper在OpenClaw和Claude Code上分别减少了51.5%和38.9%的总令牌使用,显著降低了成本。

📝 摘要(中文)

大型语言模型代理能够修复真实的代码库问题,但在处理整个文件读取、广泛搜索和长终端输出时,往往会消耗大量上下文预算,其中有用证据与无关代码和日志混合。本文提出了ContextSniper,这是AntTrail的一个高效代码记忆层,专注于代码修复。ContextSniper实现了Sniper特性,通过精确的证据选择来检索候选代码和运行时证据,利用混合检索信号进行排名,通过意图感知的上下文门过滤长输出,并返回紧凑的证据包,同时保留可恢复的源上下文。我们在SWE-bench Lite上评估了ContextSniper,结果显示其在多个任务中显著减少了总令牌使用和日志成本。

🔬 方法详解

问题定义:本文旨在解决大型语言模型在代码修复过程中对上下文预算的高消耗问题,现有方法在处理长输出和无关信息时效率低下。

核心思路:ContextSniper通过实现Sniper特性,专注于精确的证据选择,旨在提高代码修复的效率和准确性。该方法通过意图感知的上下文门过滤无关信息,确保仅返回相关证据。

技术框架:ContextSniper的整体架构包括候选代码和运行时证据的检索、混合检索信号的排名、意图感知的上下文门过滤和紧凑证据包的返回。各模块协同工作,以实现高效的上下文管理。

关键创新:ContextSniper的主要创新在于其高效的证据选择机制和意图感知的上下文过滤,与现有方法相比,显著提升了上下文的使用效率。

关键设计:在设计上,ContextSniper采用了混合检索信号来优化证据排名,并通过意图感知的上下文门来过滤长输出,确保返回的证据包紧凑且相关。

🖼️ 关键图片

fig_0
img_1
img_2

📊 实验亮点

实验结果表明,ContextSniper在OpenClaw上减少了51.5%的总令牌使用和36.4%的日志成本,而在Claude Code上则分别减少了38.9%和27.3%。尽管提交解决率略有下降,但整体性能提升显著,展示了其在实际应用中的潜力。

🎯 应用场景

ContextSniper的研究成果可广泛应用于软件开发和维护领域,尤其是在自动化代码修复和智能编程助手中。其高效的上下文管理能力将提升开发者的工作效率,减少调试和修复代码所需的时间和资源,未来可能对软件工程的自动化水平产生深远影响。

📄 摘要(原文)

Large language model agents can repair real repository issues, but they often spend large context budgets on whole-file reads, broad searches, and long terminal outputs where useful evidence is mixed with irrelevant code and logs. This paper presents ContextSniper, AntTrail's token-efficient code memory layer for repository-level program repair. As the coding specialization of AntTrail's broader agent memory engine, ContextSniper implements the Sniper feature for precision evidence selection: it retrieves candidate code and runtime evidence, ranks it with hybrid retrieval signals, filters long outputs through an intention-aware context gate, and returns compact evidence packets while preserving recoverable source context outside the prompt. We evaluate ContextSniper on SWE-bench Lite with OpenClaw and Claude Code, using 50 task runs per host-agent condition. ContextSniper reduces total token use by 51.5% and logged cost by 36.4% for OpenClaw, and reduces total token use by 38.9% and estimated cost by 27.3% for Claude Code. Submitted-resolution rates decrease slightly, from 26.0% to 24.0% for OpenClaw and from 32.0% to 30.0% for Claude Code. ContextSniper's pilot testing scripts are open-sourced atthis https URL