Lesson 2 of 8 · 3 min read
Plan-and-Execute and Replanning
In this lesson
TL;DR: Plan once, check the plan in code, execute step by step, and replan when something the plan depended on is no longer true. Planning up front saves model calls, allows independent steps to run in parallel, and produces an artefact a person or a policy can approve before anything happens. The risk is a stale plan: make every step carry its preconditions and the assumptions it relies on, check them before running the step, and treat a violated assumption, a failed step or a blown budget as a trigger to replan from the current state.
After this lesson, you should be able to design a plan format that can be validated and monitored, explain the cost and latency advantages over ReAct, choose replanning triggers, and avoid both stale plans and constant replanning.
Before you read
Commit to an answer now. The lesson that follows explains it, and having guessed first, even wrongly, makes the explanation easier to remember.
1A travel agent plans: 1) book the 9:10 flight, 2) book a hotel near the airport, 3) book a car. Between steps 1 and 2 the airline cancels the flight. The agent books the hotel and car anyway. What should the plan have recorded so the executor could stop?
The shape
The model plans; code checks, runs and watches. A broken assumption sends the run back to planning.
Plan
steps, dependencies, assumptions
Validate plan
allowed tools, order, budget
Approve
policy or a person, if needed
Execute step
code or a cheaper model
Monitor
preconditions, results, budget
What sends the run back to planning
Invalid plan
unknown tool or impossible order; the planner gets the reason
Assumption broken
the flight was cancelled; replan from current state
Step failed for good
not a transient error the dispatcher can retry
Research variants differ in how far they separate the parts. Plan-and-Solve (Wang et al., 2023) prompted a model to write a plan before solving. ReWOO (Xu et al., 2023) planned all tool calls up front with placeholders for their results, so the planner ran once. LLMCompiler (Kim et al., 2023) planned a dependency graph and ran independent calls in parallel. All three report cost or latency gains over step-by-step reasoning on their benchmarks, which follows from making fewer planning calls.
Why plan first
- Fewer expensive calls. One planning call, then cheap execution, instead of a full reasoning step before every action.
- Parallelism. A dependency graph shows which steps are independent.
- Reviewability. A plan is an artefact: code can check it, a policy can approve it, a person can read it before anything irreversible happens.
- Global order. Phases that must happen in sequence are stated once rather than rediscovered at each step.
A plan that can notice it is wrong
The executor must be able to tell that a step no longer makes sense, so the plan carries what each step depends on:
PLAN = [
{"id": 1, "do": "book_flight", "args": {"flight": "AI-807"}, "needs": []},
{"id": 2, "do": "book_hotel", "args": {"near": "BLR"}, "needs": [1],
"assumes": {"flight_status:AI-807": "on_time"}},
{"id": 3, "do": "book_car", "args": {"from": "BLR"}, "needs": [1]},
]
def execute(plan, world, act):
done = {}
for step in plan:
if any(n not in done for n in step["needs"]):
return "replan", step["id"], "a step it depends on did not finish"
for key, expected in step.get("assumes", {}).items():
if world.get(key) != expected:
return "replan", step["id"], f"{key} is now {world.get(key)}"
done[step["id"]] = act(step["do"], step["args"])
return "complete", None, None
world = {"flight_status:AI-807": "on_time"}
def act(name, args):
if name == "book_flight":
world["flight_status:AI-807"] = "cancelled" # the world moves
return "ok"
status, step, reason = execute(PLAN, world, act)
print(status, step, reason) # => replan 2 flight_status:AI-807 is now cancelled
The executor stops before booking the hotel and hands the planner the reason and the current state. The replan starts from what is already done (a cancelled flight that may need a refund), not from the original request.
Replanning without thrashing
Replanning too rarely runs stale plans; replanning too often turns plan-and-execute back into an expensive ReAct. Good triggers are specific:
| Trigger | Replan? |
|---|---|
| A stated assumption or precondition is false | Yes, from current state |
| A step failed permanently (not a transient error) | Yes |
| A step succeeded but its result differs from what the plan expected | If later steps depend on it |
| Budget for the run is mostly spent with work left | Yes, with the remaining budget as a constraint |
| A transient error | No: the dispatcher retries |
| A cosmetic difference in a result | No |
Cap the number of replans per run, and treat hitting the cap as a stop condition that hands the case to a person.
Say it in 30 seconds
"Plan-and-execute has the model write the plan once, with steps, dependencies and the assumptions each step relies on; code validates it, policy or a person can approve it, and an executor runs it with code or a cheaper model while a monitor checks preconditions and results. It saves calls, enables parallel steps and gives reviewers an artefact. The danger is a stale plan, so I replan from current state on broken assumptions, permanent failures, results later steps depend on, or budget pressure, never on transient errors, and I cap replans."
Check yourself
Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.
1Why should a replan start from the current state rather than the original request?
2Name two advantages of a plan as an artefact that ReAct does not give you.
3Why shouldn't a transient error trigger a replan?