arXiv:2603.01896cs.SEcs.AI2026-03被引 7

让大模型不跑代码就能推理代码语义,准确率提升10%以上。

Agentic Code Reasoning

  • 用结构化提示构建前提、追踪路径、得出结论,防止跳步和瞎猜。
  • 在真实补丁验证中准确率达93%,接近执行无依赖强化学习所需水平。
  • 适合做代码审查、静态分析或强化学习奖励设计的工程师和研究者。

大型语言模型代理能否在不执行代码的情况下探索代码库并推理代码语义?我们研究这一能力,称为「代理式代码推理」,并提出半形式化推理:一种要求代理构建明确前提、追踪执行路径并推导正式结论的结构化提示方法。与非结构化思维链不同,半形式化推理如同一份证明书,确保代理无法跳过情形或做出无依据断言。我们在三个任务上评估:补丁等价性验证、故障定位和代码问答。结果显示,半形式化推理在所有任务上均显著提升准确率。在补丁等价性验证中,精选样本准确率从78%提升至88%,真实世界代理生成补丁达到93%,接近无需执行的强化学习奖励信号所需可靠性。在RubberDuckBench(Mohammad et al., 2026)代码问答任务中,准确率达87%。在Defects4J(Just et al., 2014)故障定位任务中,Top-5准确率相比标准推理提升5个百分点。结果表明,结构化代理推理可在无需执行的前提下实现有意义的语义代码分析,为强化学习训练流水线、代码审查和静态程序分析提供实用方案。

原文摘要 · Abstract (English)

Can LLM agents explore codebases and reason about code semantics without executing the code? We study this capability, which we call agentic code reasoning, and introduce semi-formal reasoning: a structured prompting methodology that requires agents to construct explicit premises, trace execution paths, and derive formal conclusions. Unlike unstructured chain-of-thought, semi-formal reasoning acts as a certificate: the agent cannot skip cases or make unsupported claims. We evaluate across three tasks (patch equivalence verification, fault localization, and code question answering) and show that semi-formal reasoning consistently improves accuracy on all of them. For patch equivalence, accuracy improves from 78% to 88% on curated examples and reaches 93% on real-world agent-generated patches, approaching the reliability needed for execution-free RL reward signals. For code question answering on RubberDuckBench Mohammad et al. (2026), semi-formal reasoning achieves 87% accuracy. For fault localization on Defects4J Just et al. (2014), semi-formal reasoning improves Top-5 accuracy by 5 percentage points over standard reasoning. These results demonstrate that structured agentic reasoning enables meaningful semantic code analysis without execution, opening practical applications in RL training pipelines, code review, and static program analysis.

代码推理LLM代理静态分析

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