Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

~8 min readPrinceton / DeepMind · 2023

Tree of Thoughts,
explained.

Watch yourself solve a hard puzzle. You don't write one stream of reasoning and commit to it — you try an approach, sense it's going nowhere, back up, try another. Language models couldn't do any of that: generation moves left to right, no takebacks. Tree of Thoughts gave them the missing moves — propose several next steps, judge which look promising, explore those, and backtrack when a branch dies.

The delta

What changes against self-consistency: the paths can be abandoned

Rung 2's samples are independent and complete. Each chain is generated start to finish with no knowledge of the others, nothing is evaluated until it is over, and a chain that goes wrong in its second step still consumes the tokens to finish. Left-to-right generation cannot take anything back.

The change is to make reasoning a search. Generate several candidate next thoughts rather than one, have the model evaluate them — is this step promising, is this state still solvable — and then explore the resulting tree deliberately, breadth-first or depth-first, backtracking out of branches judged dead. The units that differ from rung 2: intermediate evaluation, which rung 2 has none of, and the ability to abandon partial work, which rung 2 cannot do because it has no notion of partial work.

The gains are largest exactly where that matters — problems needing a commitment early that is only revealed to be wrong later, where one greedy pass is nearly hopeless and independent sampling is barely better because every sample repeats the same early mistake. On the arithmetic puzzle the paper uses as its showcase, the reported move is from the low single digits to roughly three quarters.

01

The System-1 trap

Autoregressive generation is pure System 1: fast, associative, one token after another, no revision. Chain-of-thought made the stream longer and more structured, and self-consistency hedged it by sampling many streams — but every stream is still a one-way street. Nothing in the machinery lets the model consider two alternatives, compare them, or undo a commitment.

For some problems that's fatal by construction. Take Game of 24 — combine 4, 9, 10, 13 with arithmetic to make 24. Humans solve it by trial and error: try 10+13=23, leaving 4, 9, 23… nothing reaches 24, dead end, back up, try 13−9=4, leaving 4, 4, 10, and (10−4)×4=24 ✓. A model that can't back up has to guess the winning line on the first try. GPT-4 with CoT managed 4%.

02

The unit: a "thought," not a token

ToT's first move is choosing the right granularity. Searching over individual tokens would be astronomically branchy; searching over whole solutions is just self-consistency. In between sits the thought: a coherent intermediate step — one equation in a math puzzle, one plan paragraph in an essay, one word placement in a crossword.

The key idea

Frame problem-solving as search over a tree of thoughts: each node is a partial solution, each edge is one more coherent step. Then everything classical AI knows about tree search — frontiers, heuristics, pruning, backtracking — applies to LLM reasoning directly.

It's a deliberate reunion of the two AI traditions: the LLM supplies what search always lacked (rich step generation and judgment), and search supplies what LLMs lacked (exploration and the right to change your mind).

04

The model as its own heuristic

Classical search needs a heuristic function, hand-built per problem. ToT's second insight: the LLM is the heuristic. Prompt it to assess a partial solution — "can these remaining numbers still reach 24: sure, likely, or impossible?" — and you get a usable value function for free, in natural language, on any domain.

Self-evaluation is noisy, and that's fine: a search heuristic doesn't need to be right, only informative enough to rank siblings. Judging "is this partial state promising?" is reliably easier than generating the full correct solution — the same generator-verifier gap that later powers process reward models and LLM-as-judge everywhere.

06

The bill

Every proposal and every evaluation is a model call. A Game of 24 solve runs ~100 calls; deep DFS problems more. ToT is test-time compute spent aggressively — orders of magnitude beyond a single chain — plus orchestration code to manage the tree, the prompts, and the frontier.

It also needs problems with decomposable steps and evaluable partial states. Where a task is one intuitive leap, or progress can't be judged midway, the tree collapses back into an expensive chain. ToT is a specialist's scalpel, not a default decoding mode.

07

Why it still matters

ToT completed the trilogy that defined LLM reasoning's external era: CoT (make thinking visible) → self-consistency (sample and vote) → ToT (search deliberately, with evaluation and backtracking). Together they proved the capability ceiling wasn't the model — it was the inference procedure.

The final act absorbed the lesson: reasoning models trained with RL now explore, self-check, hit dead ends and say "wait, let me reconsider" inside a single generation — the tree internalized into the stream. When o1-class models budget more thinking for harder problems, they're running ToT's playbook without the scaffolding. The scaffold retired; the idea won.

Read next

Start of the thread: Chain-of-Thought. The voting middle: Self-Consistency. The internalization: DeepSeek-R1.

How it works

How Yao et al. built Tree of Thoughts

