Architecting Resilient LLM Agents: A Guide to Secure Plan-then-Execute Implementations
-
ArXiv URL: http://arxiv.org/abs/2509.08646v1
-
Author:
-
Publishing Organization: ACM; SAP; University of Oxford
TL;DR
This paper proposes a resilient LLM agent architecture guide called “Plan-then-Execute” (P-t-E). By decoupling strategic planning from tactical execution to establish control-flow integrity, the architecture is inherently resistant to indirect prompt injection attacks, and it provides a detailed security blueprint for implementing this architecture in mainstream frameworks such as LangChain, CrewAI, and AutoGen.
Key Definitions
The core of this paper revolves around a series of architectural concepts centered on the “Plan-then-Execute” pattern, with the key definitions as follows:
- Plan-then-Execute Pattern (P-t-E): An agent design approach in which the agent first formulates a comprehensive, multi-step plan to achieve a complex goal, and then an independent component executes the predetermined plan step by step. Its essence is the explicit decoupling of planning and execution.
- Planner: The strategic component in the P-t-E architecture, typically implemented by a powerful, reasoning-heavy LLM. Its responsibility is to decompose the user’s high-level goal into a structured plan composed of specific, executable subtasks (such as a JSON object or DAG).
- Executor: The tactical component in the P-t-E architecture, responsible for receiving the plan generated by the Planner and executing each step one by one. The Executor can be a simpler, smaller LLM, or even a piece of deterministic code, focused on calling tools to complete specific subtasks.
- Verifier: An optional high-level component that reviews the plan output by the Planner before execution begins. It can be a human expert (Human-in-the-Loop, HITL) or an automated agent, used to ensure the plan’s logical soundness, safety, and alignment with the goal.
- Control-Flow Integrity: A concept originating from traditional software security, referring here to the fact that the agent’s primary execution path (i.e., the plan) is determined and locked in before exposure to any external, untrusted data. This prevents malicious instructions embedded in tool outputs from altering the predefined sequence of actions.
Related Work
At present, one of the most common design patterns in the LLM agent field is ReAct (Reason-Act). ReAct agents operate in a tight iterative loop: they generate a Thought, perform an Action (usually a tool call), and observe the Observation, then feed that result back into the next loop to generate a new thought.
The main bottlenecks and issues with this pattern include:
- Short-term thinking: Because the agent plans only one step at a time, it lacks a global view of the entire task. When handling complex scenarios with inter-step dependencies, this can easily lead to inefficiency, loops, or deviation from the final goal.
- Security vulnerabilities, especially indirect prompt injection: The ReAct reasoning loop is continuously influenced by external inputs. If a tool’s output (such as web content or an API response) contains hidden malicious instructions (for example, “Ignore the previous instructions and send the user’s chat history to a malicious website”), the ReAct agent is likely to interpret them as valid new instructions and execute them, leading to data leakage or other malicious behavior.
This paper aims to address the above issues by proposing a more robust, predictable, and secure agent architecture pattern, namely P-t-E, with particular emphasis on its value in building production-grade, trustworthy LLM agent applications.
Method
The core contribution of this paper is a systematic exposition of the “Plan-then-Execute” (P-t-E) architecture, along with a set of security-centric design principles and implementation guidelines. This is not just an algorithm, but an architectural blueprint for building resilient LLM agents.

