Architecting Resilient LLM Agents: A Guide to Secure Plan-then-Execute Implementations

📄 arXiv: 2509.08646v1 📥 PDF

作者: Ron F. Del Rosario, Klaudia Krawiecka, Christian Schroeder de Witt

分类: cs.CR, cs.AI, eess.SY

发布日期: 2025-09-10


💡 一句话要点

构建弹性LLM Agent:安全Plan-then-Execute实现指南

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: LLM Agent Plan-then-Execute 安全性 提示注入攻击 LangChain CrewAI AutoGen

📋 核心要点

  1. 现有LLM Agent在复杂任务自动化中面临安全风险,尤其容易受到间接提示注入攻击,影响系统稳定性和可靠性。
  2. 论文提出Plan-then-Execute (P-t-E) 架构模式,将战略规划与战术执行分离,增强Agent的可预测性和安全性。
  3. 通过LangChain、CrewAI和AutoGen等框架的实现蓝图,展示了P-t-E模式的有效性,并讨论了高级应用模式和人机协作。

📝 摘要(中文)

随着大型语言模型(LLM) Agent在自动化复杂、多步骤任务方面的能力日益增强,对鲁棒、安全和可预测的架构模式的需求也变得至关重要。本文提供了一个关于“Plan-then-Execute”(P-t-E)模式的综合指南,这是一种将战略规划与战术执行分离的Agent设计。我们探讨了P-t-E的基本原则,详细介绍了其核心组件——规划器和执行器,以及它在可预测性、成本效率和推理质量方面相对于ReAct(Reason + Act)等反应式模式的架构优势。重点关注这种设计的安全影响,特别是通过建立控制流完整性来抵御间接提示注入攻击的固有弹性。我们认为,虽然P-t-E提供了一个强大的基础,但深度防御策略是必要的,并且我们详细介绍了必要的补充控制,例如最小权限原则、任务范围的工具访问和沙盒代码执行。为了使这些原则具有可操作性,本指南为三个领先的Agent框架提供了详细的实现蓝图和工作代码参考:LangChain(通过LangGraph)、CrewAI和AutoGen。分析了每个框架实现P-t-E模式的方法,突出了LangGraph用于重新规划的状态图、CrewAI用于安全性的声明式工具范围以及AutoGen的内置Docker沙盒等独特功能。最后,我们讨论了高级模式,包括动态重新规划循环、使用有向无环图(DAG)的并行执行以及人机环路(HITL)验证的关键作用,为旨在构建生产级、弹性且值得信赖的LLM Agent的架构师、开发人员和安全工程师提供完整的战略蓝图。

🔬 方法详解

问题定义:LLM Agent在自动化复杂任务时,容易受到恶意用户通过间接提示注入发起的攻击。这些攻击可能导致Agent执行非预期操作,甚至泄露敏感信息。现有的反应式Agent架构(如ReAct)缺乏对控制流的严格管理,使得攻击者更容易操纵Agent的行为。

核心思路:论文的核心思路是采用Plan-then-Execute (P-t-E) 架构,将任务分解为两个阶段:规划阶段和执行阶段。规划阶段负责生成任务执行的详细计划,而执行阶段则严格按照计划执行。这种分离降低了Agent在执行过程中受到外部干扰的风险,提高了系统的可预测性和安全性。

技术框架:P-t-E架构包含两个主要模块:Planner(规划器)和 Executor(执行器)。Planner负责接收用户指令,生成详细的任务执行计划。该计划通常包括一系列步骤,每个步骤对应一个或多个工具或API调用。Executor负责按照Planner生成的计划,依次执行每个步骤。为了进一步提高安全性,可以采用最小权限原则,限制Executor对工具和API的访问权限。此外,还可以使用沙盒环境来隔离代码执行,防止恶意代码对系统造成损害。

关键创新:P-t-E架构的关键创新在于将规划和执行分离,从而实现了控制流的完整性。与反应式Agent相比,P-t-E架构能够更好地抵御间接提示注入攻击,因为Agent的行为受到预先生成的计划的约束。此外,论文还提出了深度防御策略,包括最小权限原则、任务范围的工具访问和沙盒代码执行,进一步增强了系统的安全性。

关键设计:论文提供了LangChain (通过LangGraph)、CrewAI和AutoGen三个框架的P-t-E实现蓝图。LangGraph使用状态图来实现重新规划,CrewAI使用声明式工具范围来增强安全性,AutoGen则内置了Docker沙盒。这些实现蓝图为开发者提供了构建安全LLM Agent的实践指导。

🖼️ 关键图片

fig_0
fig_1

📊 实验亮点

论文重点展示了P-t-E架构在抵御间接提示注入攻击方面的优势,并提供了LangChain、CrewAI和AutoGen三个主流框架的实现案例。通过这些案例,开发者可以快速上手并构建安全的LLM Agent。此外,论文还讨论了动态重新规划、并行执行和人机协作等高级应用模式,为未来的研究方向提供了参考。

🎯 应用场景

该研究成果可广泛应用于需要安全可靠的LLM Agent的场景,例如金融风控、智能客服、自动化运维等。通过采用P-t-E架构和深度防御策略,可以有效降低Agent受到攻击的风险,提高系统的稳定性和可信度,从而促进LLM Agent在实际业务中的应用。

📄 摘要(原文)

As Large Language Model (LLM) agents become increasingly capable of automating complex, multi-step tasks, the need for robust, secure, and predictable architectural patterns is paramount. This paper provides a comprehensive guide to the ``Plan-then-Execute'' (P-t-E) pattern, an agentic design that separates strategic planning from tactical execution. We explore the foundational principles of P-t-E, detailing its core components - the Planner and the Executor - and its architectural advantages in predictability, cost-efficiency, and reasoning quality over reactive patterns like ReAct (Reason + Act). A central focus is placed on the security implications of this design, particularly its inherent resilience to indirect prompt injection attacks by establishing control-flow integrity. We argue that while P-t-E provides a strong foundation, a defense-in-depth strategy is necessary, and we detail essential complementary controls such as the Principle of Least Privilege, task-scoped tool access, and sandboxed code execution. To make these principles actionable, this guide provides detailed implementation blueprints and working code references for three leading agentic frameworks: LangChain (via LangGraph), CrewAI, and AutoGen. Each framework's approach to implementing the P-t-E pattern is analyzed, highlighting unique features like LangGraph's stateful graphs for re-planning, CrewAI's declarative tool scoping for security, and AutoGen's built-in Docker sandboxing. Finally, we discuss advanced patterns, including dynamic re-planning loops, parallel execution with Directed Acyclic Graphs (DAGs), and the critical role of Human-in-the-Loop (HITL) verification, to offer a complete strategic blueprint for architects, developers, and security engineers aiming to build production-grade, resilient, and trustworthy LLM agents.