Phase 14 · Lesson 2 of 54

ReWOO and Plan-and-Execute: Decoupled Planning

ReAct interleaves thought and action in one stream. ReWOO separates them: one big plan up front, then execute. 5x fewer tokens, +4% accuracy on HotpotQA, and you can distill the planner into a 7B model. Plan-and-Execute generalized it; Plan-and-Act scaled it to web navigation.

Lesson 2 of 54Build~60 minutesPython (stdlib)

Before this: Lesson 1 of Phase 14 (Agent Loop)

On this page

Learning Objectives

  • Explain why ReWOO's Planner / Worker / Solver split saves tokens and improves robustness over ReAct's interleaved loop.
  • Implement a plan DAG, a dependency-ordered executor, and a solver that composes worker outputs — all stdlib.
  • Decide when a task should run as plan-then-execute vs interleaved ReAct, using the 2026 "five workflow patterns" framing (Anthropic).
  • Recognize when Plan-and-Act's synthetic plan data is needed for long-horizon web or mobile tasks.

The Problem

ReAct's interleaved thought-action-observation loop is simple and flexible, but each tool call has to carry the full prior context — including every previous thought. Token usage grows quadratically with depth. Worse: when a tool fails mid-loop, the model has to re-derive the whole plan from the error observation.

ReWOO (Xu et al., arXiv:2305.18323, May 2023) noticed this and made a bet: plan the whole thing up front, fetch evidence in parallel, compose the answer at the end. One LLM call to plan, N tool calls for evidence (can be parallel), one LLM call to solve. The trade is less flexibility (the plan is static) for much better token efficiency and clearer failure modes.

The Concept

The three roles

Planner:  user_question -> [plan_dag]
Workers:  [plan_dag]     -> [evidence]        (tool calls, possibly parallel)
Solver:   user_question, plan_dag, evidence -> final_answer

Planner produces a DAG. Each node names a tool, its arguments, and which earlier nodes it depends on (references like #E1, #E2). Workers execute nodes in topological order. Solver stitches everything together.

Why 5x fewer tokens

ReAct grows prompt length linearly with step count. At step 10, the prompt contains thought 1 plus action 1 plus observation 1 plus thought 2 plus action 2 plus observation 2, and so on. Each intermediate step also redundantly includes the original prompt.

ReWOO pays one planner prompt (large), N small worker prompts (each just the tool call, no chain), and one solver prompt. On HotpotQA the paper measures ~5x fewer tokens while scoring +4 absolute accuracy.

Why it is more robust

If worker 3 fails in ReAct, the loop has to reason out of the error mid-stream. In ReWOO, worker 3 returns an error string; the solver sees it in context with the original plan and can degrade gracefully. Failure localization is per-node, not per-step.

Planner distillation

The paper's second result: because the planner does not see observations, you can fine-tune a 7B model on planner outputs from a 175B teacher. The small model handles planning; the big model is not needed at inference. This is now standard — many 2026 production agents use a small planner and a big executor or vice-versa.

Plan-and-Execute (2023)

The LangChain team's August 2023 post generalized ReWOO into a pattern name: Plan-and-Execute. Up-front planner emits a step list, executor runs each step, an optional replanner can revise after observing results. This is closer to ReAct than ReWOO (the replanner brings observations back into planning) but preserves the token savings.

Plan-and-Act (Erdogan et al., arXiv:2503.09572, ICML 2025)

Plan-and-Act scales the pattern to long-horizon web and mobile agents. The key contribution is synthetic plan data: a labeled trajectory generator produces training data where the plan is explicit. Used to fine-tune planner models that keep working past 30–50 steps on WebArena-like tasks where a single ReAct trajectory loses coherence.

When to pick which

Pattern When
ReAct Short tasks, unknown environment, need reactive exception handling
ReWOO Structured tasks with known tools, token-sensitive, parallelizable evidence
Plan-and-Execute Like ReWOO but with replanning after partial execution
Plan-and-Act Long-horizon (>30 steps), web/mobile/computer-use
Tree of Thoughts Search is worth paying for (Lesson 04)

Anthropic's Dec 2024 guidance: start with the simplest. If the task is one tool call plus a summary, do not build ReWOO. If the task is a 40-step research assignment, do not do ReAct alone.

rewoo-plan

Build It

code/main.py implements a toy ReWOO:

  • Planner — a scripted policy that emits a plan DAG from a prompt.
  • Worker — dispatches each node's tool call via the registry.
  • Solver — scripted composition that reads evidence and produces a final answer.
  • Dependency resolution — references like #E1 are substituted with earlier worker outputs.

The demo answers "What is the population of the capital of France, rounded to millions?" using a two-step plan: (1) look up the capital, (2) look up the population, then solve.

Run it:

python3 code/main.py

The trace shows the full plan first, then worker results, then solver composition. Compare the token count (we print a rough character count) to a ReAct-style interleaved run — ReWOO wins on this kind of structured task.

Use It

LangGraph ships Plan-and-Execute as a recipe (create_react_agent for ReAct, custom graphs for plan-execute). CrewAI's Flows encode the pattern directly: you define tasks up front and the Flow DAG executes them. Plan-and-Act's synthetic data approach is still mostly research; the runtime pattern (explicit plan DAG) ships in production through LangGraph and CrewAI Flows.

Ship It

outputs/skill-rewoo-planner.md generates a ReWOO plan DAG from a user request, given a tool catalog. It validates the plan (acyclic, every reference resolved, every tool exists) before handing off to an executor.

Exercises

  1. Parallelize worker execution for independent plan nodes. What does it buy you on a 6-node DAG with 2 parallel groups?
  2. Add a replanner node that fires if any worker returns an error. What is the smallest change to ReWOO that makes it Plan-and-Execute?
  3. Replace Planner with a small model (7B class) and keep Solver on a frontier model. Compare end-to-end quality — where does the split fail?
  4. Read Section 4 of the ReWOO paper on planner distillation. Reproduce the 175B -> 7B result conceptually: what training data do you need, and how do you score plan quality?
  5. Port the toy to Plan-and-Act's trajectory shape: plan is a sequence, not a DAG. What tradeoffs change?

Key Terms

Term What people say What it actually means
ReWOO "Reasoning without observations" Plan, then fetch evidence in parallel, then solve — no observations in the planning prompt
Plan-and-Execute "LangChain's plan-execute pattern" ReWOO with an optional replanner node after execution
Plan-and-Act "Scaled plan-execute" Explicit planner/executor split with synthetic plan training data for long-horizon tasks
Evidence reference "#E1, #E2, ..." Plan-node placeholder substituted with prior worker output at dispatch time
Planner distillation "Small planner, big executor" Fine-tune a small model on planner traces from a large teacher
Token efficiency "Fewer round trips" 5x fewer tokens on HotpotQA vs ReAct in the paper
DAG executor "Topological dispatcher" Runs plan nodes in dependency order; parallel at each level

Further Reading

Check yourself

Quick quiz

  1. Why does ReAct's prompt grow quadratically with depth?

    1. Each step carries the full prior context including every previous thought and observation
    2. The model re-tokenizes itself on every step
    3. Tool schemas are duplicated per call
    4. The provider charges per byte rather than per token
    Show the answer

    A. Each step carries the full prior context including every previous thought and observation ReAct re-includes prior thoughts and observations on each step, making total prompt length grow with the square of the depth.

  2. What is the three-role split that defines ReWOO?

    1. Planner, Workers, Solver
    2. Reader, Writer, Reviewer
    3. Generator, Critic, Optimizer
    4. Actor, Evaluator, Reflector
    Show the answer

    A. Planner, Workers, Solver ReWOO separates a Planner that emits a DAG, Workers that fetch evidence, and a Solver that composes the final answer.

  3. What headline numbers does the paper report for ReWOO vs ReAct on HotpotQA?

    1. 10x fewer tokens and -2 accuracy
    2. ~5x fewer tokens and +4 absolute accuracy
    3. Same tokens and +1 accuracy
    4. ~2x more tokens and +10 accuracy
    Show the answer

    B. ~5x fewer tokens and +4 absolute accuracy ReWOO reports about a 5x token reduction and +4 absolute accuracy on HotpotQA compared to ReAct.

  4. What does a placeholder like #E1 inside a ReWOO plan node mean?

    1. A reference substituted at dispatch time with the output of an earlier worker node
    2. A planner version identifier
    3. An error code returned by worker 1
    4. A retry counter for evidence fetching
    Show the answer

    A. A reference substituted at dispatch time with the output of an earlier worker node Plan nodes use evidence references like #E1, #E2 that the executor substitutes with the output of upstream workers.

  5. Why does ReWOO localize failures better than ReAct?

    1. The Planner re-emits a fresh DAG after every error
    2. Workers crash the run on any error
    3. ReWOO retries every failed call up to ten times
    4. An error in a worker becomes a string the Solver sees alongside the original plan, so degradation is per-node not per-step
    Show the answer

    D. An error in a worker becomes a string the Solver sees alongside the original plan, so degradation is per-node not per-step Per-node failure with the original plan in context lets the Solver degrade gracefully rather than reasoning mid-stream out of an error.

  6. Which task shape best fits Plan-and-Act over plain ReWOO?

    1. A pure arithmetic question
    2. A 40-step web or mobile navigation trajectory
    3. A two-step factoid lookup
    4. A single-turn classification
    Show the answer

    B. A 40-step web or mobile navigation trajectory Plan-and-Act is built for long-horizon (over 30 steps) web and mobile agents where a single ReAct trajectory loses coherence.

  7. What does ReWOO's planner distillation result imply for production agents?

    1. Frontier models must be used at every step
    2. A small planner (around 7B) can match a large teacher because the planner never sees observations
    3. Planning quality drops below 7B parameters
    4. Distillation requires gradient-based RL data
    Show the answer

    B. A small planner (around 7B) can match a large teacher because the planner never sees observations Because the planner does not see observations, plan traces from a large teacher transfer cleanly to a small fine-tuned planner.

Questions people ask

When should an AI agent plan everything before it acts?

Plan first when the steps are fairly predictable and the tools behave reliably, such as gathering data from known sources. Step-by-step agents fit better when each result changes what to do next, like troubleshooting or browsing an unfamiliar site.

Does plan-and-execute make AI agents cheaper to run?

Often, yes. The big planning call happens once, and the execution steps can use tools directly or a smaller model. You avoid sending the whole growing conversation back to the model after every single tool call.

Next lessonReflexion: Verbal Reinforcement LearningPrevious: The Agent Loop: Observe, Think, Act

Lessons from AI Engineering from Scratch by Rohit Ghumare and contributors, MIT license. Notes for owners by Lozo. License

Next step

Rather have it built for you?

Reading is optional. Tell me what's stuck and I'll build it into the business you already run.

  • A real conversation, not a pitch
  • You keep your accounts
  • Nothing sends without your yes