5K

Plan-Then-Execute Pattern

Has the LLM fix the full sequence of tool calls before it reads untrusted data, then runs that sequence so tool outputs change only parameters

established Updated 2026-10-13 By Nikola Balic (@nibzard) Based on Luca Beurer-Kellner et al. (2025), He et al. (2025)
View .md Edit on GitHub
Add to Pack
or

Saved locally in this browser for now.

Cite This Pattern
APA
Nikola Balic (@nibzard) (2026). Plan-Then-Execute Pattern. In *Awesome Agentic Patterns*. Retrieved October 14, 2026, from https://agentic-patterns.com/patterns/plan-then-execute-pattern
BibTeX
@misc{agentic_patterns_plan-then-execute-pattern,
  title = {Plan-Then-Execute Pattern},
  author = {Nikola Balic (@nibzard)},
  year = {2026},
  howpublished = {\url{https://agentic-patterns.com/patterns/plan-then-execute-pattern}},
  note = {Awesome Agentic Patterns}
}

Use when

  • Tool outputs contain untrusted content that can carry prompt injections
  • The set of actions is known up front but parameters vary
  • Complex tasks benefit from a reviewed plan before execution

Avoid when

  • The next action depends on what earlier tool results reveal
  • Poisoned output content, such as a bad email body, is the main risk
  • Simple task that a capable model can one-shot

Problem

When planning and execution are interleaved in one loop, untrusted tool outputs can influence which action is selected next. That makes the control flow itself attackable: a malicious intermediate result can redirect the agent into unsafe tools or unauthorized operations.

Solution

Split reasoning into two phases:

  1. Plan phase – LLM generates a fixed sequence of tool calls before it sees any untrusted data.
  2. Execution phase – Controller runs that exact sequence. Tool outputs may shape parameters, but cannot change which tools run.

This separates strategic decisions from data-dependent execution. The planner commits to a bounded action graph up front, and the executor enforces that graph deterministically, which preserves flexibility on arguments while protecting control-flow integrity.

Benefits: Fixing the action sequence up front keeps untrusted tool output out of control-flow decisions. He et al. (2025) study plan-then-execute daily-assistant agents empirically (N = 248) across tasks with different risk levels.

plan = LLM.make_plan(prompt)      # frozen list of calls
for call in plan:
    result = tools.run(call)
    stash(result)                 # outputs isolated from planner

How to use it

Great for email-and-calendar bots, SQL assistants, code-review helpers—any task where the action set is known but parameters vary.

Claude Code Plan Mode

Claude Code implements this pattern through "plan mode" which shifts the agent into planning-only mode:

  1. User shifts to plan mode: Explicitly request planning (e.g., shift+tab in Claude Code CLI)
  2. Agent generates detailed plan: Creates step-by-step approach without executing
  3. Human reviews and approves: Can modify plan before execution
  4. Execution phase: Agent follows the approved plan

Effectiveness:

  • Can 2-3x success rates for complex tasks by aligning on approach first
  • Prevents wasted work from wrong assumptions
  • Allows human expertise to guide agent execution

Dynamic boundary:

The threshold of what requires planning changes with each model generation:

"The boundary changes with every model in a surprising way. Newer models are more intelligent, so the boundary of what you need plan mode for got pushed out a little bit. Before you used to need to plan, now you don't." —Boris Cherny (Anthropic)

This means simpler tasks that once required planning can now be one-shot with more capable models (e.g., Sonnet 4.5 vs. Opus 4.1).

LangGraph Plan-and-Execute

The archived langchain.experimental.plan_and_execute package has been superseded by LangGraph, which implements this pattern with separate planner and executor nodes over a shared state graph. See the LangGraph plan-and-execute tutorial.

Trade-offs

  • Pros: Strong control-flow integrity; moderate flexibility.
  • Cons: Content of outputs can still be poisoned (e.g., bad email body).

References