arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2610.30571cs.SE
收藏

编码智能体中过时的指令文件会覆盖代码:一个单句修复方案

Stale Instruction Files Override the Code in Coding Agents: A One-Sentence Fix

College of Computing, Georgia Institute of Technology(佐治亚理工学院计算学院);Department of Computer Science, University of Colorado Boulder(科罗拉多大学博尔德分校计算机科学系)

Xiaonan Xu, Wenjing Wu

AI总结:

该研究发现编码智能体倾向遵循过时指令文件而非代码,通过在指令文件中添加赋予代码优先级的单句,可大幅提升智能体遵循代码的比例并提高测试通过率。

摘要:

目的:编码智能体遵循项目的指令文件(如this http URL或this http URL),即使该文件与现有代码不一致,且即使智能体注意到这种不一致。我们测量了这种行为,并测试用户自己的指令文件中的一个句子是否能让智能体转而遵循代码。方法:我们构建了40个Python项目,其中指令文件要求一种约定,而现有代码使用另一种约定,例如使用print而非logging。我们在320次运行中,让Claude Code和Codex CLI为每个项目添加一个功能,分别在用户级指令文件中包含赋予现有代码优先级的句子和不包含该句子的情况。结果:没有该句子时,90.1%的智能体选择遵循过时文件;Claude Code在80次运行中的79次指出了冲突,但仍遵循该文件;Codex CLI在80次运行中的20次重写现有代码以匹配该文件,其中17次导致项目自身的测试失败。该句子使遵循代码的选择比例从4.2%提升至91.4%,停止了重写行为,并使测试通过率从89.4%提升至100%。结论:我们将这种行为归因于智能体对两种信息源的接收方式:指令文件作为指令传递给模型,而代码作为工具输出传递,模型在训练中对后者的优先级更低。用户如今即可添加该句子,智能体和模型的开发者也可在其产品中内置相同规则。

英文摘要:

Purpose: Coding agents follow a project's instruction file, such as CLAUDE.md or AGENTS.md, even when it disagrees with the existing code and even when they notice the disagreement. We measure this behaviour and test whether one sentence in the user's own instruction file makes agents follow the code instead. Methods: We built 40 Python projects in which the instruction file asks for one convention while the existing code uses another, for example print instead of logging. Claude Code and Codex CLI added a feature to each project, with and without a sentence in the user-level instruction file that gives the existing code precedence, in 320 runs. Results: Without the sentence, 90.1% of the agents' choices followed the stale file. Claude Code pointed out the conflict in 79 of 80 runs and still followed the file. Codex CLI rewrote the existing code to match the file in 20 of 80 runs, and the project's own tests then failed in 17 of them. The sentence raised the share of choices that follow the code from 4.2% to 91.4%, stopped the rewrites and raised the test pass rate from 89.4% to 100%. Conclusion: We attribute the behaviour to how agents receive the two sources: the instruction file reaches the model as an instruction and the code as tool output, which models are trained to rank lower. Users can add the sentence today, and makers of agents and models can build the same rule into their products.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