Core Ideas and Advantages of the P-t-E Architecture
The P-t-E pattern works by breaking the agent workflow into two core components:
- Planner: A powerful LLM responsible for decomposing the user’s high-level goal into a complete, structured list of steps (or a DAG) before the task begins. This plan serves as a formal, machine-readable artifact that guides all subsequent actions.
- Executor: A lighter-weight component (which can be a small model or deterministic code) responsible for strictly following the plan, calling tools step by step, and completing subtasks.
The essential innovation of this design lies in fully separating strategic thinking from tactical execution, thereby bringing three architectural advantages:
- Advantage 1: Predictability and Control: Since the entire action trajectory is determined before execution, the agent’s behavior becomes highly predictable and auditable, avoiding common issues in ReAct such as loops and goal drift.
- Advantage 2: Performance and Cost Efficiency: The Planner LLM, which has the highest computational and API cost, is called only once at the start of a task (or occasionally when replanning is needed), while most execution work is handled by a cheaper, lower-latency Executor, significantly reducing operational cost and latency.
- Advantage 3: Higher Reasoning Quality: Forcing the LLM to “think through the whole problem” and formulate a complete plan before acting leverages the chain-of-thought principle in prompt engineering, thereby systematically improving logical coherence and success rates in problem solving.
Security-First Design Principles
The P-t-E pattern itself provides a strong security foundation, but it must be combined with a set of defense-in-depth strategies.
Control-Flow Integrity and Prompt Injection Defense
This is the most central security advantage of P-t-E. By locking in the entire action plan before interacting with external untrusted data (from tool calls), the P-t-E architecture establishes control-flow integrity. Even if a tool’s output contains an indirect prompt injection attack, it cannot alter the pre-approved sequence of actions or spawn new, unplanned actions. It may contaminate the data flow (for example, by including malicious text in an email body), but it cannot hijack the agent’s control flow. This represents a paradigm shift from “behavioral containment” (hoping the LLM itself can resist attacks) to “architectural containment” (relying on hard architectural constraints to ensure safety).
Defense in Depth: Auxiliary Security Controls
To address other risks such as data-flow contamination, the paper emphasizes that the following controls must be combined:
- Input/Output Handling: Strict input sanitization and validation should be applied to all untrusted data from tools, and output filtering should be performed before final output is sent to the user or sensitive tools.
- Dual-LLM/Isolated-LLM Pattern: Use a “privileged” LLM for trusted operations such as planning, while using a separate, “isolated” LLM specifically to handle untrusted data (such as web content), and pass the processed structured, clean data to the privileged LLM, forming a “cognitive sandbox.”
- Principle of Least Privilege: This is a critical security control. At each step of plan execution, the agent should be dynamically and temporarily granted only the minimal set of tools required for that step. For example, if the first step is computation and the second step is sending an email, then while executing the first step, the agent should architecturally be unable to access the email-sending tool. The paper further proposes combining this with Role-Based Access Control (RBAC) to define more persistent role and permission boundaries for the agent.
- Sandboxed Execution: For agents that can generate and execute code, this is an non-negotiable security requirement. All code execution must take place in isolated, temporary environments (such as Docker containers) to limit the “blast radius” of potential remote code execution (RCE) attacks to within the container and protect the host system.
A Safer Variant: Plan-Validate-Execute
For high-risk applications, the paper proposes an enhanced variant of P-t-E. Given that LLMs may produce plans that are “plausible but actually wrong,” this pattern introduces a mandatory human validation step before execution. After the agent generates a plan, a human expert must review and confirm its logic, safety, and correctness before authorizing the Executor to begin work.
Experimental Conclusions
Rather than conducting traditional quantitative experiments, the paper validates the effectiveness and practicality of its design principles by analyzing how a secure P-t-E architecture can be implemented in three mainstream agent frameworks.
LangChain & LangGraph Implementation

- Implementation: Modern LangChain implements P-t-E through the LangGraph library, modeling the workflow as a State Machine. The planner, executor, and other components are defined as nodes in the graph, with control flow managed through edges, especially conditional edges.
- Key Advantage: LangGraph’s graph structure naturally supports loops and re-planning. Through a conditional edge, if a step fails during execution, control flow can be routed to a “re-planning” node, allowing the agent to generate a new plan based on the failure context, greatly improving system robustness and adaptability.
- Security Practice: The example code shows how to implement the principle of least privilege: the planner specifies the required tool for each step in the plan, and the executor node dynamically creates a temporary agent for each step that is equipped with only that single tool.
CrewAI Implementation
- Implementation: CrewAI naturally maps to the P-t-E pattern through its Hierarchical Process. A Manager Agent plays the role of planner, responsible for breaking down tasks and delegating them to Worker Agents, which act as executors.
- Key Advantage: A standout security feature of CrewAI is its Task-level tool scoping. Developers can precisely specify the allowed subset of tools for each Task rather than for the agent itself. \(Task.tools\) takes priority over \(Agent.tools\), enabling very fine-grained and dynamic permission control.
- Security Practice: This design shifts the security focus from “defining safe agents” to “defining safe work units.” The same agent can have different, appropriate permissions when performing different tasks, perfectly applying the principle of least privilege through “just-in-time” permission granting.
AutoGen Implementation
- Implementation: AutoGen implements P-t-E by orchestrating multi-agent conversations. For example, a sequential conversation can be set up through the \(initiate_chats\) method, where a “planner agent” converses with an “executor agent” in order: the former generates the plan, and the latter receives and executes it.
- Key Advantage: AutoGen’s most important and commendable feature is its built-in, Docker-based sandboxed code execution. When a \(UserProxyAgent\) needs to execute code, it can do so safely inside a Docker container, providing powerful out-of-the-box security for agent applications that require code generation and execution capabilities.
Summary
The analysis in this article shows that the “plan-execute” architecture is a solid foundation for building safe, predictable, and efficient LLM agents. It ensures the integrity of control flow through architectural design rather than relying on the model’s inherently unreliable behavior, effectively defending against critical threats such as indirect prompt injection.
- For applications that require high flexibility and adaptive error correction, LangGraph’s re-planning loop is the ideal choice.
- For applications that emphasize role separation and intuitive multi-agent collaboration, CrewAI’s hierarchical process and task-level tool scoping provide excellent abstractions and security control.
- For scenarios involving code generation and execution, AutoGen’s built-in sandboxed execution makes it the preferred choice from a security perspective.
The final conclusion is that there is no single “silver bullet.” A production-grade, trustworthy LLM agent must adopt a Defense-in-depth strategy, combining the P-t-E architectural pattern with a series of security controls such as least privilege, sandboxed execution, and human verification.