Plan-and-execute agent: a strong planner and a cheap executor
A plan-and-execute agent has a large model write the plan once, then a smaller model carries out each step. Use it for longer tasks with routine steps, where cost and speed matter.
Plan-and-execute agent in 60 seconds
- What: an agent that separates planning from doing. A large model writes the plan, a smaller model runs each step.
- How: plan once, execute steps one by one, check each result, and replan only when a step fails.
- Best for: longer tasks with many routine steps, such as data clean-up, document processing, and multi-part research.
- Weak spots: a weak first plan spoils the run, and replanning can loop if limits are missing.
- Research link: Plan-and-Solve prompting (Wang et al., 2023) splits a task into subtasks first. LLMCompiler (Kim et al., 2023) plans calls as a dependency graph and runs independent ones in parallel.
Where this type fits
The types of AI agents hub groups agents by how they decide. Plan-and-execute belongs to the first family, next to the planning agent and the ReAct agent. It takes the up-front plan of the first and the step-by-step action of the second, then assigns each job to the model that suits it. The result is a design shaped by cost and control as much as by capability.
The problem it solves
A ReAct loop asks a large model to think at every step. For a task with twenty steps, that means twenty expensive calls, each re-reading a growing trace. Most of those steps are routine: fetch this record, format that field, write this row. They do not need the strongest model, yet the loop pays for it every time. Cost and delay climb with task length.
There is a quality problem too. A model that decides one step at a time can lose sight of the overall goal. After many steps it may drift, repeat work, or skip a stage it forgot about. A written plan acts as a fixed reference. The executor does not need to remember the whole task. It only needs the current step and the results it depends on.
Finally, a single pass of planning is weak when the world pushes back. If the plan is followed blindly, one failed step ruins the rest. Plan-and-execute adds a check after each step and a bounded way back to the planner. It keeps the savings of a short planning phase and the resilience of a feedback loop.
How it works
- Take the goal. State the goal and what done looks like, plus any limits on cost, time, or tools.
- Plan with a large model. The planner returns a short list of steps, each with a clear instruction, the tool it needs, and the earlier steps it depends on.
- Execute with a smaller model. The executor receives one step at a time, along with only the results that step needs. It calls tools and returns a result.
- Check each result. A rule, a schema check, or a light model confirms the step did what it was asked. Failures are caught here, not at the end.
- Replan once if a step fails. The planner receives the goal, the finished steps, and the failure, and writes a revised plan for the remaining work. The number of replans is capped.
- Return the result. The agent assembles the step results into the final output.
The diagram makes the division of labour clear. The planner appears only at the start and on the dashed return path. The executor and the check carry the repeated work. That is where the savings come from: the expensive model is called a few times, not once per step.
Independent steps can run together. LLMCompiler, by Kim and colleagues in 2023, plans function calls as a dependency graph and runs the independent calls in parallel. If steps two and three both depend only on step one, they can run at the same moment. Plan-and-Solve prompting, by Wang and colleagues in 2023, covers the planning half: ask the model to split the task into subtasks, then carry them out. Plan-and-execute puts both ideas into one production design.
A worked example
Acme needs a supplier summary. The goal: "For each of our three largest suppliers, find the contract end date and any open disputes, then write a one-page summary." The planner is a large model. The executor is a smaller one.
The planner returns four steps. Step 1: list_suppliers(top=3). Step 2: for each supplier, get_contract(supplier_id). Step 3: for each supplier, list_disputes(supplier_id, status=open). Step 4: write the summary from the results of steps 2 and 3. It marks steps 2 and 3 as independent of each other, since both need only step 1.
The executor runs step 1 and gets three suppliers: Northgate Metals, Brightline Packaging, and Orchard Freight. Steps 2 and 3 run in parallel for each supplier. The contract results show end dates of 2027-03-31, 2026-12-15, and 2028-06-30. The checker validates each result against a schema, requiring a date in a valid format.
Step 3 for Brightline Packaging fails. The dispute service returns an error. The check flags it. The agent sends the goal, the finished results, and the failure to the planner. The planner revises only the remaining work: retry the dispute lookup, and if it still fails, mark the dispute field as "unavailable" and note it in the summary. The retry succeeds with one open dispute. Step 4 writes the summary. In total the large model was called twice, and the smaller model handled every tool step.
{
"goal": "Supplier summary for top 3 suppliers",
"steps": [
{"id": 1, "do": "List the three largest suppliers", "tool": "list_suppliers", "needs": []},
{"id": 2, "do": "Get contract end date per supplier", "tool": "get_contract", "needs": [1], "for_each": "supplier"},
{"id": 3, "do": "List open disputes per supplier", "tool": "list_disputes", "needs": [1], "for_each": "supplier"},
{"id": 4, "do": "Write a one-page summary", "tool": null, "needs": [2, 3]}
]
}Building it
The sketch below shows the core loop. The planner and executor are separate calls with separate models. Each step has a check, a timeout, and a retry. Replanning is capped at one. planner_llm.generate(), executor_llm.generate(), and run_tool() are placeholders for your own code.
import json
# Placeholders: planner_llm and executor_llm are two different model clients.
# run_tool(name, args, timeout_s) -> dict. check_result(step, result) -> bool.
MAX_STEPS = 12 # cap plan size
MAX_REPLANS = 1 # the diagram says: replan once
STEP_RETRIES = 1 # retry a failed step once before replanning
TOOL_TIMEOUT_S = 20
def make_plan(goal, done=None, failure=None):
# The large model sees the goal and, on replan, the finished work and the failure.
prompt = {'goal': goal, 'done': done or {}, 'failure': failure}
steps = json.loads(planner_llm.generate(json.dumps(prompt)))
return steps[:MAX_STEPS]
def run_step(step, results):
# The small model gets only this step and the results it depends on.
inputs = {sid: results[sid] for sid in step.get('needs', []) if sid in results}
args = json.loads(executor_llm.generate(json.dumps({'step': step, 'inputs': inputs})))
return run_tool(step['tool'], args, TOOL_TIMEOUT_S) if step.get('tool') else args
def execute(plan, results):
for step in plan:
if step['id'] in results:
continue # reuse finished work after a replan
for attempt in range(STEP_RETRIES + 1):
try:
out = run_step(step, results)
if check_result(step, out):
results[step['id']] = out
break
except Exception as err:
out = {'error': str(err)[:200]}
else:
return {'failed_step': step['id'], 'last': out}
return None
def run_agent(goal):
results = {}
plan = make_plan(goal)
for replan in range(MAX_REPLANS + 1):
failure = execute(plan, results)
if failure is None:
return {'status': 'done', 'results': results}
if replan == MAX_REPLANS:
break # out of replans: stop, do not loop
plan = make_plan(goal, done=results, failure=failure)
return {'status': 'partial', 'results': results, 'failure': failure}
Note the line that skips steps already in results. It lets a revised plan reuse finished work. Without it, a replan repeats every call, wastes money, and can repeat side effects.
Design decisions
- Model split: use a strong model to plan and a smaller one to execute. Default to this when more than half of the steps are routine. If most steps need judgement, use one model throughout.
- Step checks: validate every result with a schema or a rule where you can. A model-based check is the fallback, because it adds cost and its own errors.
- Replan limit: allow one replan, at most two. Beyond that, return a partial result and escalate to a person.
- Parallelism: run steps that share no dependency at the same time. Mark dependencies explicitly in the plan so the runner can find them. Keep write steps sequential unless they are idempotent.
- State storage: keep results in a store keyed by run and step id. This makes replanning cheap and lets a crashed run resume.
- Access control: check tool permissions in code per step, and give the executor only the tools the plan needs.
- Context passing: hand each step only the results it needs. Smaller prompts are cheaper and reduce the chance of confusion.
Measuring it
- Task success rate: the share of test goals completed correctly. Compare it with a single-model ReAct baseline on the same goals.
- Cost per task: total tokens and tool charges, split between planner and executor. The saving over the baseline is the main reason to use this design.
- Plan quality: the share of plans judged complete and correctly ordered by a checklist or a reviewer, before any step runs.
- Step failure and replan rate: failed steps per run and the share of runs that needed a replan. High values mean weak plans or flaky tools.
- Wall-clock time: total time with and without parallel steps, to confirm the dependency graph is paying off.
When to use it, and when not to
| Situation | Use this type? | Why |
|---|---|---|
| Long tasks with many routine, repeatable steps | Yes | A cheap executor handles the bulk, and the planner is called rarely. |
| Batch work across many items, such as one lookup per supplier | Yes | The plan repeats a pattern, and independent items can run in parallel. |
| Tasks where you want a reviewable plan but lower cost than a pure ReAct loop | Yes | The plan can be shown for approval, and execution stays cheap. |
| Short tasks of two or three steps | No | Planning overhead outweighs the saving. Use a ReAct agent. |
| Exploratory work where early results change the whole direction | No | The plan would keep breaking. A ReAct loop adapts step by step. |
| Steps that each need deep reasoning | Maybe | A small executor may be too weak. Test it before committing. |
Trade-offs
| Dimension | Effect | What to do about it |
|---|---|---|
| Quality | Good when the plan is sound. A flawed plan is carried out faithfully, and a small executor may miss subtleties. | Check plans, and test the executor on real steps. |
| Latency | Planning delay up front, then fast steps, and faster still with parallel work. | Run independent steps together and keep plans short. |
| Cost | Lower than a full-strength loop on long tasks, because most calls use the smaller model. | Measure against a baseline to confirm the saving. |
| Complexity | Higher than ReAct: two models, a plan format, a checker, and a replan path. | Store plans as data and log every step. |
| Failure modes | Weak first plans, replan loops, and an executor that wanders from its step. | Cap replans, validate results, and give the executor narrow instructions. |
Compared with related types
The planning agent uses one model for everything and focuses on review before action. Plan-and-execute keeps the plan but optimises how the work is done and paid for. The ReAct agent skips the plan and adapts at every step. It handles uncertainty better, and it costs more on long tasks.
When the plan has several independent parts, the parallel fan-out and merge pattern shows how to run them at once and combine the results. If different steps need different specialists, look at supervisor with workers, which extends the same idea across several agents.
What this means for your role
Common mistakes
Further reading
- Types of AI agents: the hub page that compares every agent type.
- Plan-and-Solve prompting, Wang et al., 2023: asks the model to first devise a plan that splits the task into subtasks, then carry the subtasks out.
- LLMCompiler, Kim et al., 2023: plans function calls as a dependency graph and runs independent calls in parallel.
- Inference and serving: why model size drives cost and latency.
- Gateway, cost and reliability: controls for spend and failures.
Plan-and-execute spends thinking where it pays and saves it where it does not. Measure it against a simple loop on your own tasks before you commit to the extra moving parts.