With replanner (default)
All steps
Parts of this pattern
- Goal Input / output
- The open-ended goal, such as 'Write a brief on a competitor'.
- Planner LLM call
- Writes the whole step-by-step plan once, before any tool is used; the last step yields the answer.
- Plan Memory
- The explicit, inspectable list of remaining steps; the executor reads it and the replanner rewrites it.
- Executor Agent
- A small ReAct-style agent that completes one plan step at a time using the tools.
- Tools Tool
- The tools the executor calls to do a step, such as web search for a competitor's pricing.
- Replanner LLM call
- After each step, compares the plan and results so far, then returns revised steps or the final answer.
- Answer Input / output
- The finished deliverable, such as the competitor brief, returned when the replanner has a final_answer.
- Goal → Planner
- The goal goes to the planner before any tool is touched.
Write a one-page brief on competitor Acme: products, pricing and recent news.
- Planner → Plansteps
- The planner's numbered step list is stored as the plan.
1. Find Acme's product lines and pricing. 2. Find recent news. 3. Write the brief from the findings.
- Plan → Executornext step
- The first remaining step is handed to the executor as a self-contained task.
Find Acme's product lines and pricing.
- Executor → Tools
- A tool call the executor makes while working on the current step.
web_search(query="Acme pricing plans 2026")
- Tools → Executor
- The tool's output returns to the executor to use in finishing the step.
Acme sells Basic ($20/mo), Pro ($60/mo) and Enterprise (custom).
- Executor → Replannerresult
- The finished step and its result are recorded as a past step for the replanner.
Step 1 done: Acme has three tiers, Basic $20, Pro $60, Enterprise custom.
- Replanner → Planrevise
- The replanner writes back the updated remaining steps, not merely the old list minus one step.
{"remaining_steps": ["Find recent Acme news, focusing on the Enterprise launch", "Write the brief"]}
- Replanner → Answerdone
- When the results already answer the goal, the replanner returns the final answer instead of steps.
{"final_answer": "Acme Competitor Brief: three pricing tiers, strong Enterprise push..."}
Plan-and-Solve
No tools and no replanner: one model call writes a plan and then works through it, and a short second call extracts the answer.
All steps
Parts of this pattern
- Question Input / output
- A word problem whose facts are all given, such as 'A cafe sells 120 coffees a day at $4; how much in 2 days?'.
- Plan LLM call
- The first half of one model reply: it pulls out the variables and writes a short numbered plan.
- Solve LLM call
- The second half of the same reply: it works through each planned step, showing the intermediate values.
- Extract LLM call
- A short second call that reads the reasoning and returns only the final answer, in the expected format.
- Answer Input / output
- The bare answer, such as 960, returned with the reasoning that produced it.
- Question → Plan
- The question goes in with the Plan-and-Solve trigger sentence appended.
Q: A cafe sells 120 coffees a day at $4 each. How much does it take in over 2 days? A: Let's first understand the problem...
- Plan → Solveplan
- The plan is written into the same reply, so the solving half follows it step by step.
Variables: 120 coffees/day, $4 each, 2 days. Plan: 1. Daily takings. 2. Multiply by the days.
- Solve → Extractreasoning
- The full reasoning text, plan and worked steps together, goes to the extraction call.
Step 1: 120 x $4 = $480 a day. Step 2: $480 x 2 = $960. The answer is $960.
- Extract → Answer
- The extracted answer leaves in the expected format, with no reasoning around it.
Answer: 960
As-needed (ADaPT)
No upfront plan: the executor tries the task directly, and only a step that fails is handed to the planner to split into sub-steps, recursively.
All steps
Fails, splits, then succeeds
Succeeds directly
Parts of this pattern
- Task Input / output
- The whole task, tried directly first, such as 'Write a one-page brief on competitor Acme'.
- Executor Agent
- A tool-using agent that attempts the task or sub-step it is given and ends with SUCCESS or FAILURE.
- Tools Tool
- The tools the executor uses, such as web search and a page reader.
- Planner LLM call
- Called only when an attempt fails: splits that one task into smaller sub-steps, marked and or or.
- Sub-steps Memory
- The sub-steps for the failed task, run one at a time; each may itself be split if it fails.
- Result Input / output
- The finished brief, assembled from whichever attempts succeeded.
- Task → Executor
- The whole task goes straight to the executor, with no plan written first.
Write a one-page brief on competitor Acme: products, pricing and recent news.
- Executor → Tools
- A tool call the executor makes while attempting its task.
web_search(query="Acme pricing")
- Tools → Executor
- The tool's output returns to the executor.
No public pricing page found; Acme says 'contact sales'.
- Executor → PlannerFAILURE
- Only a failed attempt reaches the planner, together with the executor's reason.
FAILURE: Acme publishes no pricing, so the pricing section cannot be written.
- Planner → Sub-stepssub-steps
- The planner's sub-steps for the failed task are stored, with the and/or logic that combines them.
{"logic": "and", "sub_steps": ["Estimate Acme pricing from reseller listings", "Write the brief, marking pricing as estimated"]}
- Sub-steps → Executornext sub-step
- Each sub-step goes back to the same executor, one level deeper, and is split again only if it fails.
Estimate Acme pricing from reseller listings.
- Executor → ResultSUCCESS
- When the attempt that completes the task succeeds, its result is returned.
SUCCESS: Acme brief, one page; pricing estimated at $20 to $60 a seat from two resellers.
← → neighboursesc atlas
Plan-and-Execute
Also known as Plan-and-Solve · Planner-executor · Planning
A planner writes a step list, an executor runs each step, and a replanner revises the remaining steps.
With replanner: Popularized by LangChain team (2024) · LangChain
The LangChain post (2024-02-13) says its planner-executor-replanner agent is based loosely on Plan-and-Solve prompting (Lei Wang et al., 2023: see the Plan-and-Solve tab) and on Yohei Nakajima's BabyAGI.
Plan-and-Solve: Introduced by Wang et al. (2023) · Singapore Management University et al.
Plan-and-Solve prompting (ACL 2023): a zero-shot prompt that asks the model to devise a plan and then carry it out step by step, before an answer-extraction prompt reads off the result.
As-needed (ADaPT): Introduced by Prasad et al. (2023) · UNC Chapel Hill & Allen Institute for AI
ADaPT (NAACL 2024 Findings): As-needed Decomposition and Planning, which decomposes a task only when the executor cannot complete it.
Measured over one run
With replanner
- Nodes
- 7. Boxes in the diagram: models, tools, stores, people and plain code.
- LLM calls
- 4. Model invocations in the first scenario: each time a model or agent node starts thinking, plus each branch it decides.
- Tool calls
- 3. Messages sent to a tool node in the first scenario.
- Steps
- 5. Steps in the first scenario, with repeated steps counted every time they run.
- Scenarios
- 1. Distinct example runs you can switch between on the diagram.
- Loop
- yes. Whether the flow cycles back on itself until a condition is met.
- Parallel
- no. Whether two or more messages are in flight at the same time.
- Branch
- yes. Whether the flow takes one path out of several, chosen at run time.
- Human in the loop
- no. Whether a person appears as a node, to approve, correct or answer.
- Autonomy
- high. How much the model decides the control flow itself, from fixed code paths (low) to open-ended (high).
- Cost
- high. Relative token spend per request.
- Latency
- high. Relative wall-clock time per request.
Plan-and-Solve
- Nodes
- 5. Boxes in the diagram: models, tools, stores, people and plain code.
- LLM calls
- 3. Model invocations in the first scenario: each time a model or agent node starts thinking, plus each branch it decides.
- Tool calls
- 0. Messages sent to a tool node in the first scenario.
- Steps
- 4. Steps in the first scenario, with repeated steps counted every time they run.
- Scenarios
- 1. Distinct example runs you can switch between on the diagram.
- Loop
- no. Whether the flow cycles back on itself until a condition is met.
- Parallel
- no. Whether two or more messages are in flight at the same time.
- Branch
- no. Whether the flow takes one path out of several, chosen at run time.
- Human in the loop
- no. Whether a person appears as a node, to approve, correct or answer.
- Autonomy
- high. How much the model decides the control flow itself, from fixed code paths (low) to open-ended (high).
- Cost
- high. Relative token spend per request.
- Latency
- high. Relative wall-clock time per request.
As-needed (ADaPT)
- Nodes
- 6. Boxes in the diagram: models, tools, stores, people and plain code.
- LLM calls
- 3. Model invocations in the first scenario: each time a model or agent node starts thinking, plus each branch it decides.
- Tool calls
- 3. Messages sent to a tool node in the first scenario.
- Steps
- 6. Steps in the first scenario, with repeated steps counted every time they run.
- Scenarios
- 2. Distinct example runs you can switch between on the diagram.
- Loop
- yes. Whether the flow cycles back on itself until a condition is met.
- Parallel
- no. Whether two or more messages are in flight at the same time.
- Branch
- yes. Whether the flow takes one path out of several, chosen at run time.
- Human in the loop
- no. Whether a person appears as a node, to approve, correct or answer.
- Autonomy
- high. How much the model decides the control flow itself, from fixed code paths (low) to open-ended (high).
- Cost
- high. Relative token spend per request.
- Latency
- high. Relative wall-clock time per request.
Counted from the first scenario's timeline when the site is built.
Problem
A ReAct agent decides one step at a time, which makes long tasks wander. By step eight it may have forgotten the original structure of the job, or spent ten turns on a side issue. Every turn also calls the biggest model, even when the step is as simple as “fetch this page”. You want the foresight of a plan without losing the ability to adapt when the world disagrees with it.
How it works
The planner reads the goal once and writes a numbered list of steps, for example “find the competitor’s pricing page”, “summarize their positioning” and “compare against ours”. The list is stored as an explicit plan that your code, and you, can inspect.
The executor takes the next step and carries it out, usually as a small agent with tools of its own. It sees only the step, not the whole strategy, so it can be a cheaper model. Its result goes to the replanner, which is the distinctive part. The replanner looks at the goal, the remaining plan and what has been learned, then either rewrites the remaining steps or declares the work done and sends the answer.
The loop in the diagram is that revise edge. Without it, this would be a fixed pipeline. With it, a surprise in step one, such as the competitor having no public pricing, changes steps two and three before they run.
Two variants sit at either end of this design. Plan-and-Solve, the prompting technique the pattern grew from, drops the tools and the replanner: one model call writes a plan and works through it. As-needed decomposition (ADaPT) drops the upfront plan instead: the executor tries the whole task first, and the planner splits only the parts that fail.
When to use
- The task is long and multi-step, and the broad shape is predictable even if the details are not.
- You want a visible plan for debugging, approval or progress reporting.
- Steps are cheap and focused enough that a smaller model can execute them.
When to avoid
- The task is short. Planning overhead exceeds the savings.
- The next step is unknowable until you see results. ReAct fits that better.
- Steps depend on each other so tightly that every plan would be rewritten each turn.
Trade-offs
You pay for an extra model call after every step, but you gain a plan that is easy to read, log and interrupt. Strong models can plan and weaker, cheaper ones can execute. Replanning every time is the safest policy and the most expensive. Some systems replan only when a step fails.
Failure modes
- Over-planning: twelve steps for a three-step job. Ask for the fewest steps.
- Stale plan: results contradict the plan and nobody updates it. This is the job of the replanner, so do not skip it.
- Repeated work: the replanner re-adds a completed step. Show it the full history and say not to repeat steps.
- Executor drift: a step is too vague, and the executor wanders. Make steps self-contained.
Build it with your AI
With replanner
Paste this into Claude Code, Cursor, ChatGPT or any AI coding assistant.
Implement the Plan-and-Execute pattern in this codebase, using the LLM client and language we already use.
## Goal
Turn an open-ended goal into a written step list, run the steps one at a time with a tool-using executor, and revise the remaining steps after each result until the goal is answered.
## How it works
1. Call the planner model once with the Planner prompt, passing the goal and the tool names, and parse its numbered list into a plan: an ordered list of step strings.
2. Pop the first step and hand it, with the goal, to the executor: a small tool-using agent loop that sees only that step and returns a short result string.
3. Append the step and its result to past_steps, a list of (step, result) pairs.
4. Call the replanner model with the Replanner prompt, passing the goal, the remaining plan and all of past_steps, and parse its JSON reply.
5. If the reply has final_answer, return it. If it has remaining_steps, replace the plan with them and go back to the executor step.
## Prompts
### Planner prompt
```markdown
For the goal below, write a step-by-step plan. Each step must be a
self-contained task that one worker with {{tool_names}} can complete.
Use as few steps as possible. Do not add a step that only restates
the goal.
<goal>{{goal}}</goal>
Respond as a numbered list. The last step should produce the final answer.
```
### Replanner prompt
```markdown
Goal: {{goal}}
Current plan:
{{plan}}
Steps already completed, with results:
{{past_steps}}
Update the plan. Remove steps that are done or no longer needed, and
add or change steps if the results require it. Do not repeat a
completed step.
If you can already answer the goal, respond with:
{"final_answer": "..."}
Otherwise respond with:
{"remaining_steps": ["...", "..."]}
```
## Stop rule
Stop when the replanner returns final_answer, or after 10 executed steps. On the cap, return past_steps and the unfinished plan with a status saying the goal was not reached.
## Requirements
- Make the step cap (default 10), the plan length cap (default 7) and the executor's own tool-call cap per step (default 5) parameters.
- If the planner's list or the replanner's JSON cannot be parsed, or remaining_steps is empty with no final_answer, retry once with the error appended, then stop with a failed status. Truncate a plan over the cap, and log it.
- When a tool errors or the executor hits its cap, record the error text as that step's result so the replanner can route around it; do not abort the run.
- Let the planner, executor and replanner use separately configured models, so a cheaper model can execute the steps.
- Log the plan before and after every replan, next to the step result that caused the change.
- Add a test with a stub LLM whose planner returns 3 steps and whose replanner returns 1 remaining step, then a final_answer; assert the executor ran 2 steps and the final_answer is returned.
Plan-and-Solve
Paste this into Claude Code, Cursor, ChatGPT or any AI coding assistant.
Implement the Plan-and-Execute pattern (Plan-and-Solve variant) in this codebase, using the LLM client and language we already use.
## Goal
Answer a multi-step reasoning question by having one model call write a plan and carry it out in the same reply, then reading the final answer off that reasoning.
## How it works
1. Call the model with the Plan-and-Solve prompt, passing the question; the reply is reasoning text that states a plan and then works through each step.
2. Call the model again with the Answer extraction prompt, passing the question and that reasoning text, to get the bare final answer.
3. Validate the answer against the expected format (a number, a date, one option letter) and return it together with the reasoning.
## Prompts
### Plan-and-Solve prompt
```markdown
Q: {{question}}
A: Let's first understand the problem, extract the relevant variables
and their values, and devise a plan. Then, let's carry out the plan,
calculate the intermediate values (paying attention to calculation
and common sense), solve the problem step by step, and show the answer.
```
### Answer extraction prompt
```markdown
Q: {{question}}
{{reasoning}}
Therefore, the answer (a single {{answer_format}}) is:
```
## Stop rule
Stop after the extraction call; there is no loop. If the extracted answer fails format validation twice, return the reasoning text with a status saying no answer could be extracted.
## Requirements
- Use no tools: every fact the plan needs must be in the question, so route questions that need lookups to the tool-using pattern instead.
- Cap the reasoning reply length (default 1,000 tokens). If a reply is truncated, retry once; if it is truncated again, stop with a status saying the reasoning did not finish.
- If the extracted answer does not match the expected format, retry the extraction call once with the format error appended.
- Keep the reasoning text alongside the answer so a wrong answer can be traced to the step that went wrong.
- Add a test with a stub LLM that returns a two-step plan with a worked result, then '960' from extraction; assert exactly two model calls and that the answer is 960.
As-needed (ADaPT)
Paste this into Claude Code, Cursor, ChatGPT or any AI coding assistant.
Implement the Plan-and-Execute pattern (As-needed (ADaPT) variant) in this codebase, using the LLM client and language we already use.
## Goal
Complete a task by trying it directly with a tool-using executor, and decompose only the parts that fail into sub-steps, recursively, up to a depth limit.
## How it works
1. Hand the task to the executor with the Executor prompt; it works with its tools and must end by reporting success with a result, or failure with a reason.
2. If the executor reports success, return its result for this task.
3. If it reports failure and the depth limit is not reached, call the planner with the Decompose-on-failure prompt, passing the task and the failure reason, and parse its JSON into sub_steps plus a logic of and or or.
4. Run each sub-step through this same procedure, one level deeper. With and, stop at the first sub-step that fails; with or, stop at the first that succeeds.
5. Return the result upwards. For and, the parent's result is the list of sub-step results in order (the last is usually the deliverable); for or, it is the result of the sub-step that succeeded.
## Prompts
### Executor prompt
```markdown
Complete the task below using the tools. Work step by step.
<task>{{task}}</task>
<tools>{{tool_descriptions}}</tools>
When you finish, end with exactly one line:
SUCCESS: <the result>
or, if you cannot complete the task as a whole,
FAILURE: <what blocked you>
```
### Decompose-on-failure prompt
```markdown
An executor tried this task and could not complete it.
<task>{{task}}</task>
<failure>{{reason}}</failure>
Split the task into 2 to {{max_sub_steps}} smaller sub-steps that avoid
the blocker. Say whether all of them must succeed (and) or any one
is enough (or).
Respond in JSON:
{"logic": "and" | "or", "sub_steps": ["...", "..."]}
```
## Stop rule
Stop when the top-level task succeeds, or when a task fails at the depth limit (default 3). On failure, return the tree of attempted sub-steps with each one's result or reason.
## Requirements
- Make the depth limit (default 3), the sub-steps per decomposition (default 4) and the executor's tool calls per attempt (default 8) parameters.
- Require the executor to end with an explicit success or failure line; treat a missing or unparseable verdict as failure with the raw reply as the reason.
- If the planner's JSON cannot be parsed, retry once with the parse error appended, then report the task as failed.
- Pass a tool error to the executor as an observation; only the executor's final verdict decides whether a task failed.
- Add a test with a stub LLM whose executor fails the top task, then succeeds on both of 2 and-sub-steps; assert one planner call, three executor calls and a success result.
Prompt templates
With replanner
For the goal below, write a step-by-step plan. Each step must be aself-contained task that one worker with {{tool_names}} can complete.Use as few steps as possible. Do not add a step that only restatesthe goal.
<goal>{{goal}}</goal>
Respond as a numbered list. The last step should produce the final answer.Goal: {{goal}}
Current plan:{{plan}}
Steps already completed, with results:{{past_steps}}
Update the plan. Remove steps that are done or no longer needed, andadd or change steps if the results require it. Do not repeat acompleted step.
If you can already answer the goal, respond with:{"final_answer": "..."}Otherwise respond with:{"remaining_steps": ["...", "..."]}Plan-and-Solve
Q: {{question}}
A: Let's first understand the problem, extract the relevant variablesand their values, and devise a plan. Then, let's carry out the plan,calculate the intermediate values (paying attention to calculationand common sense), solve the problem step by step, and show the answer.Q: {{question}}
{{reasoning}}
Therefore, the answer (a single {{answer_format}}) is:As-needed (ADaPT)
Complete the task below using the tools. Work step by step.
<task>{{task}}</task><tools>{{tool_descriptions}}</tools>
When you finish, end with exactly one line:SUCCESS: <the result>or, if you cannot complete the task as a whole,FAILURE: <what blocked you>An executor tried this task and could not complete it.
<task>{{task}}</task><failure>{{reason}}</failure>
Split the task into 2 to {{max_sub_steps}} smaller sub-steps that avoidthe blocker. Say whether all of them must succeed (and) or any oneis enough (or).
Respond in JSON:{"logic": "and" | "or", "sub_steps": ["...", "..."]}Related patterns
Composes well with:
Sources
From the Agentic Atlas by Joran Kikke · Edit on GitHub · Suggest a correction