Tree of Thoughts comes from Shunyu Yao and colleagues at Princeton and Google DeepMind, and was published at NeurIPS 2023. It wraps a frozen language model in a search program. The paper frames any instance of it as four design choices, and each of its three tasks makes those choices differently.

4 9 10 13 13 − 9 = 4 left: 4 4 10 10 − 4 = 6 left: 6 9 13 4 + 9 = 13 left: 10 13 13 9 × 10 = 90 left: 4 13 90 sure · kept sure · kept impossible · pruned impossible · pruned 10 − 4 = 6 left: 4 6 4 × 4 = 16 left: 10 16 13 − 9 = 4 left: 4 6 sure · kept impossible · pruned sure · kept 4 × 6 = 24 ✓ breadth-first search keeps the b best states at each depth paper b = 5; here 2
One Game of 24 search, drawn with breadth 2: the model proposes equations, judges whether the numbers left can still reach 24, keeps the best states and prunes the rest. Each verdict shown was checked by brute force.
  1. Decompose the problem into thoughts. A thought must be small enough that the model can propose good, varied candidates, and big enough that the model can judge whether it is promising. In Game of 24 a thought is one intermediate equation, so a solution is three thoughts deep. In creative writing it is a whole plan for the passage. In 5×5 mini crosswords it is one word placed on the board.
  2. Generate candidate thoughts. Two generators. Sample draws k independent thoughts from a chain-of-thought prompt, which suits rich thought spaces such as a paragraph-long plan, where independent samples are naturally different. Propose asks for several next steps in one prompt, which suits narrow spaces such as one equation or one word, where independent samples would repeat each other.
  3. Evaluate states. Two evaluators. Value prompts the model to judge one state on its own, as a score or a class. For Game of 24 the classes are sure, likely and impossible, sampled three times per state, and the model reaches them by trying a few quick completions and by noticing when the remaining numbers are obviously too big or too small. Vote shows the model several states at once and asks which is most promising, which suits states that are hard to score alone, such as choosing the best of five writing plans.
  4. Search. Breadth-first search keeps the b best states at each depth and suits shallow trees: Game of 24 with b = 5, and creative writing. Depth-first search follows the most promising state until it reaches a solution or the evaluator rules the state impossible, then backtracks to the parent. It suits crosswords, where one bad word can make the board unsolvable several placements later.
  5. Return the answer. Once a full-depth state exists, the model writes the final output from it: the equation that makes 24, the passage written from the winning plan, or the filled board.

The three task setups

Game of 24. 100 hard games taken from an online collection of 1,362, ranked by how long people took to solve them. Success means a valid equation that uses each of the four numbers exactly once and equals 24. GPT-4 is the model throughout, sampling at temperature 0.7.

Creative writing. Given four random sentences, write a coherent four-paragraph passage whose paragraphs end with those sentences. The tree is two levels deep: the model writes five plans and votes on the best, then writes five passages from that plan and votes again.

Mini crosswords. 5×5 boards from a puzzle site, solved by depth-first search. The model proposes words for open clues with a confidence for each, fills the most promising one, and prunes the branch as soon as it judges any remaining clue impossible to fill.

The baselines use the same model and examples: input-output prompting, chain-of-thought prompting, self-consistency over chain-of-thought samples and, for some tasks, an iterative self-refinement loop. So any gap comes from the search, not from a different model or a better prompt.

The math

The breadth-first update and the two evaluators

The paper writes the breadth-first version as a loop over depth t. Expand every kept state with the generator G, score the new states with the evaluator V, and keep the b best:

S′t = { [s, z] : s ∈ St−1, z ∈ G(pθ, s, k) }
Vt = V(pθ, S′t)
St = argmaxS ⊂ S′t, |S| = b Σs ∈ S Vt(s)

The two evaluators differ in what the model sees at once:

value: V(pθ, S)(s) ∼ pθ^value( v | s )
vote: V(pθ, S)(s) = 1[ s = s* ], with s* ∼ pθ^vote( s* | S )
  • [s, z] — a state extended by one new thought z
  • k — candidates generated per state; b — the breadth kept, 5 for Game of 24
  • pθ^value — the model prompted to rate one state alone: sure, likely or impossible in Game of 24
  • s* — the state the model picks when shown all of S together

At b = 1 the search keeps only the single best-rated state, which is a greedy chain steered by the evaluator, and Game of 24 success fell from 74% to 45%. Raising b raises cost in proportion, since every kept state is expanded and every child is evaluated. The depth-first variant swaps the argmax for a threshold: a state valued at vth or below is pruned and the search backtracks to its parent.

The evidence

What Yao et al. ran, and what it showed

Every result uses GPT-4. Game of 24 is scored on 100 hard games. The two oracle rows count a game as solved if any of 100 samples is correct, which no real system could know without checking every one.

Game of 24 methodSuccess
Input-output prompting7.3%
Chain-of-thought prompting4.0%
Chain of thought + self-consistency, 100 samples9.0%
Input-output + iterative refinement, up to 10 rounds27%
Input-output, best of 100 (oracle)33%
Chain of thought, best of 100 (oracle)49%
Tree of Thoughts, b = 145%
Tree of Thoughts, b = 574%

Two comparisons carry the argument. Tree of Thoughts at b = 5 beats even the oracle that picks the right answer out of 100 chain-of-thought samples, so the gain is not just more attempts. And breadth matters: keeping one state instead of five drops success from 74% to 45%.

Where chains fail. The error analysis found that about 60% of chain-of-thought samples had already failed after the first step, the first equation, which is exactly the commitment a left-to-right chain cannot revisit.

The other two tasks. In creative writing, GPT-4 scored coherence on a 1 to 10 scale at 6.19 for input-output prompting, 6.93 for chain of thought and 7.56 for Tree of Thoughts, and human judges preferred Tree of Thoughts over chain of thought in 41 of 100 pairs against 21. In mini crosswords, Tree of Thoughts got 60% of words right and solved 4 of 20 games, where the prompting baselines solved almost none. Ablations that removed pruning or removed backtracking both scored clearly lower at the word level, so both parts of the search earn their cost.

Since then

What the authors admit, and what happened next

The cost is much worse than rung 2's and is admitted: every node needs generation and evaluation, so a search of any breadth costs many model calls per problem, with latency to match. The self-evaluation is also the weak link — the search is only as good as the model's judgement of a partial solution, and that judgement is less reliable than its ability to generate, precisely on the hard problems where pruning matters most.

There is also a scope limit that the showcase tasks obscure: the method needs a task that decomposes into discrete, evaluable intermediate states. Puzzles have those. Open-ended writing and most real questions do not, and the framework has nowhere to put its evaluator.

How it held up: as a framing that mattered more than the implementation. Establishing that reasoning could be search — with generation, evaluation and backtracking as separable components — reorganised how people thought about the problem. What did not persist is the external scaffold: rungs 4 and 5 train the search behaviour into the model, so that backtracking and reconsideration appear inside one generated stream rather than being orchestrated by a program around it. This rung's ideas won; its architecture was absorbed.

SOLVE IT YOURSELF

Play Game of 24 two ways

The paper's 4%→74% jump comes entirely from replacing a linear chain with a search that can backtrack. Here it is, literally: a greedy chain that commits to one move and never reconsiders, versus a tree search that tries every combination and backs out of dead ends. Run it on the classic [3,3,8,8] — the greedy chain dead-ends, and the tree finds 8/(3-8/3) = 24. It even proves [1,1,1,1] is impossible. Change the numbers and watch which strategy survives.

YOUR TASK

Write the body of tree_solve. Everything else in the file is already written; this is the function the paper is about. Press ▶ Run to check it against the 5 assertions below — they start red.

WHAT IT HAS TO SATISFY — 5 ASSERTIONS
  1. Tree search solves the classic hard set [3,3,8,8]
  2. The greedy single chain dead-ends on the same set
  3. Tree search solves a standard set too
  4. Tree search proves an impossible set has no solution
  5. The solution the tree finds really equals 24
CPython · WebAssembly
Questions

Questions people ask about Tree of Thoughts

What prompts does a Tree of Thoughts implementation need?

Two kinds, and which versions depend on the task. A generator prompt produces candidate next thoughts: either a chain-of-thought prompt sampled several times, or a propose prompt that asks for several possible next steps in one response, which is what Game of 24 uses. An evaluator prompt judges states: either a value prompt that rates one state alone, such as asking whether the remaining numbers can still reach 24 and answering sure, likely or impossible, or a vote prompt that shows several states and asks which is most promising. A final prompt turns a complete state into the answer. The search itself, the queue or stack of states and the breadth limit, lives in ordinary code around the model.

When should Tree of Thoughts use breadth-first versus depth-first search?

The paper uses breadth-first search when the tree is shallow and the evaluator can compare states at the same depth: Game of 24 has three steps, and creative writing has a plan level and a passage level. Breadth-first keeps the b best states per level, 5 in Game of 24. It uses depth-first search for 5×5 mini crosswords, where the tree is deep, a solution has to be pushed all the way to completion, and the useful signal is that some remaining clue has become impossible. Depth-first follows the most promising state until it finishes or is judged impossible, then backtracks to the parent and tries the next candidate. The choice follows the shape of the problem.

