arXiv:2411.04329cs.CL2024-11NAACL被引 41

用树状结构引导代码生成,让大模型更高效地规划、写代码并调试。

CodeTree: Agent-guided Tree Search for Code Generation with Large Language Models

  • 构建统一树结构,分阶段探索不同编码策略
  • 在HumanEval等7个基准上表现优异,最高达95.1分
  • 适合需要复杂逻辑推理的代码生成任务

预训练于海量代码和文本数据的大语言模型(LLMs)在代码生成任务中展现出卓越性能。结合执行反馈后,这些模型可作为智能体实现自主代码优化。然而,在搜索空间极高的复杂编程任务中,现有代理方法仍难以有效完成多阶段规划、生成与调试。为此,我们提出CodeTree框架,使LLM代理能高效探索代码生成各阶段的搜索空间。具体而言,采用统一树结构显式探索不同编码策略,生成相应解决方案,并逐步优化。每个阶段的关键决策(排序、终止、扩展)均由环境执行反馈与模型自生成反馈共同指导。我们在7个代码生成基准上进行了全面评估,结果表明CodeTree显著优于强基线。以GPT-4o为底座模型,人类评估(HumanEval)得分达到95.1,MBPP得分为98.7,CodeContests得分为43.0。在更具挑战性的SWEBench基准上,性能提升尤为显著。

原文摘要 · Abstract (English)

Pre-trained on massive amounts of code and text data, large language models (LLMs) have demonstrated remarkable achievements in performing code generation tasks. With additional execution-based feedback, these models can act as agents with capabilities to self-refine and improve generated code autonomously. However, on challenging coding tasks with extremely large search space, current agentic approaches still struggle with multi-stage planning, generating, and debugging. To address this problem, we propose CodeTree, a framework for LLM agents to efficiently explore the search space in different stages of the code generation process. Specifically, we adopted a unified tree structure to explicitly explore different coding strategies, generate corresponding coding solutions, and subsequently refine the solutions. In each stage, critical decision-making (ranking, termination, expanding) of the exploration process is guided by both the environmental execution-based feedback and LLM-agent-generated feedback. We comprehensively evaluated CodeTree on 7 code generation benchmarks and demonstrated the significant performance gains of CodeTree against strong baselines. Using GPT-4o as the base model, we consistently achieved top results of 95.1 on HumanEval, 98.7 on MBPP, and 43.0 on CodeContests. On the challenging SWEBench benchmark, our approach led to significant performance gains.

代码生成树搜索大模型智能体

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