Why it matters
Open-ended agent loops have a characteristic failure: they work locally and drift globally. Each step is reasonable, the sequence is not. The agent reads the docs, edits the config, then reads the docs again, because nothing forced it to decide what the whole job required.
Planning addresses that by making the shape of the work explicit. It also makes cost predictable in batches, gives the user something to approve before side effects, and gives you a debugging artefact: when a run fails, the plan tells you which belief was wrong.
Mental model
A route plan for a delivery van. Before leaving, the driver orders stops by geography and time window. Mid-route, a closed road forces a re-plan, and the driver does not pretend the original route is still valid.
The analogy breaks because the driver can see the closed road. An agent often cannot tell the difference between "the step failed" and "the step succeeded in a way I did not expect". A plan without an explicit invalidation signal tends to survive contact with reality far longer than it should.
How it works
- 1Decide whether to plan. Signals for planning: more than roughly five dependent steps, multiple files or systems, irreversible actions, or a task where the user should approve the approach. Short single-tool tasks do not need it.
- 2Choose a representation. A numbered list is enough for linear work. Add explicit dependencies when steps can run in parallel. Add expected observations when you want to check progress.
- 3Generate the plan with the constraints in view. Include the budget, the allowed tools and the definition of done. A plan made without the action space produces steps the agent cannot execute.
- 4Validate before executing. Every step must map to an available tool or a known capability chain. Reject plans that reference tools that do not exist, or that end without a verification step.
- 5Execute step by step, carrying state. After each step, record the outcome against the step, not just in the transcript.
- 6Re-plan on named triggers. A step failed twice, an observation contradicted an assumption, the remaining budget fell below the estimated cost, or the user changed the goal. Anything else continues.
Step 1 of 6
Decide whether to plan. Signals for planning: more than roughly five dependent steps, multiple files or systems, irreversible actions, or a task where the user should approve the approach. Short single-tool tasks do not need it.
Figure. The mechanism in this page's own steps. The figure adds sequence, not new claims.
What to notice. A step can be read alone, but the order is the mechanism. The control lets you stop on any one.
Text version
The page's steps: 1. Decide whether to plan. Signals for planning: more than roughly five dependent steps, mul… 2. Choose a representation. A numbered list is enough for linear work. Add explicit dependen… 3. Generate the plan with the constraints in view. Include the budget, the allowed tools and… 4. Validate before executing. Every step must map to an available tool or a known capability… 5. Execute step by step, carrying state. After each step, record the outcome against the ste… 6. Re-plan on named triggers. A step failed twice, an observation contradicted an assumption…
- Decide whether to plan. Signals for planning: more than roughly five dependent steps, multiple files or systems, irreversible actions, or a task where the user should approve the approach. Short single-tool tasks do not need it.
- Choose a representation. A numbered list is enough for linear work. Add explicit dependencies when steps can run in parallel. Add expected observations when you want to check progress.
- Generate the plan with the constraints in view. Include the budget, the allowed tools and the definition of done. A plan made without the action space produces steps the agent cannot execute.
- Validate before executing. Every step must map to an available tool or a known capability chain. Reject plans that reference tools that do not exist, or that end without a verification step.
- Execute step by step, carrying state. After each step, record the outcome against the step, not just in the transcript.
- Re-plan on named triggers. A step failed twice, an observation contradicted an assumption, the remaining budget fell below the estimated cost, or the user changed the goal. Anything else continues.
- Reconcile at the end. Check that every plan step is either done, skipped with a reason, or failed and reported. Silent omission is the most common planning bug.
Two families are worth knowing. Interleaved planning (the ReAct style) plans one step at a time and re-decides constantly; it adapts fast and pays a model call per step. Plan-and-execute commits to a list first and runs it, which is cheaper and more coherent but brittle when the world moves. Hybrids plan in phases and re-plan between them, which is what most production systems settle on.
PLAN_SCHEMA = {
"type": "object",
"properties": {
"goal": {"type": "string"},
"steps": {
"type": "array",
"maxItems": 12,
"items": {
"type": "object",
"properties": {
"id": {"type": "integer"},
"action": {"type": "string"},
"tool": {"type": "string", "enum": ["search", "read_file", "run_tests", "edit"]},
"depends_on": {"type": "array", "items": {"type": "integer"}},
"done_when": {"type": "string"},
},
"required": ["id", "action", "tool"],
},
},
},
"required": ["goal", "steps"],
}
def should_replan(step, observation, attempts, remaining_budget):
if attempts[step.id] >= 2:
return "repeated_failure"
if observation.contradicts(step.assumption):
return "assumption_violated"
if remaining_budget < estimate_remaining(step):
return "budget"
return NoneThe done_when field is the part teams skip and later miss. A step without a completion criterion becomes a step the agent can declare finished whenever it wants. Writing "tests pass for the new endpoint" instead of "add endpoint" makes the plan checkable.
Text version
A goal produces a plan, the agent acts and observes, and either replans or answers when the goal is satisfied.
Trade-offs
| Approach | Good for | Cost | Fails when |
|---|---|---|---|
| No explicit plan | One or two step tasks | Drift on long tasks | The task needs more than five dependent actions |
| Plan then execute | Stable environments, batch jobs | One bad assumption invalidates the run | The environment changes mid-task |
| Interleaved (ReAct) | Exploratory tasks, unknown state | A model call per step, less coherent | The task has a long horizon and no cheap feedback |
| Phased plan with re-planning | Most production agents | Extra calls at phase boundaries | Phases are too coarse to detect drift |
| Plan with explicit dependencies | Parallelisable subtasks | Complexity in scheduling and merge | Steps share mutable state |
Good for
One or two step tasks
Cost
Drift on long tasks
Fails when
The task needs more than five dependent actions
- The task needs more than five dependent actions
- The environment changes mid-task
- The task has a long horizon and no cheap feedback
- Phases are too coarse to detect drift
- Steps share mutable state
Figure. Each choice with what it buys, what it costs, and the case where it loses.
What to notice. The fourth column is the decision: if the losing case describes your situation, the choice is wrong.
Text version
Four trade-offs: No explicit plan is good for One or two step tasks, costs Drift on long tasks, and fails when The task needs more than five dependent actions. Plan then execute is good for Stable environments, batch jobs, costs One bad assumption invalidates the run, and fails when The environment changes mid-task. Interleaved (ReAct) is good for Exploratory tasks, unknown state, costs A model call per step, less coherent, and fails when The task has a long horizon and no cheap feedback. Phased plan with re-planning is good for Most production agents, costs Extra calls at phase boundaries, and fails when Phases are too coarse to detect drift. Plan with explicit dependencies is good for Parallelisable subtasks, costs Complexity in scheduling and merge, and fails when Steps share mutable state
Failure modes
- Unexecutable plan. The plan references a tool or permission the agent does not have, and execution stalls at step one. Debug: validate every step's tool against the registry before running; log rejected plans with the offending step.
- Zombie plan. Step three failed, but the agent continues to four through seven as if it succeeded. Debug: require each step's
done_whencheck to be evaluated and stored; alert when execution advances past an unevaluated step. - Plan restatement. The plan is the task sentence split into bullet points, adding latency and no information. Debug: compare plan steps to the prompt with a similarity check; if steps are near-duplicates, skip planning for that task class.
- Re-plan thrash. Every surprising observation triggers a new plan, and the agent spends its budget planning. Debug: cap re-plans per run (two is a reasonable start) and count them as a metric.
In production
Planning changes the cost shape from per-step to per-phase. That is good for budget forecasts and bad for tail latency: a plan call at the start adds a fixed delay before any work begins, which users notice on short tasks. Gate planning by task class rather than enabling it globally.
Keep plans as durable artefacts. A stored plan lets a crashed run resume, gives the reviewer a summary that is far cheaper to read than a transcript, and makes "which belief was wrong" answerable after an incident. It also creates an approval surface: a plan is easier to review than a tool call stream. On long-horizon tasks, the plan is often the only part of the context that must never be evicted.
Common misconceptions
People think: Planning is always better than reacting, because thinking before acting is good practice.
Actually: Planning front-loads assumptions. When feedback is cheap and the environment is unknown, interleaved decisions beat a committed plan; when feedback is expensive, the plan wins.
People think: A detailed plan is a more reliable plan.
Actually: Detail increases the number of assumptions that can be wrong. Plans should be as coarse as the task allows, with verifiable completion criteria per step.
Interview angle
Expect "how would you stop an agent from going in circles?" Planning is one answer, and the strong version explains the trade: commitment buys coherence and cost control, and costs adaptability. Then describe the invalidation rule and how you would measure it. A follow-up usually asks what happens when the plan is wrong at step two, which is really a question about state and re-planning. See agents interview questions, state and checkpoints and task decomposition.
Sources
- Wang et al., Plan-and-Solve Prompting — evidence that decomposing into subtasks before answering changes accuracy on multi-step reasoning.
- Xu et al., ReWOO: Decoupling Reasoning from Observations — plans with variable substitution, which cuts token use by not re-feeding full history.
- Kim et al., An LLM Compiler for Parallel Function Calling — dependency-aware plans that expose parallel branches.
- Anthropic, Building effective agents — when orchestration patterns such as orchestrator-workers pay for themselves.