Cheat sheets

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

Source

Four patterns side by side#

FactorReActReWOOReflexionToT / LATS
RolesThought, Action, ObservationPlanner, Workers, SolverActor, Evaluator, Self-ReflectorPolicy, value function, search
LLM callsOne for each stepOne plan, one solveOne run for each trialOne for each node
ObservationsIn every stepNot in the plannerAs reflections in the next trialMixed into the value function
Token costGrows with depthAbout 5x fewer on HotpotQAGrows with the buffer100-1000x CoT
Paper resultALFWorld +34 pointsHotpotQA +4 accuracyBeats ReAct on ALFWorldGame of 24: 4% to 74%
Main failureLoop length explosionStatic planMemory rotNoisy 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#

1Userthe message goes into the history as a userturn.2LLMrespond(history) returns a thought and anaction, or finish.3ToolRegistrydispatch(call) runs the tool by name.4Formattera bad tool or bad args returns an error: string,not a crash.5Loopthe action turn and its observation go into thehistory. Go to step 2.6Stopfinish, no tool calls, max turns, max tokens ora guardrail trip.7Budgetafter max_turns the loop returns "budgetexhausted".

ReWOO: plan, fetch, solve#

topological#E1#E2evidenceclientQuestionuser_questionmodelPlannerplan DAG, noobservationsprocessWorker E1search capitalprocessWorker E2population of #E1processWorker E3round_million #E2modelSolverquestion, plan,evidencetopological#E1#E2evidenceclientQuestionuser_questionmodelPlannerplan DAG, noobservationsprocessWorker E1searchcapitalprocessWorker E2population of#E1processWorker E3round_million#E2modelSolverquestion,plan,evidence

Reflexion trial#

1Actoractor.act(memory) returns a candidatetrajectory.2Evaluatorbinary_evaluator(attempt, TARGET) returnssuccess and delta.3Self-Reflectorwrites one line, for example "pick largervalues".4EpisodicMemorymemory.add stores it. The oldest drops pastmax_len.5Next trialstarts fresh but sees the reflections. A successends the run.

LATS: one MCTS iteration#

1Selectwalk from root to a leaf by Q(s, a) + c *sqrt(ln N(s) / N(s, a)).2Expandgenerate K children with the policy.3Simulateroll out from a child. Score the leaf with thevalue function.4Backpropagateadd 1 to visits and the reward to value_sum onthe path.

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#

TaskCode
Register a tooltools.register("calculator", calculator)
Order a plan DAGtopological(plan)
Fill #E referencesresolve_references(value, evidence)
Reflexion with memoryrun_reflexion(max_trials=4, use_memory=True)
ToT breadth firsttot_bfs(root_tot)
LATS searchmcts(root_lats, iterations=80, rng=rng)
CRITIC looprun_loop("world facts", use_critic=True)

CoT escalation pipeline#

single_answer, _ = few_shot_cot_solve(question, examples, client, model)temperature 0.0
sc_answer, confidence, reasonings, votes = self_consistency_solve(
question, examples, client, model, n_samples=5
)temperature 0.7, majority vote
if confidence >= 0.8 and single_answer == sc_answer:
return sc_answer4 of 5 samples agree
tot_answer, tot_reasoning = tree_of_thought_solve(
question, client, model, breadth=3, depth=2
)escalate hard problems

Prompt reasoning ladder (GPT-5, GSM8K)#

FactorZero-Shot CoTFew-Shot CoTSelf-Consistency (N=5)Tree-of-Thought
API calls11510-40+
Token overhead50-200 tokens300-600 tokens5x token cost10-40x token cost
Accuracy97%98%98.5%74% on Game of 24
Best forQuick reasoning boostMaximum single-call accuracyHigh-stakes reasoningSearch/planning problems

Defaults in the lesson code#

SettingDefaultNote
max_turns12AgentLoop turn budget. The demo sets 10
max_len6EpisodicMemory size
max_iters4Refine loop cap in run_loop
c in uct1.4Exploration weight
max_expansions_per_level8ToT BFS frontier width
max_depth3ToT BFS depth
n_samples5Self-consistency votes
temperature0.7Sampled paths. At 0.0 all samples match

Troubleshooting#

SymptomCauseFix
Agent hallucinates success on 400 errorsError not fed backTurn each error into an observation string
A web page gives the agent ordersTrust boundary collapseOnly direct user instructions count as permission
"cyclic plan or unresolved reference"A step refers to a missing nodeFix the #E references in the plan
Reruns get slower, stale adviceMemory rotCompaction or TTL on reflections
Reflection does not helpExternal failure, network downDo not store one-off flaky runs
Critique always says looks goodRubber-stamp loopUse structurally different prompts
Search finds a good-scoring wrong answerNoisy evaluatorUse 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.