How many model calls does Tree of Thoughts cost compared with chain of thought?

Far more than one chain, because every expanded state needs a generation call and every candidate state needs at least one evaluation; in Game of 24 each candidate is valued three times. Cost grows with the breadth kept, the number of candidates proposed per state and the depth, so breadth 5 costs several times breadth 1, and in the paper that difference is worth 74% against 45%. The authors discuss the cost openly and argue it pays only on problems that genuinely need search, where an early commitment can turn out to be wrong. On tasks that a single chain already solves, the extra calls buy nothing, which is part of why later systems trained search-like behavior into the model instead of orchestrating it from outside.

Why did chain-of-thought prompting score only 4% on Game of 24?

Because the first equation decides most outcomes and a chain cannot take it back. The paper's error analysis found that about 60% of chain-of-thought samples had already failed after the first step, the first three words of an equation such as 4 + 9. Once a chain writes an equation that leaves an unsolvable set of numbers, every later step is wasted. Sampling more chains helps little: self-consistency over 100 samples reached only 9%, because most samples make a similar early mistake and the vote has nothing correct to converge on. Tree of Thoughts fixes exactly this step by proposing several first equations, judging each remaining set of numbers, and keeping only the promising ones.

How is Tree of Thoughts different from Graph of Thoughts and LATS?

Both are later work that kept the search framing and changed its structure. Graph of Thoughts, from Besta and colleagues in 2023, lets thoughts merge as well as branch, so partial solutions can be combined, for example sorting sublists and then merging them, which a tree cannot express. Language Agent Tree Search, or LATS, from Zhou and colleagues in 2023, replaces breadth-first and depth-first search with Monte Carlo tree search and adds feedback from an external environment plus self-reflection on failed attempts, aimed at agents acting in the world rather than puzzles solved in text. Tree of Thoughts remains the simplest of the three: a frozen model, a generator, an evaluator and a classical search loop.

Check yourself

4 questions to test what you just read

Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.

Suppose each kept state proposes 8 candidates and each candidate is valued 3 times. With breadth b = 5 and three equation steps, how many value samples does one game take, and how many at b = 1?

Show answer

Step 1 expands only the root: 8 × 3 = 24. Steps 2 and 3 each expand 5 states: 5 × 8 × 3 = 120 per step. Total 264. At b = 1 every step costs 24, so 72 in all, about 27% of the cost, for 45% success instead of 74%.

Two first proposals from 4 9 10 13 are 13 − 9 = 4 and 4 + 9 = 13. Which state should the value prompt call impossible, and why is that verdict cheap to reach?

Show answer

4 + 9 = 13, which leaves 10, 13, 13, and no combination of those makes 24. The other leaves 4, 4, 10, which is solvable as (10 − 4) × 4. The verdict is cheap because three small numbers have few combinations to try, which is the quick lookahead the value prompt is designed to do.

Chain of thought with an oracle choosing the best of 100 samples scores 49% on Game of 24, while Tree of Thoughts at b = 5 scores 74%. Why can a method with an oracle over 100 attempts still lose?

Show answer

The oracle can only choose among complete chains, and most chains are doomed by their first equation; about 60% fail at step one, and extra samples repeat similar early mistakes. Tree of Thoughts evaluates partial states, so it drops a bad first equation before spending the rest of an attempt on it and moves the effort to promising branches.

Which task gains more from depth-first search with backtracking, Game of 24 or a 5×5 crossword, judging by how and when errors show up?

Show answer

The crossword. A wrong word can look fine until a crossing clue several placements later has no valid fill, so the error surfaces deep in the search, and backtracking to undo the bad placement is the remedy. Game of 24 is only three steps deep, and a bad state is usually visible at once from its remaining numbers, so breadth-first pruning at each level is enough.

Where this sits

Reasoning you can prompt, then train

It began as a prompting trick and ended as a training objective. Read in order, the progression from "let's think step by step" to a model trained to.

  1. 1Chain-of-Thought Prompting2022
  2. 2Self-Consistency2022
  3. 3Tree of Thoughts2023
  4. 4OpenAI o12024
  5. 5DeepSeek-R12025

All 110 papers, in 19 ladders →

Tree of Thoughts: Deliberate Problem Solving with Large Language Models · Yao, Yu, Zhao, et al. · Princeton / Google DeepMind · 2023 · read the original paper on arXiv → · Vibe Engines · 2026
Finished this one? 0 / 110 Paper Breakdowns done
NextOpenAI o1 Next on the “Reasoning you can prompt, then train” ladder · rung 4 of 5

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns