Planning (plan-and-execute)
A strong model writes an explicit step-by-step plan first; the steps are executed (often by a cheaper model with tools), and the agent replans only when a step fails or new facts appear.
Analogy: A contractor drafts the renovation schedule before any wall comes down. Crews follow it step by step, and when they find a rotten beam the schedule is revised, not thrown away.
How it works
- Unlike ReAct: the agent loop, which picks one action per turn, it commits to a route and adapts at checkpoints.
- Variants: ReWOO plans every tool call in one LLM call; LLMCompiler runs the plan's DAG in parallel.
- Coding agents' to-do lists are a living plan the model rewrites and the user can see and correct.
- You gain fewer expensive calls and a reviewable plan; you risk stale plans and over-planning simple tasks.
- Keep plans to 3–10 steps, each with a "done when" check; cap replans at 2–3, then escalate.
Check yourself
Answer to mark it learned; your answers aren't scored.
A pure-ReAct agent on a frontier model reconciles 12 invoices per run: ~45 calls, each re-reading a growing transcript, and it sometimes re-checks the same invoice. The ops lead also wants to approve what happens before any payment is touched. Best redesign?
Go deeper
Full explanation
Planning (plan-and-execute) splits an agent into roles. A planner writes an explicit, ordered list of steps for the whole task up front; an executor carries them out one by one, often with a cheaper model and its own short tool loop. When a step fails or reveals something new, a replanner revises the remaining steps from the evidence.
Contrast with ReAct: the agent loop, which interleaves think → act → observe and decides only the next action each turn. ReAct adapts instantly but pays a full-context LLM call per step and can wander; plan-and-execute commits to a route and adapts at checkpoints.
Variants worth naming:
- ReWOO: the planner writes every tool call with placeholders (
#E1,#E2), workers fill them without calling the LLM again, and a solver writes the answer. One planning call instead of one per step. - LLMCompiler: the plan is a DAG, so independent tool calls run in parallel.
- To-do lists in coding agents: Claude Code's task list (
TodoWrite, replaced in 2026 byTaskCreate/TaskUpdate) or Cursor's to-dos are a lightweight, living plan the model rewrites as it goes and the user can see and correct.
What you buy: fewer calls to the expensive model, a plan a human can review before anything runs, and steerability. What you risk: stale plans executed after reality changed, and over-planning a two-step task.
Code Plan once, execute cheaply, replan on failure
from openai import OpenAI
from pydantic import BaseModel
client = OpenAI()
PLANNER = "gpt-4.1" # strong model: plans and replans
EXECUTOR = "gpt-4.1-mini" # cheap model: one step at a time
MAX_REPLANS = 2
class Step(BaseModel):
id: int
action: str # e.g. "fetch PO for invoice INV-7"
done_when: str # verifiable exit check, not "looks fine"
class Plan(BaseModel):
steps: list[Step]
def make_plan(goal: str, progress: str = "") -> Plan:
r = client.responses.parse(model=PLANNER, text_format=Plan, input=(
f"Goal: {goal}\nDone so far:\n{progress}\nWrite 3-10 remaining steps."))
return r.output_parsed
def run(goal: str) -> list[str]:
done: list[str] = []
plan = make_plan(goal)
for _ in range(MAX_REPLANS + 1):
for step in plan.steps:
out = execute_step(EXECUTOR, step, done) # small ReAct loop scoped to one step
if not out.ok: # replan from evidence; keep finished work
plan = make_plan(goal, "\n".join(done) + f"\nFAILED {step.action}: {out.error}")
break
done.append(f"{step.action} -> {out.summary}")
else:
return done
raise RuntimeError("Still failing after replans: escalate to a human")Real example
A finance-ops agent reconciles 12 vendor invoices against purchase orders. Version 1 was pure ReAct on a frontier model: ~45 calls per run, each re-reading a growing transcript, ~$1.80 per run, and it sometimes re-checked the same invoice. Version 2 is plan-and-execute: one frontier call writes a 13-step plan (one step per invoice plus a summary), a mini model runs each step with a small fresh context, and the ops lead sees the plan before any payment is touched. Invoice #7 has no PO, so the replanner inserts an "email vendor" step. Cost falls to ~$0.35 per run.
Trade-offs +4 · −3
+ You gain
- Fewer calls to the expensive model: plan once, execute steps with a cheap one.
- A visible plan that a human or a policy can approve before side effects.
- Easier debugging: a failure points to one step, not a 40-turn transcript.
- Independent steps can run in parallel when the plan is a DAG.
− You pay
- The planner commits before seeing any tool result, so plans go stale.
- Extra latency and tokens on tasks that only needed one or two tool calls.
- Replanning policy (when, how often, what to keep) is new logic you must test.
Use it when
Multi-step tasks with a predictable shape (reconciliations, migrations, research reports, multi-file code changes) where cost matters or a human must approve the plan before side effects.
Avoid it when
Tasks of one to three tool calls, or exploratory ones (debugging, open-ended browsing) where every observation changes the next move. A plain ReAct loop is simpler there.
Numbers to know 3
- ReWOO (Xu et al., 2023): ~5× token efficiency and +4% accuracy on HotpotQA versus interleaved reasoning.
- LLMCompiler (Kim et al., 2023): up to 3.7× lower latency and 6.7× lower cost than ReAct by running the plan's DAG in parallel.
- Rule of thumb: 3–10 steps per plan, each with a "done when" check; cap replans at 2–3, then escalate.
Common pitfalls 4
- Never replanning, so step 6 runs against data that step 2 already changed.
- Over-planning: a 25-step plan for a 3-step task, full of steps the planner cannot know yet.
- Vague steps with no exit check, so the executor cannot tell success from failure.
- Replanning from scratch on every hiccup, throwing away finished work and looping.
Interview questions 2
Answer out loud first, then reveal.
ReAct or plan-and-execute: how do you choose?Show answer
It depends on how predictable the task is and how expensive the model is. If the shape is known up front, like reconciling 12 invoices or migrating 30 files, I plan once with a strong model and execute with a cheap one: fewer big-model calls, and a plan a human can approve before side effects. If each observation changes the next move, like debugging, I use ReAct. In practice I often combine them: a living to-do list on top, a short ReAct loop inside each step.
The plan turns out to be wrong halfway through. What does your agent do?Show answer
Each step carries a verifiable "done when" check, so failure is detected, not guessed. On failure I replan with the evidence: finished steps, the error, what changed. I keep completed work instead of starting over. I cap replans at two or three, then the agent stops and escalates rather than burning tokens. For side-effecting steps I re-check preconditions right before running them, because the plan was written against a world that may have moved.