Plan-and-Execute Agents: Task Decomposition, Step Tracking & Dynamic Re-Planning
Why pure ReAct loses the plot on 12-step tasks, how Plan-and-Execute separates strategic planning from tactical execution, Frontier-Planner + Mini-Executor model tiering, and dynamic re-planning when tools fail!
Plan-and-Execute separates high-level task decomposition (creating an ordered step list) from focused step execution, dynamically updating the plan whenever a step uncovers surprises.
Pure step-by-step ReAct loses the big picture on 15-step tasks; explicit planning keeps long-horizon work coherent while allowing cheaper models to execute routine sub-steps.
ReAct agents are tactical sprinters — on long 10-step research or analytics tasks, they wander, forget earlier sub-goals, and burn Frontier tokens on every trivial step!
Plan-and-Execute gives you an explicit, inspectable checklist ([S1, S2, S3]) you can stream to users in the UI, resume after crashes, and execute with cheap mini models.
When Step 2 discovers unexpected schema drift or an empty API response, a Dynamic Re-Planner splices recovery steps automatically instead of crashing with NaN.
Top system-design & coding interview question: 'How does Plan-and-Execute differ from ReAct, and how do you handle a mid-plan tool failure without restarting from scratch?'
If Step 2 of a 4-step plan fails with 404 Endpoint Deprecated, what is the best recovery behavior?
- Contrast greedy single-step ReAct loops with explicit Plan-and-Execute task decomposition
- Design a typed
PlanStatewithsteps[],completed_results[], and a bounded Dynamic Re-Planner - Slash multi-step agent costs by 60%+ using Model Tiering (Frontier Planner + Fast Mini Executor)
- Prevent infinite re-planning loops with a strict
max_replansbudget and progress invariants
[Fetch Q3 CSV, Query Billing DB, Compute YoY Growth, Draft Memo].Think of ReAct like hiking through a forest looking only one step ahead at your feet — great for short trails, terrible for a 12-mile summit. Plan-and-Execute is checking the topographic map at the trailhead, writing down 5 clear waypoints, and re-routing calmly if a bridge washes out at Waypoint 2!
1. Why Pure ReAct Struggles on Long-Horizon Tasks
In Module 1, ReAct (Thought → Action → Observation) shined on 2–4 step lookups. Push ReAct to a 12-step research or analytics workflow and three failure modes hit immediately:
- Myopic wandering: Deciding only one step ahead causes detours and forgotten early constraints.
- Frontier token burn: Every trivial step re-sends the growing transcript to your most expensive reasoning model.
- Zero user visibility: Users stare at a spinner with no live progress checklist.
Plan-and-Execute solves all three by separating strategic planning from tactical step execution!
Tracing a Self-Healing Plan-and-Execute Run
User asks: 'Compare our Q3 enterprise revenue against last quarter and summarize the top 2 drivers.'
The Planner outputs a crisp 3-step JSON plan: [1: Fetch Q2 CSV, 2: Query Stripe Q3 API, 3: Compute delta & summarize]. Users immediately see the live checklist!
2. Static Plans vs. Dynamic Re-Planning
Early Plan-and-Execute prototypes emitted a rigid list once and ran it blindly — breaking the moment real-world APIs returned unexpected data or 404s.
Production systems add a Dynamic Re-Planner on failure or surprise:
- Keep
completed_results[]immutable — never redo work that already succeeded. - Mutate only the remaining tail
steps[]: splice a fallback step, skip redundant steps, or exit early. - Enforce
max_replans(e.g.,3) so a broken downstream API triggers a graceful fallback rather than an infinite re-plan storm.
Plan-DAG Failure & Dynamic Re-Planner Simulator
When a Dynamic Re-Planner runs after Step 2 fails, what should happen to Step 1's completed result?
3. Model Tiering: Frontier Planner + Mini Executor
One of the highest-ROI production tricks in Agentic AI is asymmetric model routing:
- Use a Frontier Reasoning Model once to decompose the goal into unambiguous, atomic steps (and only re-invoke it when re-planning is needed).
- Dispatch each atomic step to a fast Mini/Flash Executor with only the 2–3 tools needed for that step — cutting latency by 2×+ and LLM spend by 60%–80%!
Click each term to see why separating Planning from Execution cuts production bills dramatically.
Combined LLM API spend to finish a multi-step goal from prompt to final answer.
The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.
No! Plan-and-Execute adds an extra upfront Planner LLM call. For simple 1–2 step tasks, a fast single-turn tool call or basic ReAct loop is much faster and cheaper.
Plan-and-Execute + Dynamic Re-Planner Recovery Studio
Watch the Executor hit an unexpected 404 on Step 2 and the Re-Planner dynamically splice a recovery step.
max_replans), giving long-horizon agents global coherence, live UI checklists, self-healing recovery, and 60%+ lower cost.Deep Research & Competitive Intelligence
Generates an explicit multi-step research checklist before browsing, streaming live progress to users.
Automated SQL & BI Data Analysts
Decomposes multi-table analytics questions into verifiable query steps with dynamic re-planning on schema surprises.
from dataclasses import dataclass, field
from typing import List, Dict, Any
@dataclass
class PlanState:
goal: str
steps: List[str] = field(default_factory=list)
completed: List[Dict[str, Any]] = field(default_factory=list)
replans: int = 0
max_replans: int = 3
def run_plan_and_execute(goal: str, planner, executor, replanner) -> str:
state = PlanState(goal=goal, steps=planner(goal))
while state.steps:
current_step = state.steps.pop(0)
obs = executor(current_step, context=state.completed)
state.completed.append({"step": current_step, "obs": obs})
if obs.get("status") == "error" or obs.get("needs_replan"):
if state.replans >= state.max_replans:
return f"Stopped safely after {state.max_replans} re-plans: {obs}"
state.replans += 1
decision = replanner(state.goal, state.completed, state.steps)
if decision["done"]:
return decision["final_answer"]
state.steps = decision["updated_steps"]
return replanner(state.goal, state.completed, [])["final_answer"]
max_replans cap on the Dynamic Re-Planner.max_replans = 3 so a persistently broken API exits gracefully instead of looping forever.