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:

A ReAct agent answers the car-maker request with seven sequential big-model calls whose context grows each time, and the final table forgets one maker and uses the wrong base year. User request 3 makers, 2 years each call re-sends every earlier search result 1 2 3 4 5 6 7 big-model calls, one after another Final table third maker missing wrong base year
Each bar is one call to the frontier model, and its height is the context it carries. Cost grows with every step, and the request's details end up buried under search results.

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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").
  5. 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

The objective goes to a planner that writes a plan; a scheduler runs ready steps on parallel executors; their results go to a replanner, which either answers or sends a revised plan with only the remaining steps back to the plan. revised plan: remaining steps only respond Objective Planner strong model Plan a. find the 3 makers b–d. revenues (after a) e. growth, f. table Scheduler code, no LLM Executor maker 1 Executor maker 2 Executor maker 3 Step results by id Replanner answer or new plan Answer 1 2 3 4 5 6
Solid arrows carry instructions, dashed arrows carry results. Steps b, c and d run in parallel once step a is done. The accent arrow is the closed loop; the plan-once variant (ReWOO) removes it and replaces the replanner with a solver that always answers.
  1. 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.
  2. 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.
  3. Scheduler. Plain code. Picks every step whose dependencies are done, replaces references such as $1 or #E1 with the real outputs, and dispatches. LLMCompiler calls this the task fetching unit.
  4. 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.
  5. Step results. Stored by step id, errors included as values ("failed: no 2023 figure found") so one failure does not crash the run.
  6. 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.

Executor tools one row per tool, fewer plan better
Plan format
When to replan

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.

Where the quality comes from

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

Avoid it when

How to implement

  1. 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.
  2. Choose the plan format. A plain ordered list is easiest to produce and read. Use a graph with explicit dependencies and $id references 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.md file as it works so the objective stays in recent attention.
  8. 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 support (check current docs before use)
FrameworkHow this pattern appears
LangGraphTutorial 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 deepagentsTodoListMiddleware adds a write_todos tool with pending, in-progress and completed statuses.
CrewAICrew(planning=True) runs a planner before the tasks; agent-level PlanningConfig exposes fields such as max_replans and observe_steps.
Google ADKLlmAgent(planner=...) with BuiltInPlanner (native thinking) or PlanReActPlanner, which makes the model write tagged planning, action and replanning sections.
smolagentsplanning_interval=N on CodeAgent or ToolCallingAgent inserts a planning step every N steps.
LlamaIndexStructuredPlannerAgent wraps another agent and splits the input into sub-tasks with expected outputs and dependencies.
AutoGenMagenticOneGroupChat: an orchestrator with a task ledger and a progress ledger that replans on stall.
Semantic KernelIts Stepwise and Handlebars planners are deprecated and removed; the docs recommend automatic function calling instead.
Claude Code, CursorPlan 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_replans cap, 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

Further reading