让代码生成模型自动反思并修正潜在安全漏洞
Reflection-Driven Control for Trustworthy Code Agents
- 在生成过程中引入持续自省循环,实时评估决策路径
- 检测风险后调用修复示例与安全规范,显著提升代码安全性
- 适合需要高可靠性与可审计性的编程自动化场景
当前大型语言模型代理虽能力强大,但仍缺乏可靠的安全控制,易产生不可控甚至有害的输出。为此,我们提出反射驱动控制(Reflection-Driven Control),一种可标准化、可插拔的控制模块,能无缝集成于通用代理架构中。该方法将“自我反思”从事后修补升级为代理推理过程中的显式步骤:在生成过程中,代理持续运行内部反思循环,监控并评估自身决策路径。当检测到潜在风险时,系统从动态演化的反思记忆中检索相关修复示例与安全编码指南,并将这些基于证据的约束直接注入后续推理步骤。我们在安全代码生成场景下实现了该控制模块,并在八类安全关键型编程任务中系统评估。实验结果表明,反射驱动控制显著提升了生成代码的安全性与策略合规性,同时基本保持功能正确性,且运行时与令牌开销极小。综合来看,该方法为可信AI代码代理提供了可行路径:实现自主、内置安全、可审计的设计。
原文摘要 · Abstract (English)
Contemporary large language model (LLM) agents are remarkably capable, but they still lack reliable safety controls and can produce unconstrained, unpredictable, and even actively harmful outputs. To address this, we introduce Reflection-Driven Control, a standardized and pluggable control module that can be seamlessly integrated into general agent architectures. Reflection-Driven Control elevates "self-reflection" from a post hoc patch into an explicit step in the agent's own reasoning process: during generation, the agent continuously runs an internal reflection loop that monitors and evaluates its own decision path. When potential risks are detected, the system retrieves relevant repair examples and secure coding guidelines from an evolving reflective memory, injecting these evidence-based constraints directly into subsequent reasoning steps. We instantiate Reflection-Driven Control in the setting of secure code generation and systematically evaluate it across eight classes of security-critical programming tasks. Empirical results show that Reflection-Driven Control substantially improves the security and policy compliance of generated code while largely preserving functional correctness, with minimal runtime and token overhead. Taken together, these findings indicate that Reflection-Driven Control is a practical path toward trustworthy AI coding agents: it enables designs that are simultaneously autonomous, safer by construction, and auditable.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。