Home › Prompt Engineering › Tree-of-Thoughts (ToT)
✍️ · Ground

Tree-of-Thoughts (ToT)

Tree-of-Thoughts explores many reasoning branches, scores them, and expands the most promising paths.

In one line

Instead of committing to one chain of reasoning, ToT branches into several candidate thoughts, evaluates each, and searches the resulting tree for the best path to a solution.

ConceptWhat it is

Tree-of-Thoughts (ToT) is a reasoning technique that generalizes Chain-of-Thought from a single linear trace into a branching search tree. Each node is a partial thought — an intermediate step toward the answer — and the model deliberately generates several candidate next-steps from any node instead of committing to the first one it produces.

It exists because many problems cannot be solved in one forward pass: they need exploration, lookahead, and backtracking. ToT layers two ingredients on top of the generator — a state evaluator that scores how promising each partial solution is, and a search algorithm (typically breadth-first or depth-first) that decides which branches to expand and which to abandon. This turns the model into a deliberate problem-solver rather than a one-shot guesser.

How it worksThe mechanics

You decompose the task into discrete thought steps, then loop: from the current frontier of partial solutions the model proposes multiple candidate next-thoughts (the branching factor), a separate evaluation prompt scores or ranks each candidate — often as a value estimate or a vote across samples — and the search policy keeps the top-k states, prunes the rest, and expands the survivors one level deeper. The cycle repeats until a branch reaches a complete, validated answer or the depth budget is exhausted, at which point the best-scoring path is returned.

At a glanceSee it

Tree-of-Thoughts (ToT) diagram
Tree-of-Thoughts (ToT) diagram 1

The two classic ways to walk the tree — breadth-first, which keeps a fixed-width beam of the best states, or depth-first, which dives down one branch and backtracks out of dead ends.

Tree-of-Thoughts (ToT) diagram 2

Opening up the generate and evaluate boxes the main loop treats as atomic — generation can sample independent thoughts or propose distinct next steps, and evaluation can score each state by value or rank a set of them by vote.

When to use itWhere it fits

  • Problems with a large solution space that reward search and lookahead, such as puzzles, games, and constraint satisfaction.
  • Multi-step planning where early choices must be revisited, so backtracking pays off.
  • Tasks with a cheap, reliable way to score partial progress, so branches can be compared and ranked.
  • High-value, low-volume queries where accuracy matters far more than latency or cost.

When NOT to use itLimits & anti-patterns

  • Simple factual or single-step tasks where plain prompting or Chain-of-Thought already suffices.
  • Latency- or cost-sensitive paths — the many extra model calls make it slow and expensive.
  • Problems with no meaningful way to evaluate a partial state, since the search then has nothing to steer by.
  • High-throughput production endpoints where predictable spend and response time dominate.

Trade-offsAdvantages & costs

Advantages
  • Materially higher success on search- and planning-heavy problems than linear Chain-of-Thought.
  • Explicit backtracking recovers from a bad early step instead of being stuck with it.
  • The tree and its per-node scores are inspectable, making the reasoning process easier to debug.
  • Tunable knobs — branching factor, depth, and top-k — trade cost against thoroughness.
Trade-offs & costs
  • Many model calls per query: cost and latency scale with branching factor times depth.
  • Needs a good evaluator; a noisy scorer confidently sends the search down wrong branches.
  • Orchestrating generation, scoring, and search state is complex to build and tune.
  • Diminishing returns on tasks that lack real search structure to exploit.

ExampleIn the real world

Consider the Game of 24 puzzle: given the numbers 4, 9, 10, and 13, combine them with arithmetic to reach exactly 24. A single Chain-of-Thought often commits early to a bad first operation and fails. With ToT, the model proposes several possible first steps — for example 13 minus 9 equals 4, or 10 minus 4 equals 6 — each becoming a branch that carries the remaining numbers forward. An evaluator labels every partial state as sure, likely, or impossible to reach 24, the search keeps the promising branches and prunes the rest, then expands the survivors with the next operation. Exploring a handful of branches to a depth of three steps reliably finds a valid expression where a single linear pass frequently does not.

ToolsHow to implement it

  • tree-of-thought-llmthe Princeton NLP reference implementation from the original paper, including the Game of 24 and crosswords tasks.
  • LangGraphmodels the branch, evaluate, and backtrack loop as an explicit graph, a natural fit for orchestrating ToT search.
  • LlamaIndexand LangChain — provide agent and query-engine scaffolding on which tree-search strategies can be layered.
  • DSPylets you declare and optimize the generate-and-evaluate modules instead of hand-tuning every prompt.

Cost & effortWhat it takes

ToT is one of the most expensive prompting patterns: a run issues roughly branching-factor times depth generation calls plus a scoring call per candidate, so a modest three-wide, three-deep search can mean dozens of model invocations for one answer. Budget accordingly — reserve it for high-value problems, cap depth and breadth, and consider a cheaper model for the evaluator. Engineering effort is moderate-to-high because you must build the search loop, the state representation, and a trustworthy scorer, though libraries like LangGraph reduce the orchestration burden.

A living map of modern AI — kept current every morning