Tree of Thoughts implements deliberate LLM reasoning via generate, score, and search steps. It ships in the Swarms framework as TreeOfThoughts with BFS or DFS exploration.
Overview
Tree of Thoughts (ToT) is an approach where a language model proposes multiple next steps, evaluates them, prunes weak branches, and backtracks when a reasoning path fails. The packaged TreeOfThoughts agent in Swarms implements that loop for tasks that benefit from search rather than a single chain-of-thought pass.
Each step generates candidate thoughts with propose or sample strategies, scores them with value or vote evaluation, and explores the tree using breadth-first beam search or depth-first search with a value threshold. Model calls use function calling validated against Pydantic schemas, and concurrent calls run at the same tree level. run(task) returns a final answer while lastresult retains the full search trace.
Configuration covers model name via LiteLLM, search depth and breadth, number of thoughts per node, evaluation samples, expansion limits, and custom thought or evaluation prompts. Examples span puzzles, physics word problems, logic grids, and math exercises with documented expected answers. Prompt-only expert templates are listed for use without code.
Setup expects an API key in a .env file loaded by Swarms and a model that supports function calling. Cost grows with thoughts, breadth, depth, and evaluation samples; maxexpansions can cap spending.
Key features
- BFS and DFS search algorithms
- Propose and sample generation modes
- Value and vote candidate scoring
- Function-calling validated tree steps
- Concurrent per-level model calls
- Configurable depth, breadth, thresholds
- Swarms TreeOfThoughts agent class
- Standalone prompt templates included
Use cases
- Multi-step puzzles and logic tasks
- Structured math and physics problems
- Deliberate LLM planning workflows
- Experimenting with ToT hyperparameters