ReAct, ReWOO, Reflexion and Tree of Thoughts
Pick, build and stop an agent reasoning loop. ReAct, ReWOO, Reflexion, ToT, LATS, Self-Refine, CRITIC and CoT.
- Concepts and terms
- Tasks and commands
- Annotated code
- Diagrams
- Comparisons
- Defaults and numbers
- Troubleshooting
- Questions and tips
Four patterns side by side#
| Factor | ReAct | ReWOO | Reflexion | ToT / LATS |
|---|---|---|---|---|
| Roles | Thought, Action, Observation | Planner, Workers, Solver | Actor, Evaluator, Self-Reflector | Policy, value function, search |
| LLM calls | One for each step | One plan, one solve | One run for each trial | One for each node |
| Observations | In every step | Not in the planner | As reflections in the next trial | Mixed into the value function |
| Token cost | Grows with depth | About 5x fewer on HotpotQA | Grows with the buffer | 100-1000x CoT |
| Paper result | ALFWorld +34 points | HotpotQA +4 accuracy | Beats ReAct on ALFWorld | Game of 24: 4% to 74% |
| Main failure | Loop length explosion | Static plan | Memory rot | Noisy evaluator |
Use each pattern when#
- ReAct
- short tasks, unknown environment, reactive exception handling.
- ReWOO
- structured tasks with known tools and parallel evidence.
- Plan-and-Execute
- like ReWOO, with replanning after partial execution.
- Plan-and-Act
- long horizon (>30 steps), web, mobile or computer use.
- Reflexion
- a clear failure signal and a task class that repeats.
- ToT / LATS
- a cheap, reliable value function. Correctness beats wall-clock.
- Self-Refine
- no external verifier. One model generates and critiques.
- CRITIC
- an external verifier exists: search, code, calculator, tests.
ReAct loop: AgentLoop.run#
ReWOO: plan, fetch, solve#
Reflexion trial#
LATS: one MCTS iteration#
Tips#
- Start with the simplest pattern. One tool call plus a summary needs no ReWOO.
- Stop a refine loop when the verifier passes. Also cap it with
max_iterations. - Keep branching factor K at 3-5. K=10 explodes cost.
Tasks in code#
| Task | Code |
|---|---|
| Register a tool | tools.register("calculator", |
| Order a plan DAG | topological(plan) |
| Fill #E references | resolve_references(value, |
| Reflexion with memory | run_reflexion(max_trials= |
| ToT breadth first | tot_bfs(root_tot) |
| LATS search | mcts(root_lats, |
| CRITIC loop | run_loop("world facts", |
CoT escalation pipeline#
single_answer, _ = few_shot_cot_solve(question, examples, client, model)temperature 0.0sc_answer, confidence, reasonings, votes = self_consistency_solve( question, examples, client, model, n_samples=5)temperature 0.7, majority voteif confidence >= 0.8 and single_answer == sc_answer: return sc_answer4 of 5 samples agreetot_answer, tot_reasoning = tree_of_thought_solve( question, client, model, breadth=3, depth=2)escalate hard problemsPrompt reasoning ladder (GPT-5, GSM8K)#
| Factor | Zero-Shot CoT | Few-Shot CoT | Self-Consistency (N=5) | Tree-of-Thought |
|---|---|---|---|---|
| API calls | 1 | 1 | 5 | 10-40+ |
| Token overhead | 50-200 tokens | 300-600 tokens | 5x token cost | 10-40x token cost |
| Accuracy | 97% | 98% | 98.5% | 74% on Game of 24 |
| Best for | Quick reasoning boost | Maximum single-call accuracy | High-stakes reasoning | Search/planning problems |
Defaults in the lesson code#
| Setting | Default | Note |
|---|---|---|
max_turns | 12 | AgentLoop turn budget. The demo sets 10 |
max_len | 6 | EpisodicMemory size |
max_iters | 4 | Refine loop cap in run_loop |
c in uct | 1.4 | Exploration weight |
max_expansions_per_level | 8 | ToT BFS frontier width |
max_depth | 3 | ToT BFS depth |
n_samples | 5 | Self-consistency votes |
temperature | 0.7 | Sampled paths. At 0.0 all samples match |
Troubleshooting#
| Symptom | Cause | Fix |
|---|---|---|
| Agent hallucinates success on 400 errors | Error not fed back | Turn each error into an observation string |
| A web page gives the agent orders | Trust boundary collapse | Only direct user instructions count as permission |
| "cyclic plan or unresolved reference" | A step refers to a missing node | Fix the #E references in the plan |
| Reruns get slower, stale advice | Memory rot | Compaction or TTL on reflections |
| Reflection does not help | External failure, network down | Do not store one-off flaky runs |
| Critique always says looks good | Rubber-stamp loop | Use structurally different prompts |
| Search finds a good-scoring wrong answer | Noisy evaluator | Use search only with a reliable value function |
Questions#
- Why does ReWOO use fewer tokens?
- ReAct prompts carry every prior step. ReWOO workers get only the tool call.
- Why can a 7B model plan?
- The planner does not see observations. It learns from 175B teacher plans.
- What does LATS add to ToT?
- MCTS. The LLM is policy, value function and self-reflector.
- Why does Self-Refine keep history?
- Refine sees prior outputs and critiques. Without history, quality drops sharply.
- Why CRITIC over Self-Refine?
- A hallucination often looks convincing to the model that produced it.
- Add CoT to a reasoning model?
- No. The o-series and DeepSeek-R1 run CoT internally.