Ultralytics YOLO27:
License YOLO
Back to Ultralytics Glossary

Tree of Thoughts (ToT)

Tree of Thoughts (ToT) has an LLM propose several next reasoning steps, score them, and search the resulting tree, backtracking from dead ends.

Tree of Thoughts (ToT) is a prompt engineering framework in which a large language model (LLM) solves a problem by searching a tree of partial solutions. At each step, the model proposes several candidate next steps, called thoughts, rates how promising each resulting state is, and a search algorithm decides which branches to expand, keep, or abandon. Where chain-of-thought prompting commits to one line of reasoning from the first token, ToT can look ahead and backtrack. Shunyu Yao and colleagues at Princeton University and Google DeepMind introduced it in Tree of Thoughts: Deliberate Problem Solving with Large Language Models, presented at NeurIPS 2023, and Jieyi Long proposed a similar tree-search system for solving Sudoku with an LLM in the same month. On the Game of 24 puzzle, ToT raised GPT-4's success rate from 4% with chain-of-thought prompting to 74%.

How Tree of Thoughts Works#

Yao et al. define ToT through four design choices:

  • Thought decomposition: What one step is. In Game of 24, a thought is one equation; in creative text generation, a plan for the passage; in a crossword, one word to place.
  • Thought generator: How candidates are produced. The model either samples several thoughts independently, which suits open-ended steps, or proposes a list of distinct options in one prompt, which avoids duplicates when the choices are constrained.
  • State evaluator: How progress is judged. The model rates each state on its own, for example as "sure", "maybe", or "impossible" to reach the goal, or votes for the best of several states. These ratings serve as the search heuristic, a role filled by a hand-written scoring function in classical search.
  • Search algorithm: How the tree is explored. Breadth-first search keeps the best b states at each level, and depth-first search follows the most promising branch, prunes states the evaluator rules out, and backtracks.

Example: Game of 24#

Game of 24 gives four numbers that must be combined with +, -, x, and / to make 24, using each number once. ToT splits the solution into three steps, each an equation that merges two numbers. For the input 4 9 10 13, a propose prompt lists candidates such as:

13 - 9 = 4 (left: 4 4 10)
10 - 4 = 6 (left: 6 9 13)
4 + 9 = 13 (left: 10 13 13)
4 x 13 = 52 (left: 9 10 52)

The value prompt then asks whether each remaining set can still reach 24. "4 4 10" is sure, since (10 - 4) x 4 = 24, as is "6 9 13", since (13 - 9) x 6 = 24, while "10 13 13" and "9 10 52" are impossible, so search expands only the first two branches. Following the first gives 10 - 4 = 6 (left: 4 6), then 4 x 6 = 24.

In the paper's experiments on 100 hard games, breadth-first search kept the 5 best states per step, with each state rated three times. ToT with GPT-4 solved 74% of games, compared with 7.3% for direct prompting, 4.0% for chain-of-thought, and 9.0% for chain-of-thought with self-consistency. Even the best of 100 sampled chains of thought reached only 49%, and ToT keeping a single state per step reached 45%.

Where Tree of Thoughts Fits#

ToT helps on problems where early choices constrain later ones and a wrong first step is hard to repair: puzzles, planning, and multi-step math. In 5x5 mini crosswords, depth-first ToT with pruning filled 60% of words correctly and solved 4 of 20 games. The price is computation: every level of the tree costs several generation and evaluation calls, so a single answer can take dozens of model calls or more and many more tokens than one chain, with matching inference latency.

The same generate, evaluate, and expand loop appears at a much coarser grain in automated experiment search, such as hyperparameter tuning. In Ultralytics Platform AutoTrain, Ask AI can train several Ultralytics YOLO models that differ in one setting, such as image sizes of 640, 800, and 960, compare the finished runs by validation mAP50-95, and propose the next experiment from the best result.

  • Chain-of-thought prompting: A single path of reasoning, equivalent to a tree with one branch per level.
  • ReAct prompting: Interleaves reasoning with actions in an outside environment, such as searches or tool calls, and moves forward on what those actions return. ToT searches over the model's own candidate thoughts.
  • Self-consistency: Samples several complete chains and takes a majority vote on the final answers, without judging partial steps along the way.
  • Graph of Thoughts: Generalizes the tree to a graph in which thoughts can also be merged and refined, and reported 62% better sorting quality than ToT at over 31% lower cost.
  • Monte Carlo tree search (MCTS): The search algorithm behind AlphaGo, which balances exploring new branches against exploiting good ones and can replace breadth- or depth-first search over thoughts.
  • Reasoning models: Trained with reinforcement learning to write long reasoning traces in a single generation, where ToT gets branching and backtracking from an external search program around an ordinary model.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning