arXiv:2608.25457cs.CRcs.AI2026-08

多智能体协作生成更安全的代码,提升功能与安全双重指标。

MACGen: Toward Functionally Correct and Secure Code Generation via Multi-Agent Collaboration

论文配图:MACGen: Toward Functionally Correct and Secure Code Generation via Multi-Agent Collaboration
图 1 · 摘自论文原文
  • 分角色协作:规划、安全分析、编码、评审各司其职,减少上下文干扰。
  • 在CWEval和BaxBench上,功能与安全得分比直接提示提升19.61和10.57个百分点。
  • 适合关注代码安全性的开发者及自动化测试团队使用。

尽管大语言模型具备强大的代码生成能力,但其输出常包含安全漏洞。安全代码生成本质是兼顾功能正确性与安全性的多目标问题。现有方法通过注入外部安全知识或采用代理反馈与迭代优化来应对,但指南检索常导致通用建议难以转化为具体实现,共享对话式多代理反馈则易模糊角色边界并引发上下文膨胀。本文提出MACGen框架,整合规划、安全分析、代码生成与优化,协同提升安全与功能。规划器制定满足功能需求的步骤计划;安全顾问识别潜在的CWE,并生成任务相关的安全准则;编码器基于这些成果生成代码;评审者提供视角分离的反馈。各代理仅接收上游结构化成果,避免共享完整对话历史,强化角色专一性并控制上下文增长。在CWEval与BaxBench基准上,MACGen相比直接提示平均提升功能与安全得分19.61和10.57个百分点。

原文摘要 · Abstract (English)

Despite their strong ability to generate code, large language models often fail to produce secure code, as their outputs frequently contain security vulnerabilities. Secure code generation is inherently challenging because it requires solving a multi-objective problem: functional correctness and security. Existing approaches address this challenge by injecting external security knowledge or by using agentic feedback and iterative refinement. However, guideline retrieval often leaves the generator to translate generic advice into task-specific secure implementations, while shared-dialogue multi-agent feedback can blur role boundaries and suffer from context bloat. We present MACGen, a multi-agent framework that integrates planning, security analysis, code synthesis and refinement to jointly optimize security and functionality. A planner constructs a step-by-step plan to satisfy functional requirements. A security advisor identifies likely CWEs and synthesizes task-specific guidelines, a coder then generates code grounded in these artifacts, and a reviewer issues perspective-separated feedback. Rather than sharing full dialogue histories, each agent receives only structured artifacts from upstream stages, enforcing role specialization and reducing uncontrolled context growth. On CWEval and BaxBench, MACGen improves F&S@1 over direct prompting by 19.61 and 10.57 percentage points (pp) on average, respectively.

代码生成多智能体安全编码LLM

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