ContextSniper: AntTrail's Token-Efficient Code Memory for Repository-Level Program Repair
作者: Chiwang Luk, Matin Mohammad Najafi, Zhifeng Jia, Wei Yang, Xiuchang Li, Jinwei Zhu, Yang Ren, Lei Chen, Gao Cong
分类: cs.AI
发布日期: 2026-07-02
🔗 代码/项目: GITHUB
💡 一句话要点
提出ContextSniper以解决代码修复中的上下文效率问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 代码修复 上下文管理 信息检索 软件工程 智能编程
📋 核心要点
- 现有方法在处理代码修复时,往往会消耗大量上下文预算,导致效率低下。
- ContextSniper通过实现精确证据选择功能,优化了代码和运行时证据的检索与过滤。
- 实验表明,ContextSniper在多个任务上减少了51.5%的令牌使用和36.4%的成本,效果显著。
📝 摘要(中文)
大型语言模型代理能够修复实际代码库中的问题,但在处理整个文件读取、广泛搜索和长终端输出时,往往会消耗大量上下文预算,其中有用证据与无关代码和日志混合。本文提出了ContextSniper,这是AntTrail的一个高效代码记忆层,专注于代码修复。ContextSniper实现了Sniper功能,通过精确证据选择来检索候选代码和运行时证据,并使用混合检索信号进行排名,过滤长输出并返回紧凑的证据包,同时保留可恢复的源上下文。实验结果表明,ContextSniper在多个任务上显著减少了总令牌使用和日志成本。
🔬 方法详解
问题定义:本文旨在解决大型语言模型在代码修复过程中上下文预算消耗过大的问题。现有方法在处理长文件和复杂输出时,常常混淆有用信息与无关内容,导致效率低下。
核心思路:ContextSniper的核心思路是通过精确证据选择来提高上下文的使用效率。它通过检索候选代码和运行时证据,并使用混合信号进行排名,从而确保返回的信息更为紧凑和相关。
技术框架:ContextSniper的整体架构包括几个主要模块:候选代码检索、运行时证据获取、混合信号排名、意图感知上下文门过滤和证据包返回。这些模块协同工作,以提高信息的相关性和精确性。
关键创新:ContextSniper的主要创新在于其Sniper功能,能够在广泛的上下文中精确选择和过滤信息。这一设计与现有方法的根本区别在于其高效的上下文管理和信息筛选能力。
关键设计:在设计上,ContextSniper采用了混合检索信号来优化候选代码的排名,并通过意图感知上下文门来过滤冗长的输出。此外,系统还保留了可恢复的源上下文,以便在需要时进行进一步分析。
🖼️ 关键图片
📊 实验亮点
实验结果显示,ContextSniper在OpenClaw上减少了51.5%的总令牌使用和36.4%的日志成本,而在Claude Code上则分别减少了38.9%和27.3%。虽然提交解决率略有下降,但整体性能提升显著,验证了其有效性。
🎯 应用场景
ContextSniper的研究成果在软件工程、自动化代码修复和智能编程助手等领域具有广泛的应用潜力。通过提高代码修复的效率和准确性,该技术可以显著降低开发者的工作负担,并提升软件开发的整体质量和速度。未来,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 at https://github.com/Calluking/ContextSniper