arXiv:2604.27283cs.CLcs.AI2026-04被引 2

让大模型代码代理学会判断何时该用记忆,避免错误修复。

Learning When to Remember: Risk-Sensitive Contextual Bandits for Abstention-Aware Memory Retrieval in LLM-Based Coding Agents

论文配图:Learning When to Remember: Risk-Sensitive Contextual Bandits for Abstention-Aware Memory Retrieval in LLM-Based Coding Agents
图 1 · 摘自论文原文
  • 用风险感知的上下文老虎机决策是否使用记忆
  • 离线测试成功率62.5%,零误用率
  • 适合关注代码修复安全性的工程实践者

基于大语言模型(LLM)的代码代理依赖外部记忆复用过往调试经验、修复记录和仓库本地知识。然而,只有当前失败与历史案例真正兼容时,记忆才有效;仅表面相似的堆栈轨迹、终端错误、路径或配置症状可能导致危险的记忆注入。本文将记忆使用重构为一种选择性、风险敏感的控制问题,而非单纯的top-k检索。提出RSCB-MC:一种风险感知的上下文老虎机记忆控制器,决定代理应不使用记忆、注入最优修复、汇总多个候选、执行高精度或高召回检索、放弃决策或请求反馈。系统通过模式-变体-事件结构存储可复用的问题知识,并将检索证据转化为包含16个特征的固定上下文状态,涵盖相关性、不确定性、结构兼容性、反馈历史、误报风险、延迟和令牌成本。奖励设计对误报注入的惩罚远高于遗漏复用,使非注入与放弃成为首要的安全动作。在确定性烟雾规模人工缺陷测试中,RSCB-MC实现62.5%的最高非预言机离线回放成功率,且保持0.0%误报率。在200例限定场景热路径验证中,达到60.5%代理成功率,0.0%误报率,95分位决策延迟为331.466微秒。结果表明,对代码代理记忆而言,关键问题不仅是哪条记忆最相似,而是任何检索记忆是否足够安全以影响调试轨迹。

原文摘要 · Abstract (English)

Large language model (LLM)-based coding agents increasingly rely on external memory to reuse prior debugging experience, repair traces, and repository-local operational knowledge. However, retrieved memory is useful only when the current failure is genuinely compatible with a previous one; superficial similarity in stack traces, terminal errors, paths, or configuration symptoms can lead to unsafe memory injection. This paper reframes issue-memory use as a selective, risk-sensitive control problem rather than a pure top-k retrieval problem. We introduce RSCB-MC, a risk-sensitive contextual bandit memory controller that decides whether an agent should use no memory, inject the top resolution, summarize multiple candidates, perform high-precision or high-recall retrieval, abstain, or ask for feedback. The system stores reusable issue knowledge through a pattern-variant-episode schema and converts retrieval evidence into a fixed 16-feature contextual state capturing relevance, uncertainty, structural compatibility, feedback history, false-positive risk, latency, and token cost. Its reward design penalizes false-positive memory injection more strongly than missed reuse, making non-injection and abstention first-class safety actions. In deterministic smoke-scale artifacts, RSCB-MC obtains the strongest non-oracle offline replay success rate, 62.5%, while maintaining a 0.0% false-positive rate. In a bounded 200-case hot-path validation, it reaches 60.5% proxy success with 0.0% false positives and a 331.466 microseconds p95 decision latency. The results show that, for coding-agent memory, the key question is not only which memory is most similar, but whether any retrieved memory is safe enough to influence the debugging trajectory.

代码生成记忆控制风险感知LLM

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