Code generation models based on large language models (LLMs) have gained wide adoption, but challenges remain in ensuring safety, accuracy, and controllability, especially for complex tasks. Existing methods often lack dynamic integration of external tools, transparent reasoning, and user control over safety. To address these issues, we propose a controllable code generation framework utilizing the ReAct paradigm for multi-agent task execution. This framework is a multi-agent system designed to enable efficient, precise, and interpretable code generation through dynamic interactions between LLMs and external resources. The framework adopts a collaborative architecture comprising four specialized agents: a Planner for task decomposition, a Searcher that leverages the ReAct framework for reasoning and tool integration, a CodeGen agent for accurate code generation, and an Extractor for structured data retrieval. The ReAct-based Searcher alternates between generating reasoning traces and executing actions, facilitating seamless integration of internal knowledge with external tools (such as search engines) to enhance accuracy and user control. Experimental results show the framework's effectiveness across multiple languages, achieving a 94.8% security rate on the SVEN dataset with CodeQL, outperforming existing approaches. Its transparent reasoning process fosters user trust and improves controllability.
翻译:基于大语言模型(LLM)的代码生成模型已得到广泛应用,但在确保安全性、准确性和可控性方面仍面临挑战,尤其是在处理复杂任务时。现有方法通常缺乏外部工具的动态集成、透明的推理过程以及用户对安全性的控制。为解决这些问题,我们提出了一种利用ReAct范式进行多智能体任务执行的可控代码生成框架。该框架是一个多智能体系统,旨在通过LLM与外部资源之间的动态交互,实现高效、精确且可解释的代码生成。框架采用协作式架构,包含四个专用智能体:用于任务分解的规划器(Planner)、利用ReAct框架进行推理和工具集成的搜索器(Searcher)、用于精确代码生成的代码生成器(CodeGen)以及用于结构化数据提取的提取器(Extractor)。基于ReAct的搜索器交替生成推理轨迹和执行操作,促进内部知识与外部工具(如搜索引擎)的无缝集成,从而提升准确性和用户控制力。实验结果表明,该框架在多种编程语言上均表现有效,在SVEN数据集上使用CodeQL实现了94.8%的安全率,优于现有方法。其透明的推理过程增强了用户信任并提升了可控性。