What Is the Plan-and-Execute Pattern?
Quick Definition#
The plan-and-execute pattern is an AI agent architecture that separates task planning from task execution into two distinct phases. A planner LLM first generates a complete decomposition of the task into ordered steps. Executor agents then carry out each step independently, using their available tools. Unlike the ReAct pattern where reasoning and action are interleaved, plan-and-execute makes the full execution plan visible upfront — improving auditability and performance on long-horizon tasks.
Browse all AI agent terms in the AI Agent Glossary. For the interleaved alternative, see ReAct (Reasoning + Acting). For agents that delegate steps to specialists, see Subagent.
Why Plan-and-Execute Exists#
Interleaved reasoning-action patterns like ReAct work well for short tasks. For longer workflows, they face fundamental limitations:
- Context window drift: Over many steps, the model's attention drifts and it loses track of the original goal
- Auditability gap: In ReAct, it is hard to inspect what the agent plans to do before it does it — each step is decided reactively
- Inefficient replanning: When a step fails in ReAct, the agent has no explicit plan to revise — it just generates the next thought
- Parallelization difficulty: With no explicit plan, identifying which steps can run in parallel requires post-hoc analysis
The plan-and-execute pattern addresses these by making the plan a first-class artifact that can be inspected, approved, and modified before execution begins.
Pattern Architecture#
User Request
↓
[Planner LLM]
Generates: ["Step 1: Search for X",
"Step 2: Filter by Y",
"Step 3: Summarize findings",
"Step 4: Format output"]
↓
[Optional: Human or system reviews the plan]
↓
[Executor Agent] [Executor Agent] [Executor Agent]
Step 1: Search Step 2: Filter Step 3: Summarize
↓ ↓ ↓
[Replanner] ← Are results what the plan expected? ← Optional
↓
Final Answer
Implementing Plan-and-Execute#
Basic Implementation with LangGraph#
from langgraph.graph import StateGraph, END
from typing import TypedDict, List
import anthropic
client = anthropic.Anthropic()
class PlanExecuteState(TypedDict):
input: str # Original user request
plan: List[str] # Generated task steps
past_steps: List[dict] # Completed steps with results
current_step_idx: int # Which step is being executed
response: str # Final answer
def planner(state: PlanExecuteState) -> dict:
"""Generate a task plan from the user request."""
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=1000,
messages=[{
"role": "user",
"content": f"""Create a step-by-step plan to accomplish this task.
Return a JSON list of steps, each a clear action.
Task: {state['input']}
Format: {{"steps": ["step 1 description", "step 2 description", ...]}}"""
}]
)
import json
plan_data = json.loads(response.content[0].text)
return {"plan": plan_data["steps"], "current_step_idx": 0}
def executor(state: PlanExecuteState) -> dict:
"""Execute the current step in the plan."""
current_step = state["plan"][state["current_step_idx"]]
context = "\n".join(
f"Step {i+1} result: {s['result']}"
for i, s in enumerate(state["past_steps"])
)
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=1500,
messages=[{
"role": "user",
"content": f"""You are executing step {state['current_step_idx'] + 1} of a plan.
Previous results:
{context if context else "None yet"}
Current step to execute: {current_step}
Execute this step and return the result."""
}]
)
result = response.content[0].text
past_steps = state["past_steps"] + [{"step": current_step, "result": result}]
return {
"past_steps": past_steps,
"current_step_idx": state["current_step_idx"] + 1
}
def synthesizer(state: PlanExecuteState) -> dict:
"""Synthesize all step results into a final response."""
steps_summary = "\n".join(
f"Step {i+1}: {s['step']}\nResult: {s['result']}\n"
for i, s in enumerate(state["past_steps"])
)
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=2000,
messages=[{
"role": "user",
"content": f"""Synthesize these step results into a final answer.
Original request: {state['input']}
Steps completed:
{steps_summary}
Final answer:"""
}]
)
return {"response": response.content[0].text}
def should_continue(state: PlanExecuteState) -> str:
"""Route: continue execution or move to synthesis."""
if state["current_step_idx"] >= len(state["plan"]):
return "synthesize"
return "execute"
# Build the plan-and-execute graph
graph = StateGraph(PlanExecuteState)
graph.add_node("planner", planner)
graph.add_node("executor", executor)
graph.add_node("synthesizer", synthesizer)
graph.set_entry_point("planner")
graph.add_edge("planner", "executor")
graph.add_conditional_edges("executor", should_continue,
{"execute": "executor", "synthesize": "synthesizer"})
graph.add_edge("synthesizer", END)
agent = graph.compile()
# Run a long-horizon research task
result = agent.invoke({
"input": "Research the top 3 AI agent frameworks of 2026 and compare them",
"plan": [], "past_steps": [], "current_step_idx": 0, "response": ""
})
print(result["response"])
With Adaptive Replanning#
Adding a replanner that updates the plan after each step:
def replanner(state: PlanExecuteState) -> dict:
"""Decide whether to continue, replan, or complete."""
last_result = state["past_steps"][-1]["result"] if state["past_steps"] else ""
remaining_steps = state["plan"][state["current_step_idx"]:]
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=500,
messages=[{
"role": "user",
"content": f"""Given this execution result, should the plan continue as-is,
be revised, or is the task complete?
Remaining plan steps: {remaining_steps}
Last execution result: {last_result}
Respond with JSON: {{"action": "continue|revise|complete", "revised_steps": [...]}}"""
}]
)
import json
decision = json.loads(response.content[0].text)
if decision["action"] == "complete":
return {"current_step_idx": len(state["plan"])} # Jump to synthesis
elif decision["action"] == "revise":
new_plan = state["plan"][:state["current_step_idx"]] + decision["revised_steps"]
return {"plan": new_plan}
return {} # Continue as-is
Plan-and-Execute vs ReAct Comparison#
| Dimension | Plan-and-Execute | ReAct |
|---|---|---|
| Planning | Upfront, explicit | Interleaved with action |
| Auditability | High — plan visible before execution | Low — decisions made in-flight |
| Long tasks | Stronger — maintains goal coherence | Weaker — context drift over many steps |
| Adaptability | Lower (needs replanner) | Higher — naturally adaptive |
| Parallelization | Easy — plan identifies parallel steps | Hard — each step depends on previous |
| Best for | Research, multi-step workflows | Dynamic, short tasks |
Common Misconceptions#
Misconception: The plan-and-execute pattern cannot adapt to new information Without a replanner, the original plan executes rigidly. With adaptive replanning (checking after each step whether the plan still makes sense), plan-and-execute can be nearly as adaptive as ReAct while maintaining better auditability.
Misconception: Planning is always slower than reactive execution For long tasks, planning upfront saves time by avoiding redundant steps, identifying parallelizable work, and preventing dead-end exploration. The planning overhead is usually amortized across a long execution.
Misconception: Plan-and-execute requires a separate planner model The same model can handle both planning and execution — the separation is architectural, not necessarily requiring different models. Using a specialized planner model is an optimization, not a requirement.
Related Terms#
- Agent Planning — The broader concept of how agents plan tasks
- ReAct (Reasoning + Acting) — The interleaved alternative to plan-and-execute
- Subagent — Executor agents that carry out plan steps
- Agent Loop — The execution cycle plan-and-execute structures
- Agentic Workflow — Multi-step workflows built with plan-and-execute
- LangGraph Multi-Agent Tutorial — Tutorial building stateful workflows with plan-and-execute patterns
- CrewAI vs LangChain — Comparing framework support for planning architectures
Frequently Asked Questions#
What is the plan-and-execute pattern in AI agents?#
The plan-and-execute pattern is an agent architecture with two distinct phases: a planning phase where a planner LLM generates a complete task decomposition, and an execution phase where executor agents carry out each step. Unlike ReAct where planning and execution are interleaved, plan-and-execute makes the full plan visible upfront.
How does plan-and-execute differ from ReAct?#
ReAct interleaves reasoning and action — one thought, one action, observe, repeat. Plan-and-execute separates them — the planner creates the complete task decomposition first, then executors carry it out. Plan-and-execute is better for long-horizon tasks requiring coherence; ReAct is better for dynamic tasks where each action's result determines the next step.
When should I use plan-and-execute vs ReAct?#
Use plan-and-execute when the task is long (5+ steps), when the plan can be determined before execution begins, or when human review of the plan before execution adds value. Use ReAct when the next action depends heavily on the previous result, when the task is short, or when the task domain is too unpredictable to plan upfront.
What is the role of the replanner in plan-and-execute?#
A replanner monitors execution progress and updates the plan when results diverge from expectations. After each step, it decides whether to continue with the original plan, modify remaining steps, or complete early. Adaptive replanning combines the upfront visibility of plan-and-execute with the flexibility of dynamic reasoning.