CodeGrep:面向大模型编程智能体的强化学习检索代理
文章背景与核心概要
现代基于大语言模型(LLM)的编程智能体(如 OpenHands 和 Claude Code)在处理复杂任务时,往往面临严重的效率瓶颈。这些智能体在代码库探索阶段(如使用 grep、glob 和 view_file 等工具)消耗了大量的 Token 预算,导致在实际代码生成环节的资源受限。
CodeGrep 是一款 14B 参数的检索代理,旨在解决这一效率难题。该模型通过 GRPO(组相对策略优化)进行端到端训练,能够自主发起多轮并行工具调用以精准定位相关文件,并将结果传递给下游的编程智能体。研究表明,CodeGrep 在 SWE-Bench Verified 基准测试中,在保持甚至提升模型解决率的同时,显著降低了 19% 的 Token 消耗和 15% 的交互轮次。
核心贡献
- 强化学习驱动的检索: 该模型通过优化下游任务的实用性进行训练,其检索精度阈值达到 0.677,证明了检索过程能够有效降低整体执行成本。
- 聚焦效率的训练方法: 通过在优势层(Advantage Layer)而非奖励层(Reward Layer)应用效率信号,作者成功减少了 KL 散度漂移,并提升了下游性能。
- 数据与环境: 本研究利用了 67K 条通过 CATM 挖掘的开源智能体轨迹,并构建了一个专为多轮智能体强化学习设计的自定义 Git-worktree 环境。
- 开放科学: 作者承诺向社区开源该模型、训练流水线、强化学习环境及评估工具。
- RL-Driven Retrieval: The model is trained to optimize for downstream utility, crossing a precision threshold (0.677) where retrieval actively reduces total rollout costs.
- Efficiency-Focused Training: By applying efficiency signals at the advantage layer rather than the reward layer, the authors successfully reduced KL drift and improved downstream performance.
- Data & Environment: The study utilized 67K open-source agent trajectories (mined via CATM) and a custom Git-worktree environment specifically built for multi-turn agent reinforcement learning.
- Open Science: The authors have committed to releasing the model, training pipeline, RL environment, and evaluation harnesses to the community.
性能指标
| 指标 | 基准模型 (无检索) | CodeGrep |
|---|---|---|
| 解决率 (Resolve Rate) | 25.8% | 27.0% |
| Token 消耗 | 基准值 | 降低 19% |
| 交互轮次 | 基准值 | 降低 15% |
注:性能指标基于 500 个 SWE-Bench Verified 实例测量。
Metric Baseline (No Retrieval) CodeGrep Resolve Rate 25.8% 27.0% Token Usage Baseline 19% Reduction Round Count Baseline 15% Reduction Note: Performance is measured across 500 SWE-Bench Verified instances.