5K

Tree-of-Thought Reasoning

Expands a tree of candidate reasoning steps, scores partial states, prunes weak branches, and picks the best path instead of one linear chain

established Updated 2026-10-13 By Nikola Balic (@nibzard) Based on Yao et al. (2023)
View .md Edit on GitHub
Add to Pack
or

Saved locally in this browser for now.

Cite This Pattern
APA
Nikola Balic (@nibzard) (2026). Tree-of-Thought Reasoning. In *Awesome Agentic Patterns*. Retrieved October 14, 2026, from https://agentic-patterns.com/patterns/tree-of-thought-reasoning
BibTeX
@misc{agentic_patterns_tree-of-thought-reasoning,
  title = {Tree-of-Thought Reasoning},
  author = {Nikola Balic (@nibzard)},
  year = {2026},
  howpublished = {\url{https://agentic-patterns.com/patterns/tree-of-thought-reasoning}},
  note = {Awesome Agentic Patterns}
}

Use when

  • Complex planning, math, or code tasks where the first path often fails
  • A good evaluation function or external verifier exists
  • Task needs explicit backtracking

Avoid when

  • Simple linear tasks
  • Tight latency or token budget (explicit trees cost substantially more tokens than chain-of-thought)

Problem

Linear reasoning commits early to one path and can fail silently when intermediate assumptions are wrong. On complex planning or synthesis tasks, this causes premature convergence, weak recovery from mistakes, and missed alternatives that a broader search would discover.

Solution

Explore a search tree of intermediate thoughts instead of a single chain. Generate multiple candidate continuations, score partial states, prune weak branches, and continue expanding the most promising paths until a stopping condition is met.

This turns reasoning into guided search: backtracking is explicit, branch quality is measurable, and the final answer can be chosen from competing candidates rather than the first trajectory.

The quality of the evaluation function significantly impacts performance—external verifiers (code execution, tests) outperform self-reflection scoring.

queue = [root_problem]
while queue:
    thought = queue.pop()
    for step in expand(thought):
        score = evaluate(step)
        queue.push((score, step))
    prune_weak_branches(queue)
select_best(queue)

How to use it

Apply when tasks benefit from exploring many potential strategies—puzzles, code generation, or planning. Use heuristics or a value function to prune unpromising branches.

Algorithm variants: BFS for exhaustive exploration, DFS for deep paths with limited memory, Beam search for memory-constrained scenarios with good heuristics.

Reasoning-model context (2024-2026): RL-trained reasoning models such as OpenAI's o1 and its successors internalize much of this deliberate search at inference time (Learning to Reason with LLMs). This pushes explicit ToT scaffolds toward verifier-guided work (where an external evaluator still prunes branches) and non-frontier models. See Language Agent Tree Search (LATS) and Inference-Time Scaling.

Trade-offs

  • Pros: Covers more possibilities; improves reliability on hard search tasks (on Game of 24, the paper reports 4% accuracy for chain-of-thought prompting versus 74% for ToT); enables explicit backtracking from failed paths.
  • Cons: Higher compute cost (substantially more tokens than chain-of-thought; the paper does not publish a token multiplier); needs a good evaluation function to guide search; inherently slower latency. Best for complex planning, mathematical reasoning, and code generation—overkill for simple linear tasks.

References