Planning patterns: direct, plan-then-execute and reason-act

Study time
≈ 2 h (estimate)
Needs
L3-M01-L02
Updated
2026-11-04

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L3-M01 · Duration: ~120 min (estimate, including the independent exercise) · Previous: L02 · Next: L04

1. Introduction

Two agents with the same tools and the same task can differ in how they use tool results: one agent writes a plan first and then runs all of it; another interleaves thought, action and observation, and decides the next step after each result. This lesson reads the origins of the two patterns (the ReAct paper by Yao et al., and the Plan-and-Solve paper), builds three patterns with simulated policies and compares them on the same nine tasks with the same limits.

Professional goal: compare two patterns without being fooled by the numbers. A warning up front: in the lab, the differences between the patterns come from how the simulated policies were written; the numbers describe that simulation, not evidence about any real model or pattern. The lesson gives you a comparison method and lints, not a ranking.

2. Learning objectives

  1. Describe ReAct as in the original paper: thought, action, observation, and what a thought does not do. Read: §4.1.
  2. Tell apart the three patterns direct, plan_execute and react by how each uses observations. Read: §4.3; practice: §8.2 part D.
  3. Lint a plan (unknown tool, forward reference, repeated step). Practice: §8.2 part A, §8.3 (lines 1 and 2), §9 (TODO 1).
  4. Compare two patterns on the same tasks, the same seed and the same limits, and read the result within its limits. Practice: §8.2 parts B and C, §8.3 (lines 3 to 8), §9 (TODO 2).
  5. Explain why 180 runs are not 180 independent pieces of evidence. Practice: §8.3 (line 9); read: §5.3.
  6. State why the lab's numbers say nothing about real models. Read: §6.2.

3. Prerequisites and tools

  • L01 (simulated policies, tasks, the end-state oracle), L02 (the loop, the guard), L2-M07-L02 (paired comparison, to see why this lesson does not build a confidence interval). The lab code is code-labs/l3-m01.
  • Separating the senses. A plan is the list of tool steps the agent writes out; it differs from the "comparison plan" of L2-M07. A pattern is a way of organizing the loop (not the "sample" in sample size and sampling in Level 2): direct (one model call, no tools), plan_execute, react. A thought is the model's reasoning text; it does not change the environment. The success rate in the lab is the share of runs where the end-state oracle (L01) says pass; it is the same division as the "pass rate" of Level 2, but here runs are deterministic. A seed is a string used to draw pseudo-random numbers with SHA-256.

4. Concept explanation

4.1 ReAct as in the original paper

The ReAct paper (Yao et al., arXiv v3, 3/2023, month/year) extends the agent's action space with the space of language: an action in the language space, called a thought or reasoning trace, "does not affect the external environment, thus leading to no observation feedback" [R1]. A trajectory solving a task consists of many thought-action-observation steps; for tasks that need many actions, thoughts can be sparser and the model decides for itself when to think [R1]. The authors tried it on question answering (HotpotQA), fact verification (FEVER, through a simple Wikipedia API) and two interactive benchmarks (ALFWorld, WebShop) [R1].

Their main setup is a frozen model (PaLM-540B) prompted with one to six in-context examples [R1]. The abstract reports that ReAct beats imitation and reinforcement learning methods by 34% and 10% (absolute, success rate) on ALFWorld and WebShop [R1]. These are results of those setups; this lesson does not use them to say which pattern is better for your product. The paper's error analysis also has parts unfavorable to ReAct: the thought-action-observation structure reduces flexibility in reasoning and gives a higher rate of reasoning errors than chain-of-thought; search that returns no information accounts for 23% of the failure cases; and there is a failure pattern of repeating earlier thoughts and actions (L02) [R1].

4.2 Plan-then-execute

