Tree of Thoughts and LATS: Deliberate Search
A single chain-of-thought trajectory has no room to backtrack. ToT (Yao et al., 2023) turns reasoning into a tree with self-evaluation on each node, and LATS (Zhou et al., 2024) folds ToT, ReAct, and Reflexion into Monte Carlo Tree Search. Game of 24 goes from 4% (CoT) to 74% (ToT), and LATS hits 92.7% pass@1 on HumanEval.
Learning Objectives
- Frame reasoning as search: nodes are "thoughts," edges are "expansions," value is "how promising."
- Implement a stdlib ToT-style BFS tree search with self-evaluation scoring.
- Extend to a toy LATS MCTS loop with select / expand / simulate / backpropagate.
- Decide when search is worth the token multiplier (Game of 24, code generation) and when a single trajectory is enough (simple Q&A).
The Problem
Chain-of-thought is a linear walk. If the first step is wrong, every step after it builds on a bad premise. Game of 24 (combine four numbers with + − × ÷ to make 24) shows the damage: GPT-4 with CoT scores 4%. It picks the wrong subexpression early and has no way back.
What the model needs is the ability to propose several candidates, score them, keep the promising ones, and back up when a branch dies. That is search. Tree of Thoughts and LATS are the two canonical ways to bolt it onto an LLM.
The Concept
Tree of Thoughts (Yao et al., NeurIPS 2023)
Tree of Thoughts (ToT) treats reasoning as search over a tree. Each node is a coherent intermediate step, a "thought," and each node expands into K child thoughts. The LLM scores every node with an evaluation prompt, and a search algorithm (BFS, DFS, or beam) decides which branches to keep exploring.
(root: "find 24 from 4 6 4 1")
/ | \
("6 - 4 = 2") ("4 + 1 = 5") ("4 * 6 = 24") <- Score: HIGH
/ \ | |
... ... ... finish
The self-evaluation step carries the whole method. The paper tests three variants: a sure / likely / impossible classification, a 1..10 numeric score, and a vote among candidates. All three beat CoT by a wide margin on Game of 24 (4% to 74% with GPT-4).
LATS (Zhou et al., ICML 2024)
LATS (Language Agent Tree Search) runs ToT, ReAct, and Reflexion together inside Monte Carlo Tree Search. One LLM plays three roles:
- Policy: proposes candidate next actions, ReAct-style.
- Value function: scores a partial trajectory, ToT-style.
- Self-reflector: after a failure, writes a natural-language reflection (Reflexion-style) that reseeds later rollouts.
Environment feedback flows into the value function too, so the search rests on real tool results and not only the model's opinion of itself. At paper time LATS reached 92.7% pass@1 on HumanEval with GPT-4 (state of the art) and a 75.9 average on WebShop with GPT-3.5, approaching gradient-based fine-tuning.
MCTS, minimally
Each iteration runs four phases:
- Select: walk from the root to a leaf using UCT (upper confidence bound for trees).
- Expand: generate K children with the policy.
- Simulate: roll out from a child using the policy, then score the leaf with the value function or the environment reward.
- Backpropagate: push the result back up the path, updating visit counts and value estimates.
The UCT formula is Q(s, a) + c * sqrt(ln N(s) / N(s, a)). The first term rewards what has worked so far (exploitation), the second rewards what has been tried least (exploration). Tune c per task.
The cost reality
Search burns tokens. ToT on Game of 24 uses 100-1000x the tokens of CoT, and LATS lands in the same range. Reach for it when:
- A single trajectory demonstrably fails (Game of 24, hard code problems).
- Correctness matters more than wall-clock time.
- You have a cheap, reliable value function, like unit tests for code or an explicit target for math.
If the task has one right answer and your evaluator is noisy, search often makes things worse. It finds a wrong answer that scores well.
2026 positioning
Most production agents don't run LATS. They run ReAct with tool-grounded verification (CRITIC, Lesson 05). Search survives in a few niches:
- Coding agents that use tests as the value function (HumanEval-style).
- Deep-research agents that explore several query paths.
- Planning-heavy workflows inside LangGraph subgraphs.
AlphaEvolve (Lesson 11) is the 2025 extreme: evolutionary search over code with machine-checkable fitness, and frontier results to show for it (the first 4x4 matmul improvement in 56 years).
Build It
code/main.py implements three pieces:
- A small ToT BFS on a stylized "pick arithmetic ops" task.
- A toy LATS MCTS loop on the same task (Select / Expand / Simulate / Backpropagate) with UCT selection.
- A value function that combines a symbolic score with a self-eval score.
Run it:
python3 code/main.py
The trace shows ToT expanding three candidates per node with BFS, then LATS converging on the best rollout through MCTS. Token counts print for both, so you can see the cost gap for yourself.
Use It
LangGraph ships ToT-style exploration as subgraph patterns, and the LangChain team's LATS post (May 2024) is the reference tutorial. LlamaIndex has a TreeOfThoughts agent. In most 2026 production agents the pattern sits behind a gate like if task_complexity > threshold: use_search(). The evaluator-optimizer pattern in Lesson 05 is the neighboring idea.
Ship It
outputs/skill-search-policy.md picks between linear ReAct, ToT, LATS, and evolutionary search based on task shape, budget, and evaluator fidelity.
The most common mistake is reaching for search before checking the evaluator. A tree is only as good as the score on its nodes. If you can't write a value function you'd trust on its own (tests that pass, a target that matches), more branches just give a noisy scorer more chances to pick the wrong answer. Fix the evaluator first. A single ReAct run with a good verifier often beats the tree at a fraction of the cost.
Exercises
- Run the toy LATS with UCT c=0.1 vs c=2.0. What changes in the trace?
- Swap the value function for a noisier scorer (add random jitter). Does MCTS still find the best leaf? What is the minimum signal-to-noise it tolerates?
- Implement beam-search ToT (keep the top-k at each level) and compare it to BFS. Which is better on a tight token budget?
- Read LATS Section 5.1. Reproduce the HumanEval trajectory count: how many rollouts does it take to hit the reported pass@1?
- Read the LATS paper's discussion of "when LATS helps less." Write a one-paragraph decision rule mapping task shape to search strategy.
Key Terms
| Term | What people say | What it actually means |
|---|---|---|
| Tree of Thoughts | "Branching CoT" | Yao et al.: a tree of thought nodes, each scored by self-evaluation |
| LATS | "MCTS for LLMs" | Zhou et al.: ToT + ReAct + Reflexion under MCTS |
| UCT | "Upper confidence bound" | Selection formula balancing exploitation (Q) and exploration (ln N / n) |
| Value function | "How good is this state" | A prompted LLM score or environment reward that feeds backprop |
| Policy | "Action proposer" | ReAct-style generator that emits candidate next thoughts or actions |
| Rollout | "Simulated trajectory" | A walk from a node to a leaf using the policy, scored with the value function |
| Backpropagate | "Update ancestors" | Push the leaf's reward up the path, updating visit counts and Q |
| Search cost | "Token explosion" | 100-1000x CoT on Game of 24; budget before you adopt |
Further Reading
- Yao et al., Tree of Thoughts (arXiv:2305.10601): the canonical paper
- Zhou et al., LATS (arXiv:2310.04406): MCTS with Reflexion feedback
- LangGraph overview: subgraph patterns for search
- AlphaEvolve (arXiv:2506.13131): evolutionary search with programmatic evaluators
Code
- main.py (python, 187 lines)