Plan-and-Execute
Also known as: planner–executor, plan-then-act, task decomposition, explicit planning. Named designs: ReWOO, LLMCompiler, HuggingGPT, BabyAGI, plan mode in coding agents.
Intent
Ask a strong model to write the whole sequence of steps first, as a list or a graph that the system stores. Run the steps with cheaper machinery (tool calls, a small model, plain code), then call a strong model again only to check the results and either answer or write a revised plan for what is left.
Problem
You are building a research assistant on top of web search. A user asks: "For each of the three largest EU car makers, find 2024 and 2023 revenue, compute growth, and give me a ranked table with sources."
A plain ReAct loop on a frontier model handles this one action at a time: search maker 1, read, search maker 1 again for 2023, read, and so on. That is roughly 7 to 10 big-model calls for this request, run strictly one after another. Where it breaks:
- One big-model call per tool result. Every step re-sends the growing transcript, full of raw search output, to the most expensive model. Cost and latency grow with the number of steps.
- Short-sighted decisions. The model reasons about the next sub-problem only, so the path wanders and repeats searches. The LangChain planning-agents post and the planning survey by Huang et al. both point this out.
- Goal drift. After many steps the original request sits far back in the context. The agent forgets the third maker, or computes growth from the wrong year. Manus reports about 50 tool calls for a typical task and says loops that long drift from their goals.
Solution
Split the agent into a planner that decides the steps once, an executor that carries them out, and a replanner that looks at the results. The plan is an explicit artifact (a JSON list, a graph of tool calls, a file) that code can read, validate, schedule and show to a person.
- Plan. One call to the strongest model gets the request and the tool list, and returns: (a) find the three largest EU car makers; (b, c, d) for each maker, find 2024 and 2023 revenue with a source; (e) compute growth; (f) rank and format. Steps b to d depend on a, and not on each other.
- Validate. Plain code checks that the plan parses, uses only known tools, has no cycles and stays under the step budget. In an interactive product a person can review or edit it here.
- Execute. A scheduler runs a, then dispatches b, c and d at the same time. Each executor (a search tool plus a small model) sees only its own sub-question and the output of step a, not the full history.
- Replan or answer. A strong model reads the request, the plan and the compact results. If all six figures are there, it writes the ranked table. If maker 2's 2023 figure is missing, it returns a new plan with only that step ("search maker 2's 2023 annual report").
- Stop. The run ends when the replanner answers, when a budget on steps or replans is reached, or when the plan is empty.
The task now takes two or three big-model calls instead of about ten, the "three makers" requirement is pinned in a step list instead of buried in a transcript, and you can read the plan before anything runs.
Who decides the flow: the planner model, up front. That is the difference from ReAct, where the model decides after every observation, and from prompt chaining, where the developer fixes the steps at design time. A plan-and-execute plan is a chain that the model writes at run time. Scheduler code enforces the order, and the replanner gets control back only at points you choose.
Real-world analogy
A head chef writes the morning prep list before service: dice two kilos of onions, make the stock, portion the fish. Each cook takes one line and does it without reading the menu. Lines that do not depend on each other get done at the same time. Before service the chef walks the stations, checks the results, and rewrites the list for whatever is missing. The chef is the planner and the replanner, the prep list is the plan, and the cooks are the executors.
The analogy stops at attention. A real chef notices at nine in the morning that the fish delivery did not come. The system only looks at results at the replan points you defined, so a failed step can go unnoticed until then, and in the plan-once variant it is never noticed at all.
Structure
- Planner. Usually the strongest model. Gets the objective, one-line tool descriptions and the budgets, and returns a plan in a strict format (JSON schema or a line grammar), ideally after two or three worked examples of good plans.
- Plan and state. The current plan, the completed steps and their outputs, kept outside the prompt (graph state, a JSON file, a to-do store) so it survives long runs and restarts. A validator in plain code rejects unknown tools, bad arguments, cycles and plans over budget before anything runs. A human approval gate, if you have one, sits here.
- Scheduler. Plain code. Picks every step whose dependencies are done, replaces references such as
$1or#E1with the real outputs, and dispatches. LLMCompiler calls this the task fetching unit. - Executors. Run one step and return a compact result. An executor can be a tool call, a small model, or a ReAct sub-agent with a few tools. If it becomes a full agent with its own context window, you are closer to Orchestrator–Workers.
- Step results. Stored by step id, errors included as values ("failed: no 2023 figure found") so one failure does not crash the run.
- Replanner. Also called joiner (LLMCompiler) or solver (ReWOO). Reads the objective, the plan and the results, and returns either a final answer or a new plan containing only the steps still needed. Counters for replans, steps and time stop it from looping.
Prompt generator
Describe the requests your agent handles, the tools the executor can call and the limits. The generator writes three prompts (planner, executor, and replanner or solver) plus the checks your runtime code should do. Paste them into the three nodes of a LangGraph plan-and-execute graph, or into your own loop around any chat API with structured output.
Generated prompt
Highlighted text comes from the form. [Bracketed] text is still to fill in. Text in {braces} is filled in by your runtime on each call.
Most failures are not in the plan. In LLMCompiler's failure analysis on its ParallelQA benchmark, 64% of failures came from executors, 28% from the final answer and only 8% from the planner. Spend effort on executor prompts, tool descriptions and the replanner's "only the remaining steps" rule before polishing the planner.
Applicability
Use it when
- The task needs several tool calls and you can guess its shape from the request. Multi-hop questions, research reports, gather-then-compute jobs and multi-file code changes all fit.
- Many steps are independent. Running them in parallel is where most of LLMCompiler's latency gains come from.
- Big-model cost or latency matters. Steps can go to cheaper models or plain code, and only planning and replanning need the strong model.
- Someone must see or approve what will happen before side effects. A written plan is easy to review before a deployment, an email or a codebase edit.
- Runs are long and the agent drifts. A stored plan works as an anchor for the original request.
- You want to limit what a prompt injection can do. If the plan comes only from the trusted request, untrusted text read later cannot add new tool calls.
Avoid it when
- The next step really depends on the last observation. Web navigation, debugging an unknown failure and games suit ReAct better. The MobilityBench study found ReAct generally more successful than static plan-and-execute under dynamic feedback.
- The task takes one to three tool calls. The planning call is pure overhead. Use ReAct, or route simple requests away from the planner.
- The steps are always the same. Hard-code them as a prompt chain.
- Each subtask needs its own agent and context window. Use Orchestrator–Workers or a Supervisor, possibly with a planning lead.
- Your model is strong at long tool use and the task is moderate. A plain tool loop may already plan well enough on its own. Semantic Kernel replacing its planners with function calling, and Claude Code no longer enabling to-do tools by default on newer models, point this way. That reading is an interpretation of those two decisions, not a measured result.
How to implement
- List the tools. Write a one-line description per tool that a planner can choose from. Keep the list short: ReWOO's authors saw accuracy fall as tools were added, mostly through tool misuse.
- Choose the plan format. A plain ordered list is easiest to produce and read. Use a graph with explicit dependencies and
$idreferences when you need to pass values between steps or run steps in parallel. Use JSON with a schema and the model's structured-output mode for anything code will parse. - Write the planner prompt. State the format, the rules (one tool per step, self-contained steps, final step produces what the answer needs, a step cap) and two or three worked examples. smolagents first asks the planner for a facts survey (given, to look up, to derive), which makes it notice what it does not know.
- Write the executor. Start with one generic ReAct sub-agent that has all the tools, as the LangGraph tutorial does. Specialise by step type later if cost matters.
- Write the replanner prompt. Give it an either/or structured output: a response, or a plan with only the steps still needed. The "only the remaining steps" line is the key instruction in the LangGraph replanner.
- Add budgets and stop conditions. Cap replans, steps, tokens and wall-clock time. Treat an empty plan without an answer as a failure. The LangGraph tutorial runs with
recursion_limit=50; Magentic-One rewrites its plan once its count of steps without progress passes 2. - Persist the plan outside the prompt for long tasks, and re-inject the current plan near the end of the context on each turn. Manus rewrites a
todo.mdfile as it works so the objective stays in recent attention. - Compare with a ReAct baseline on the same tasks, model and tools: success rate, total tokens, number of big-model calls, latency and cost. The pattern is only worth it if it wins on your tasks.
| Framework | How this pattern appears |
|---|---|
| LangGraph | Tutorial graphs for plan-and-execute (nodes planner, agent, replan, executor built with create_react_agent), ReWOO and LLMCompiler. The old docs URL now redirects to the to-do-list middleware page; the notebook lives in the LangGraph repository. |
| LangChain deepagents | TodoListMiddleware adds a write_todos tool with pending, in-progress and completed statuses. |
| CrewAI | Crew(planning=True) runs a planner before the tasks; agent-level PlanningConfig exposes fields such as max_replans and observe_steps. |
| Google ADK | LlmAgent(planner=...) with BuiltInPlanner (native thinking) or PlanReActPlanner, which makes the model write tagged planning, action and replanning sections. |
| smolagents | planning_interval=N on CodeAgent or ToolCallingAgent inserts a planning step every N steps. |
| LlamaIndex | StructuredPlannerAgent wraps another agent and splits the input into sub-tasks with expected outputs and dependencies. |
| AutoGen | MagenticOneGroupChat: an orchestrator with a task ledger and a progress ledger that replans on stall. |
| Semantic Kernel | Its Stepwise and Handlebars planners are deprecated and removed; the docs recommend automatic function calling instead. |
| Claude Code, Cursor | Plan mode: read-only research and an editable plan that the user approves before any edit. Claude Code's task tools keep a living to-do list during execution. |
Caveat. These APIs move fast and were read from docs in November 2026. The CrewAI PlanningConfig field list and deepagents making its to-do middleware opt-in in v0.7 are not verified. Since Claude Code v2.1.268 the task tools are on by default only for older models; Anthropic's docs say newer models track multi-step work without a written list.
Variants
Plan once, no replanning (ReWOO)
The planner writes every step before any tool runs, with evidence variables (#E1 = Search[...], #E2 = LLM[extract X from #E1]). Workers fill in the evidence and a solver writes the answer. No observation ever reaches the planner. On HotpotQA with gpt-3.5-turbo, the ReWOO paper reports 9,795 tokens per query for ReAct against 1,986 for ReWOO, and accuracy of 40.8 against 42.4. It is the cheapest variant and cannot recover from a bad plan.
Plan, execute, replan
The closed loop shown in the diagram, as in the LangGraph tutorial and BabyAGI's task-list loop. To reduce cost, call the replanner only when a step fails, when the plan is empty, or every N steps. In Plan-and-Act's ablation on WebArena-Lite, adding dynamic replanning raised success from about 43.6% to 53.9%, the largest single step; its authors also note that replanning after every action is slow.
DAG with parallel execution (LLMCompiler)
The plan is a graph of function calls with $k references, streamed so that execution starts before planning ends. A task fetching unit runs ready steps in parallel and a joiner decides to answer or replan. The paper reports up to 3.7x lower latency and 6.7x lower cost than ReAct; both are best cases on its Movie Recommendation benchmark, and the HotpotQA gains are smaller (1.80x and 3.37x). HuggingGPT uses a similar typed task list with dependency ids to chain models.
Plan inside a ReAct loop
The agent stays a ReAct agent but keeps a plan: smolagents refreshes it every N steps, Google ADK's PlanReActPlanner has a replanning tag, and Claude Code, deepagents and Manus keep a to-do list the agent rewrites as it learns. The plan is a memory aid and a progress display rather than a program. This is a good default when the environment is unpredictable.
Plan, then approve (plan mode)
A read-only research and planning phase, then a person approves or edits the plan, then execution. Claude Code, Cursor and ChatGPT deep research work this way. Cursor recommends reverting and refining the plan instead of patching a bad build with follow-up prompts. The gate itself is covered in Human-in-the-Loop.
Plan-then-execute for security
Fix the allowed tool calls from the trusted user request before the agent reads any untrusted data (Beurer-Kellner et al., 2025). An injected instruction in a web page or email cannot add a new tool call. It can still change the arguments of a planned call, for example the body of an email the plan was going to send.
Long-horizon plan file
In Anthropic's long-running coding harness, an initializer session expands a spec into a JSON list of more than 200 features, each with test steps and a passes: false flag. Each later session takes one failing feature, works on it, and may only flip its flag. Anthropic chose JSON because models were less likely to rewrite it inappropriately than a Markdown list.
Plan-and-Solve prompting
No tools and no executor: one prompt tells the model to make a plan and then carry it out. With text-davinci-003 the paper reports the zero-shot arithmetic average going from 70.4% (chain of thought) to 76.7% (PS+). Useful as a cheap first step, but it is a prompting technique, not an architecture.
Search-based planning (Tree of Thoughts, LATS) and pairing the model with a classical planner or verifier (LLM+P, LLM-Modulo) also go by "planning", but they search over candidate plans and cost much more. They are outside the scope of this page.
Pros and cons
Pros
- Fewer calls to the expensive model, and small focused contexts for each step. ReWOO reports about 5x fewer tokens than ReAct on HotpotQA.
- Independent steps run in parallel, which cuts wall-clock time.
- The plan is an artifact you can log, show to users, edit and approve.
- Failures can be attributed to the planner, an executor or the replanner, which tells you where to improve.
- The written plan keeps the full request in view on long runs.
- A plan made from trusted input limits which tools an injection can trigger.
Cons
- A plan made before any observation can be wrong. Plan-once variants cannot recover; replanning recovers at the cost of more calls.
- Planning and joining are serial overhead. On WebShop, LLMCompiler took 10.48 s against 5.98 s for ReAct with gpt-3.5-turbo, though its success rate was much higher (48.2% against 19.8%).
- More moving parts: plan schema, validator, scheduler, variable substitution, replanner prompt.
- Less flexible than ReAct in exploratory or reactive settings.
- Most published gains were measured on 2023-era models such as gpt-3.5-turbo, with no replication on current frontier models in the sources; treat them as directional.
Failure modes
- Wrong plan from wrong assumptions
-
The planner assumes a fact will be in the search results, or picks the wrong decomposition. ReWOO's authors saw this. Every later step faithfully executes a plan that cannot work.
Mitigation: a facts survey before planning, a clarification step, replanning on failure, and executors that can report "assumption false" explicitly.
- Brittle open-loop execution
-
Step 2 fails, steps 3 to 6 run on garbage, and the solver answers confidently anyway.
Mitigation: store errors as values and check them, skip steps whose dependencies failed, and put a replanner or joiner before the final answer.
- Replanning thrash
-
The replanner keeps rewriting similar plans, or a weak executor triggers replans over and over. Plans grow instead of shrinking.
Mitigation: a
max_replanscap, a stall counter as in Magentic-One, a graph recursion limit, a required reason for every change, or a stronger executor. - Redoing finished work
-
The new plan repeats steps that already succeeded, doubling cost.
Mitigation: tell the replanner to return only the remaining steps, and deduplicate against completed steps in code.
- Premature "done"
-
The agent marks items complete without checking them, or declares the whole task finished early.
Mitigation: give each plan item a test, and let only a verifier flip it to done, as in Anthropic's long-running harness. See Evaluator–Optimizer.
- Over-planning
-
A ten-step plan for a two-step task, where planner latency dominates.
Mitigation: route simple requests to a direct answer or a ReAct loop, and add effort-scaling rules to the planner prompt, as Anthropic's research system does.
- Malformed plans
-
Unknown tools, invalid JSON, cycles, references to step ids that do not exist.
Mitigation: structured outputs with a schema, a cycle check, and feeding the validation error back to the planner once or twice.
- Injection through tool output
-
A fetched page tells the replanner to add a "send email" step.
Mitigation: plan from trusted input only and freeze the allowed tools, keep untrusted text inside executors, and remember that arguments can still be poisoned.
- Parallel stragglers
-
One slow call holds up the join. LLMCompiler notes its slowest search took about twice the average (1.13 s against 0.61 s).
Mitigation: a timeout per step and partial joins that answer with what arrived.
Relations with other patterns
- ReAct (tool-use loop): the main alternative. ReAct decides after every observation; Plan-and-Execute decides most steps up front. Hybrids sit between them: periodic replanning, to-do lists inside a ReAct loop, ReAct sub-agents as executors.
- Orchestrator–Workers: the orchestrator also decomposes the task, but hands subtasks to separate agents with their own context windows. Here steps are usually single calls. The two are often combined as a planning orchestrator.
- Prompt Chaining: the developer fixes the steps at design time. A plan here is a chain generated by the model at run time.
- Parallelization: DAG variants fan out independent steps and join them, but the planner chooses the fan-out, not the developer.
- Evaluator–Optimizer: the replanner is a form of evaluation, and verifiers that mark plan items done belong there.
- Supervisor: a supervisor may plan, but it decides one delegation at a time instead of executing a stored plan.
- Hierarchical teams: plans can be decomposed level by level, each manager planning only its own slice.
- Group Chat: Magentic-One adds a task ledger and progress tracking on top of a group chat.
- Blackboard: a persisted plan file or task ledger is a small shared workspace that several components read and update.
- Human-in-the-Loop: plan approval and plan editing are the most common human checkpoints.
- Routing: send trivial requests away from the planner to avoid over-planning.
Further reading
- Plan-and-Execute Agents (LangChain, 2024): the three styles side by side (plan-and-execute, ReWOO, LLMCompiler) and the drawbacks of each.
- LangGraph plan-and-execute tutorial (LangChain): a small working graph with planner, executor and replanner prompts.
- ReWOO: Decoupling Reasoning from Observations (Xu et al., 2023): the plan-once design with evidence variables, token measurements and a tool-failure test.
- An LLM Compiler for Parallel Function Calling (Kim et al., ICML 2024): DAG plans, parallel dispatch, the joiner, and a breakdown of where failures come from.
- Plan-and-Act (Erdogan et al., ICML 2025): trained planner and executor models, with an ablation showing what replanning adds.
- Design Patterns for Securing LLM Agents against Prompt Injections (Beurer-Kellner et al., 2025): plan-then-execute as a security pattern, and what it leaves unprotected.