The Plan-and-Solve paper (PS prompting) proposes two components: first make a plan that divides the task into subtasks, then carry out each subtask according to the plan; its goal is to reduce the missing-step errors of zero-shot chain-of-thought [R2]. We read only the abstract of this paper. It is a technique for prompting a model to reason more accurately, not an agent design with tools, so here it is used only as the source of the idea "plan first, execute after", and its results are not used. The "Building effective agents" article describes orchestrator-workers, where a central model splits the task at run time and hands it to workers [R3].

4.3 Three patterns in the lab

lab/policies.py has three simulated policies, differing in how they use observations:

  • direct: one model call, no tools. "Computing in its head" is right only when the result has an absolute value below 100; it never refuses; it cannot write a notebook.
  • plan_execute: the first call writes the whole plan; later calls run the plan in order and do not re-plan; any tool error ends with CANNOT_ANSWER.
  • react: each call consists of a thought and an action, reading the latest observation; it retries transient errors and broken JSON (at most twice per intent), follows a "did you mean" hint once, and stops with CANNOT_ANSWER on any other error.

The last two traits (plan_execute does not re-plan, react knows how to retry) are the lab author's design choice, so that tasks with transient errors and wrong lookup keys can separate the two patterns. A real plan_execute may re-plan, and a real ReAct may not know how to retry; the lab does not say otherwise.

5. Technical deep dive

5.1 A plan is data, so it can be linted

A plan is a list of {tool, arguments}, where arguments is JSON text and may contain a placeholder {tool_name} that takes the latest result of that tool. lint_plan returns these codes: NOT_A_LIST, EMPTY_PLAN, TOO_LONG (more than 6 steps), BAD_STEP:i (not exactly two keys), UNKNOWN_TOOL:i, BAD_JSON:i or BAD_ARGUMENTS:i (the arguments are rejected by the tool's schema, after substituting placeholders), UNKNOWN_PLACEHOLDER:i, FORWARD_REF:i (using {calc} when no earlier step has called calc) and DUPLICATE_STEP:i (the same tool with the same arguments as an earlier step).

The lint does not know whether the plan can solve the task; a useless plan of the right shape is still clean. It also has one known false alarm: a note containing a word in curly braces such as {braces} is reported as UNKNOWN_PLACEHOLDER. Every plan that the simulated plan_execute writes passes the lint (a test checks all nine tasks).

5.2 Comparing the three patterns

Nine tasks, 20 seeds, the lab's default limits (8 steps, 40 cu), graded by the end-state oracle. The table below is simulated data from python -m lab.demo l03; cost is in fake cu, averaged per run.

Pattern No slips: success Model calls Cost Slip 1/10: success
direct 1/3 1.00 2.00 1/3
plan_execute 7/9 3.33 8.11 41/60
react 1 2.67 7.11 89/90

A "slip" is a simulated fault: with a given probability, a tool call has the last character of its JSON cut off (the tool returns BAD_JSON). The probability is 0 or 1/10, drawn by seed. Every rate is a reduced fraction of 180 runs: 1/3 = 60/180, 7/9 = 140/180, 41/60 = 123/180, 89/90 = 178/180. By task (no slips): direct is right on t01, t05 and t06 and wrong on the other six (they need a table lookup, a notebook write, or a result of 100 or more, or are tasks that cannot be answered); plan_execute is wrong on t05 (a tool that fails transiently once) and t06 (the lookup key lacks the word "diện tích", meaning "area"); react is right on all nine.

5.3 Reading the table correctly

  • 180 runs are not 180 pieces of evidence. Without slips each seed gives exactly the same run: 180 runs are 9 different runs repeated 20 times, and 7/9 means seven of nine tasks. With slips the seed makes runs differ, but the nine tasks are still nine situations chosen by the author.
  • Cost is not only the number of steps. react costs less on average (64/9 versus 73/9 cu, that is 7.11 versus 8.11) because plan_execute pays an extra model call (2 cu) to write the plan on every task, while react costs more on the two error tasks because it has to retry.
  • Two numbers at once. Every pattern changes both success and cost; reporting one number and dropping the other is biased. The lab deliberately does not build a confidence interval: with nine fixed tasks and nearly deterministic runs, an interval would create a feeling of precision that is not there.
  • The same seed, the same limits and the same tasks for every pattern: this is the minimum condition for a fair comparison; compare_patterns does exactly that.

6. The QA perspective

6.1 How to compare two patterns

Choose the tasks first, including easy tasks, tasks with tool faults and tasks that cannot be answered; use the same end-state oracle; record the limits and how cost is computed; report the number of successes and the total number of runs (123/180, not just 0.68), the cost, and which task each pattern gets wrong. A person decides which pattern to choose, with reasons beyond the numbers (risk, testability, operating cost).

6.2 What the numbers do not say

  • The simulated policies were written by the author together with the tasks; the difference is a consequence of how they were written, not a finding.
  • No number describes a model, a provider or a pattern in the real world. This table is not used to rank or recommend.
  • The results of the ReAct and Plan-and-Solve papers belong to their own settings [R1][R2].

6.3 What the lint does not say

A clean plan is not a correct plan: the lint does not run the plan, does not know whether the tool has enough permission, and does not know whether the arguments are reasonable (such as 999999*0). An agent that does not write a plan out (such as react) is mainly checked through the trace (L04) and the end-state oracle.

7. Real-world scenarios

Scenario 1 (fictional): "Choosing a pattern for the homework assistant". The HocVui team argues about plan_execute versus react for a new assistant. QA builds nine tasks like those in §5.2, including two tool-fault tasks, runs both patterns with the same limits, then reports the success and cost table with the sentence "nine tasks chosen by QA, simulated policies". The signer records the reasons.

Scenario 2 (fictional): "A plan that writes the notebook before computing". A planning module produces two steps: write a notebook containing {calc}, then compute. lint_plan returns FORWARD_REF:1 and QA blocks the plan before it runs, because the notebook would be written with the raw text {calc}, which a test on the final answer does not see right away.

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l3-m01
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 79 passed

8.2 Run the demo

python -m lab.demo l03

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-04; the two versions are identical). Every policy, task and cost is simulated:

