Module 4 · Lesson 5 · 17 min read
The plan, then execute, then replan pattern
Plan-and-Execute
Introduction
In ReAct the agent decides the next step in each cycle. In the plan-and-execute pattern, the planner first makes a complete plan, then an executor carries it out step by step, and a replanner steps in on failure. In this lesson we understand the components of this pattern and when we prefer it, and build a complete version in Python.
Learning objectives
- Identify the components of the plan-and-execute pattern: the planner, the executor and the replanner
- Compare the pattern with ReAct in terms of cost, clarity and flexibility
- Implement a loop that executes a plan and replans a failed step without redoing what succeeded
- Link the pattern to saved state and human approval of the plan
The idea: separate the big thinking from the execution
The plan-and-execute pattern divides the work among three roles:
- Planner: receives the goal and generates a complete plan of ordered steps. It usually uses the most capable model available, because the quality of the plan determines everything after it.
- Executor: carries out each step separately through the tools. It can be a smaller, cheaper model, or even ordinary code when the step is fully specified.
- Replanner: if a step fails or information appears that changes the picture, it revises only the remaining part of the plan.
The idea is linked to the Plan-and-Solve paper (Wang and colleagues, 2023), which proposed that the model makes a plan before solving, and it developed in agent frameworks into a structure that separates planning from execution in code.
Comparison with the ReAct pattern
| Criterion | ReAct | Plan and execute |
|---|---|---|
| When the decision is made | In every cycle | Once at the start, then when needed |
| Cost | The large model is called at every step | The large model is usually only for planning |
| Clarity | The plan is not visible in advance | The plan is visible and can be shown for approval |
| Adaptation | Fast with every observation | Needs an explicit replanning mechanism |
The practical rule: if the environment is unpredictable and every observation may change the direction, ReAct fits better. If the task is long and its structure is relatively known, or the user needs to approve what will happen, plan-and-execute fits better.
A practical example: organizing an open day for the computer science department
The goal: "Organize an open day for new students on a budget of 5000." The planner generates four steps. During execution the step of booking the main hall fails because it is already booked, so the replanner replaces only this step with booking an alternative hall, without redoing the successful steps. We represent the planner and the replanner with deterministic functions so the example runs without a model:
def planner(goal):
return [
{"id": 1, "tool": "check_budget", "args": {"limit": 5000}},
{"id": 2, "tool": "book_room", "args": {"room": "Main hall"}},
{"id": 3, "tool": "invite_speakers", "args": {"count": 2}},
{"id": 4, "tool": "announce", "args": {"channel": "Student email"}},
]
BOOKED = {"Main hall"}
def check_budget(limit): return f"A budget of {limit} is available"
def book_room(room):
if room in BOOKED:
raise RuntimeError(f"{room} is already booked")
return f"{room} has been booked"
def invite_speakers(count): return f"{count} invitations sent"
def announce(channel): return f"The announcement was published via {channel}"
TOOLS = {f.__name__: f for f in (check_budget, book_room, invite_speakers, announce)}
def replanner(step, error):
if step["tool"] == "book_room":
return dict(step, args={"room": "Labs hall"})
return None # no alternative: execution stops
def run(goal, max_replans=2):
plan, done, replans = planner(goal), [], 0
i = 0
while i < len(plan):
step = plan[i]
try:
result = TOOLS[step["tool"]](**step["args"])
done.append((step["id"], result))
print(f"Step {step['id']}: {result}")
i += 1
except RuntimeError as e:
print(f"Step {step['id']} failed: {e}")
new_step = replanner(step, e)
if new_step is None or replans >= max_replans:
return "Stopped: needs human intervention", done
plan[i] = new_step
replans += 1
return "The plan is complete", done
status, log = run("An open day for the computer science department")
print(status, "- Number of steps executed:", len(log))The first step is executed, the second fails, so the replanner replaces it, and then the plan completes with four successful steps. Notice two things: the first step was not redone, and the number of replans is limited so the agent does not go round endlessly.
Saved state
In long tasks the plan and the status of each step must be saved outside the program's temporary memory, so that work can resume after an interruption. Frameworks such as LangGraph help here; according to the official documentation (reviewed 18 November 2026, version 1.2.22) it offers durable execution, state persistence and support for human-in-the-loop intervention. The planner, the executor and the replanner can be represented as nodes in a state graph, and you will see this in practice in the LangGraph lesson.
Summary
The plan-and-execute pattern separates a planner that makes a complete plan, an executor that carries out the steps through tools, and a replanner that revises what remains on failure. The pattern reduces calls to the large model and makes the plan visible and open to approval, but it needs an explicit replanning mechanism. Good replanning does not redo successful steps and has a maximum. In long tasks the plan and its status are saved outside the program, and their assumptions are rechecked before resuming.
Terms
| Term | English | Definition |
|---|---|---|
| Plan and execute | Plan-and-Execute | A pattern that makes the whole plan first and then carries it out step by step |
| Planner | Planner | The component that generates the plan from the goal |
| Executor | Executor | The component that carries out each step through the tools |
| Replanning | Replanning | Revising the remaining part of the plan after a failure or new information |
| Durable execution | Durable Execution | The system's ability to save progress and resume after an interruption |
Review questions
- What is the role of the planner, the executor and the replanner?
- When would you prefer plan-and-execute to ReAct? Give two examples.
- Why must the replanner not redo the steps that succeeded?
- What is the danger of running a plan saved some time ago without rechecking it?
References
- Plan-and-Solve Prompting arxiv.org Reviewed on 2026-11-18
- LangGraph overview docs.langchain.com Reviewed on 2026-11-18
- Building effective agents (Anthropic) www.anthropic.com Reviewed on 2026-11-18
