一句话:用运行时轨迹与多智能体协作定位根因,并借助历史经验学习与回滚机制高效修复 LLM 生成的代码。
大语言模型生成的代码常含隐蔽而关键的缺陷,而现有自动修复方法多依赖通过/失败的粗粒度信号,难以洞察程序行为、精确定位错误,且无法从失败尝试中学习,导致修复循环重复低效。本文提出 TraceCoder,一个模拟人类专家“观察—分析—修复”流程的协作式多智能体框架:首先对代码插桩诊断探针,捕获细粒度运行时轨迹;随后对轨迹进行因果分析以定位失败根因;并引入历史经验学习机制(HLLM),从既往失败修复中提炼经验以指导后续策略、避免重蹈覆辙;同时用回滚机制保证每次修复迭代都是严格向正确解的改进,从而稳定收敛。多个基准实验显示,TraceCoder 相对先进基线在 Pass@1 上最高取得 34.43% 的相对提升;消融实验验证了各组件的作用,仅迭代修复过程即带来 65.61% 的相对精度增益,并在精度与成本效率上显著优于主流迭代式方法。
Large Language Models (LLMs) often generate code with subtle but critical bugs, especially for complex tasks. Existing automated repair methods typically rely on superficial pass/fail signals, offering limited visibility into program behavior and hindering precise error localization. In addition, without a way to learn from prior failures, repair processes often fall into repetitive and inefficient cycles. To overcome these challenges, we present TraceCoder, a collaborative multi-agent framework that emulates the observe-analyze-repair process of human experts. The framework first instruments the code with diagnostic probes to capture fine-grained runtime traces, enabling deep insight into its internal execution. It then conducts causal analysis on these traces to accurately identify the root cause of the failure. This process is further enhanced by a novel Historical Lesson Learning Mechanism (HLLM), which distills insights from prior failed repair attempts to inform subsequent correction strategies and prevent recurrence of similar mistakes. To ensure stable convergence, a Rollback Mechanism enforces that each repair iteration constitutes a strict improvement toward the correct solution. Comprehensive experiments across multiple benchmarks show that TraceCoder achieves up to a 34.43% relative improvement in Pass@1 accuracy over existing advanced baselines. Ablation studies verify the significance of each system component, with the iterative repair process alone contributing a 65.61% relative gain in accuracy. Furthermore, TraceCoder significantly outperforms leading iterative methods in terms of both accuracy and cost-efficiency.
@inproceedings{abs-2602-06875,
title = {TraceCoder: A Trace-Driven Multi-Agent Framework for Automated Debugging of LLM-Generated Code},
author = {Jiangping Huang and Wenguang Ye and Weisong Sun and Jian Zhang and Mingyue Zhang and Yang Liu},
booktitle = {ICSE},
year = {2026},
doi = {10.1145/3744916.3773187}
}