A. plan lint
   ok: []
   note before calc: ['FORWARD_REF:1']
   unknown tool: ['UNKNOWN_TOOL:1']
   empty: ['EMPTY_PLAN']
B. 9 tasks x 20 seeds, no slips (SIMULATED)
   direct: runs=180 success=1/3 model_calls=1.00 tool_calls=0.00 cost=2.00
   plan_execute: runs=180 success=7/9 model_calls=3.33 tool_calls=1.33 cost=8.11
   react: runs=180 success=1 model_calls=2.67 tool_calls=1.67 cost=7.11
C. same, slip rate 1/10 (SIMULATED)
   direct: runs=180 success=1/3 model_calls=1.00 tool_calls=0.00 cost=2.00
   plan_execute: runs=180 success=41/60 model_calls=3.28 tool_calls=1.28 cost=7.94
   react: runs=180 success=89/90 model_calls=2.85 tool_calls=1.86 cost=7.68
D. per-task success without slips
   t01 direct=1 plan_execute=1 react=1
   t02 direct=0 plan_execute=1 react=1
   t03 direct=0 plan_execute=1 react=1
   t04 direct=0 plan_execute=1 react=1
   t05 direct=1 plan_execute=0 react=1
   t06 direct=1 plan_execute=0 react=1
   t07 direct=0 plan_execute=1 react=1
   t08 direct=0 plan_execute=1 react=1
   t09 direct=0 plan_execute=1 react=1

Reading the output: part A is four plans passed through the lint. Parts B and C are the table in §5.2 (no slips, then slip 1/10). Part D is the success by task for one seed (s0); there are no slips, so every seed gives the same result. Note that t07 and t08 are tasks that cannot be answered, where the right answer is to refuse (CANNOT_ANSWER): plan_execute is right there because the rule "refuse on any tool error" happens to coincide with the answer, not because it understands the task.

