ContextSniper精准提取代码修复证据,大幅降低上下文消耗。
ContextSniper: AntTrail's Token-Efficient Code Memory for Repository-Level Program Repair

- 三层次索引+混合排序器,精准定位修复相关代码与日志。
- 在SWE-bench Lite上减少51.5%令牌使用,成本降36.4%。
- 适合追求高效低耗的大型代码修复代理系统使用。
大型语言模型代理能修复真实仓库问题,但常因读取整文件、广泛搜索和长终端输出而浪费大量上下文资源,导致有效信息被冗余代码和日志淹没。本文提出ContextSniper,作为AntTrail代码修复模块,实现仓库级程序修复中的精确证据选择,是AntTrail代理-记忆引擎的一部分。ContextSniper将代码与操作记忆索引为三个抽象层级,通过混合排名器检索候选,利用意图感知上下文门过滤长工具输出,并返回紧凑证据包,同时保持原始源码可按需恢复。在相同任务条件下对SWE-bench Lite进行50任务对比测试(基线 vs. ContextSniper),ContextSniper使OpenClaw总令牌使用减少51.5%,日志成本下降36.4%;使Claude Code分别减少38.9%和27.3%,且提交修复率基本不变。在另一次五任务对比中,ContextSniper优于现有内存与RAG集成方案,在令牌效率上表现更优。结果表明,ContextSniper可在不明显降低修复质量的前提下,显著减少仓库级修复代理的令牌与成本开销。本研究评估框架已开源:https://gitcode.com/lukchiwang/ContextSniper。
原文摘要 · Abstract (English)
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 code-repair module for precision evidence selection in repository-level program repair, part of AntTrail's broader agent-memory engine. AntTrail is available at https://gitcode.com/datagallery/AntTrail. ContextSniper indexes code and action memory as three abstract levels, retrieves candidates with a hybrid ranker, filters long tool output through an intention-aware context gate, and returns compact evidence packets while keeping full source recoverable on demand. In a matched 50-task-per-condition comparison on SWE-bench Lite (same tasks, baseline vs.\ ContextSniper), ContextSniper reduces total token use by 51.5% and logged cost by 36.4% for OpenClaw, and by 38.9% and 27.3% for Claude Code, with submitted-resolution rates essentially unchanged in both host-agent settings. In a separate five-task comparison, ContextSniper beats existing memory- and RAG-style integrations on token efficiency. These results suggest ContextSniper can substantially cut token and cost overhead for repository-level repair agents without a measurable loss in repair quality. The evaluation harness for this study is available at https://gitcode.com/lukchiwang/ContextSniper.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。