8.3 Try it yourself

Save it as try_l03.py in the lab's root directory (next to lab/, not inside lab/), run python try_l03.py, then delete the file:

import json
from fractions import Fraction

from lab import tasks as T
from lab.planning import compare_patterns, lint_plan, run_task

step = lambda tool, **a: {"tool": tool, "arguments": json.dumps(a, ensure_ascii=False)}
print(lint_plan([step("notes_add", name="n", text="Tổng = {calc}"), step("calc", expression="2+2")]))
print(lint_plan([step("calc", expression="2+2"), step("calc", expression="2+2")]))
tasks = [t for t in T.load_tasks() if t["id"] in ("t05", "t06")]
for pattern, v in compare_patterns(tasks, ["s0", "s1", "s2"]).items():
    print(pattern, v["success"], v["by_task"])
t4 = [t for t in T.load_tasks() if t["id"] == "t04"]
seeds = [f"s{i}" for i in range(10)]
for slip in (Fraction(0), Fraction(1, 5)):
    res = compare_patterns(t4, seeds, slip)
    print(slip, {p: str(v["success"]) for p, v in res.items()})
r = run_task(t4[0], "react", "s0")
print(r["stop_reason"], r["steps"], r["model_calls"], r["tool_calls"], r["used"])
many = compare_patterns(tasks, [f"s{i}" for i in range(20)])["plan_execute"]
print(many["runs"], many["by_task"] == compare_patterns(tasks, ["s0"])["plan_execute"]["by_task"])

Output (Python 3.14.6 and 3.12.14 identical):

['FORWARD_REF:1']
['DUPLICATE_STEP:2']
direct 1 {'t05': Fraction(1, 1), 't06': Fraction(1, 1)}
plan_execute 0 {'t05': Fraction(0, 1), 't06': Fraction(0, 1)}
react 1 {'t05': Fraction(1, 1), 't06': Fraction(1, 1)}
0 {'direct': '0', 'plan_execute': '1', 'react': '1'}
1/5 {'direct': '0', 'plan_execute': '1/5', 'react': '1'}
final 4 4 3 12
40 True

Reading it: lines 1 and 2: the lint catches a forward reference and a repeated step. Lines 3 to 5: on the two tasks with faults (t05, t06) direct is right (small result), plan_execute is wrong on both, react is right on both. Lines 6 and 7: on task t04 (needs three tool calls) with 10 seeds, without slips plan_execute and react are both right; with slip probability 1/5, plan_execute keeps 1/5 (two of ten seeds) while react is still 1 thanks to retries. The figure 1/5 is the result of ten specific seeds, not an estimate of a probability. Line 8: one react run (no slips): it stops at final, 4 steps, 4 model calls, 3 tool calls, 12 cu. Line 9: two tasks run with 20 seeds are 40 runs, but the per-task result of plan_execute is identical to the result of one seed (True): without slips, adding seeds adds no evidence.

8.4 Run the lesson's tests

python -m pytest tests/test_l03_planning.py -v

Result: 14 passed. Read test_plan_lint_checks_placeholders_in_order, test_comparison_numbers_without_slips, test_react_recovers_where_the_plan_does_not and test_an_empty_comparison_has_no_rates_instead_of_a_division_error. The tests run on in-memory values; the temporary directory of each run is deleted at once.

8.5 Troubleshooting

Symptom Cause Fix
success is None The seed list or task list is empty That is the result: with no runs there is no rate
The plan_execute result differs from the table when you change parameters A different seed or slip probability Keep the seed and limits fixed when comparing
UNKNOWN_PLACEHOLDER reported for an ordinary note The note contains a word in the form {ten} A known false alarm; change how the note is written

9. Independent exercise

Problem: Write a small plan lint and choose a pattern from recorded runs.

Requirements: complete exercises/test_l03_planning.py:

  1. TODO 1: my_plan_lint(plan): the sorted list of UNKNOWN_TOOL:i and FORWARD_REF:i problems (i counted from 1), one element per problem; ignore every other kind of problem.
  2. TODO 2: BEST: the name of the pattern with the highest success rate in exercises/ex_runs.json; on a tie, the one with fewer average model calls; if still tied, the name that sorts first.

Test data: exercises/ex_plans.json (seven plans, some bad), exercises/ex_runs.json (four fake patterns, ten simulated runs each).

Deliverable: the function and variable above, in the file exercises/test_l03_planning.py itself.

Acceptance criteria: python -m pytest exercises/test_l03_planning.py passes (2 tests), compared with lab.planning.lint_plan and a computation from the data. The tests do not check whether a plan can solve the task, and do not check choosing a pattern by any criterion other than the two numbers in the data.

Hints: TODO 1: walk the steps in order, remembering the tools seen before the current step; a placeholder can appear twice in one step. TODO 2: use Fraction to avoid false ties from rounding, and think about the order of the comparison key.

10. Knowledge check

0/18 done · Results are kept in this browser only.

P02 · True or false

A real-world plan-then-execute agent never re-plans after a tool error, just like the lab's plan_execute policy.

P04 · Select all that apply

A four-step plan: (1) lookup with {"key": "số chẵn"}; (2) calc with {"expression": 5} (a number, not a string); (3) tool search with {"q": "x"}; (4) notes_add with {"name": "x", "text": "{notes_read}"}. Select every code that lint_plan returns.

P05 · Put in order

Put the steps of a fair comparison between two patterns in order, from the first to the last.

  1. A person decides the pattern, with reasons beyond the numbers (risk, testability, operating cost)
  2. Report the number of successes over the total number of runs, the cost, and which task each pattern gets wrong
  3. Grade with the same end-state oracle
  4. Choose the task set beforehand, including easy tasks, tasks with tool errors and tasks that cannot be answered
  5. Fix the seeds, the limits (steps, budget) and the way cost is computed, the same for every pattern
  6. Run each pattern on the same tasks, the same seeds, the same limits

P06 · Match

Match each simulated policy with how it uses (or does not use) observations.

P07 · Spot the bug

A colleague wrote their own function that finds forward references in a plan. The function misses a case that the lab's lint_plan catches. Find the bug.

import re

def forward_refs(plan, tools):
    seen, problems = set(), []
    for i, step in enumerate(plan, 1):
        seen.add(step["tool"])
        for name in re.findall(r"\{([a-z_]+)\}", step["arguments"]):
            if name in tools and name not in seen:
                problems.append(f"FORWARD_REF:{i}")
    return problems

P08 · Short answer

A report (simulated): pattern X is plan_execute run on nine tasks with 20 seeds (180 runs), success 7/9, mean cost 73/9 (about 8.11) cu; pattern Y is direct run only on three tasks t01, t05, t06 with 5 seeds (15 runs), success 15/15, mean cost 2 cu. The report's conclusion: "Y is better than X". State at least three reasons this comparison is not fair and how to fix it.

P09 · Essay

Write 5-8 sentences reading the following table (simulated): compare_patterns on three tasks t03, t04, t09, six seeds (18 runs per pattern), slip probability 1/3, default limits. direct: success 0/18, mean cost 2 cu. plan_execute: 6/18 (1/3), 8 cu. react: 17/18, 92/9 (about 10.22) cu. State the two numbers to read together, the cost per success (total cost divided by the number of successes: 144/6 and 184/17), what the table does not prove, and who decides.

P11 · Recall

Lesson: L2-M07-L02

With no slip, plan_execute is wrong on two tasks (t05, t06) where react is right; no task goes the other way; on the remaining seven tasks the two patterns are both right or both wrong. According to L2-M07-L02, what exact p does the sign test on the differing items (2 wins, 0 losses) give?

P12 · Recall

Lesson: L3-M01-L02

The simulated react policy runs t04 with stuck_after=2 (it repeats its last call after two successful calls), with the default loop guard threshold 3. What are the result (stop reason, steps, cost) and the notebook state?

P13 · Recall

Lesson: L2-M01-L04

According to L2-M01-L04 §4.4 (the sampling unit is the case, not the run), a simulated comparison runs 3 tasks with 6 seeds per task, that is 18 runs per pattern. Which statement correctly describes the reliability of the 18 runs?

P14 · Multiple choice

With no slip, on the three tasks t03, t04, t09 and six seeds, the mean cost per run is 31/3 cu for plan_execute and 25/3 cu for react (both succeed 18/18). What is the main reason for the 2 cu difference?

P15 · Select all that apply

With slip probability 1/3, six seeds, three tasks (t03, t04, t09), the success by task is 1/6, 0 and 5/6 for plan_execute; 1, 5/6 and 1 for react; direct is 0/18. Select every true statement.

P16 · True or false

lint_plan returns [] for a one-step plan lookup with {"key": "số chẵn"}. So this plan solves the task "compute 9*8".

P17 · Match

Match each lint_plan code with the plan that causes it.

P18 · Multiple choice

Four fake patterns (simulated) with success and mean model calls: m1 7/10 and 3.0; m2 8/10 and 4.5; m3 8/10 and 3.5; m4 4/5 and 3.5. Selection rule: highest success rate; on a tie, fewer mean model calls; still a tie, the name that sorts first. Which pattern is chosen?

11. Summary

  • Concepts: ReAct (thought-action-observation; a thought does not change the environment) [R1]; Plan-and-Solve [R2]; the lab's three patterns and how they deliberately differ; a plan is data that can be linted.
  • Skills: linting a plan; comparing patterns on the same tasks, seed and limits; reporting success and cost together, with the number of successes and the total number of runs.
  • Traps: treating 180 runs as 180 pieces of evidence; treating simulated numbers as properties of a model; ignoring cost; trusting that a clean plan is a correct plan.
  • You can now: hear "pattern A is better than pattern B" and ask: on which tasks, who chose them, under the same limits yet, at what cost, and is it a simulation.

12. References

ID Title Publisher URL Accessed Relevance
R1 ReAct: Synergizing Reasoning and Acting in Language Models (Yao et al., arXiv:2210.03629 v3, 10/03/2023, day/month/year) arXiv https://arxiv.org/abs/2210.03629 (read the HTML version https://arxiv.org/html/2210.03629) 2026-11-04 Read the full text of the HTML version in the abstract, method, results and error analysis; the appendix was not read in full. The results belong to the paper's own setup (PaLM-540B, in-context examples)
R2 Plan-and-Solve Prompting: Improving Zero-Shot Chain-of-Thought Reasoning by Large Language Models (Wang et al., arXiv:2305.04091 v3, 26/05/2023, day/month/year; the page lists ACL 2023) arXiv https://arxiv.org/abs/2305.04091 2026-11-04 Read the abstract only on the arXiv page; the full text was not read
R3 Building effective agents Anthropic https://www.anthropic.com/engineering/building-effective-agents (redirects to /research/building-effective-agents) 2026-11-04 Read the page text (the passage on orchestrator-workers); the two appendices were not read in full

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Pattern Mẫu tổ chức vòng lặp: direct, plan_execute, react
Reason-act loop (ReAct) Vòng lặp suy nghĩ-hành động-quan sát [R1]
Thought Suy nghĩ: văn bản lập luận của model, không đổi môi trường [R1]
Plan-then-execute Lập kế hoạch trước rồi thực hiện (chính sách plan_execute của lab không lập lại kế hoạch; hệ thật có thể)
Plan lint Lint kế hoạch: kiểm cấu trúc, tool, tham số, tham chiếu
Forward reference Tham chiếu trước: dùng kết quả của một tool khi chưa bước nào gọi nó
Seed / slip Chuỗi rút số giả ngẫu nhiên tất định / lỗi mô phỏng làm hỏng JSON tham số