A community-curated open-source library of prompts for AI chat models, with a website, CSV/Hugging Face datasets, CLI and MCP server integration.
kyegomez/tree-of-thoughts
A Python implementation of Tree of Thoughts, which lets LLMs solve problems by searching over candidate reasoning steps instead of answering in one pass.
- Stars
- 4,594
- Forks
- 373
- Open issues
- 8
- Last commit
- last month
What is it?
Tree of Thoughts makes a language model reason by search. It proposes several candidate next steps, scores each one, prunes weak branches, and backtracks when a line of reasoning fails. This repository ships the TreeOfThoughts class, which now lives in the Swarms framework, and runs breadth-first or depth-first search over partial solutions.
Each model output is a function call validated against a Pydantic schema, and calls at the same tree level run concurrently. Users set the thought description, evaluation criteria, search algorithm, beam width, depth and value threshold to fit their task. Any LiteLLM model that supports function calling can be used, and the full search tree is available as JSON after a run.
The repository includes examples in Game of 24, physics calculations, logic puzzles and mathematical problems, each with an expected answer. It also includes prompt templates for getting similar multi-expert reasoning from a chat model without code.
Key features
- 01Breadth-first and depth-first search over reasoning steps, with backtracking and pruning.
- 02Value and vote evaluation of candidate steps.
- 03Configurable branching factor, depth, beam width and score threshold.
- 04Works with any LiteLLM model that supports function calling.
- 05Returns the full search tree as JSON-serializable data.
Use cases
- Solving multi-step arithmetic or puzzle problems where a single model pass often fails.
- Exploring planning or scheduling options by keeping several partial solutions alive.
- Running case analysis that needs backtracking when a branch contradicts itself.
- Evaluating reasoning quality on math or logic benchmarks with checkable answers.
Quick start
- 1
Install the swarms package
pip3 install -U swarms - 2
Add your API key to a .env file in your working directory
- 3
Run the Quickstart Python code using TreeOfThoughts
python examples/physics/hohmann_transfer.py
Things to know
- Requires an API key from a model provider that supports function calling.
- Multi-branch search makes many model calls, so cost grows quickly with settings like breadth and depth.
- Tree of Thoughts now ships inside the larger Swarms framework, which adds a sizable dependency.
In collections
Topics
FAQ
- What is tree-of-thoughts?
- A Python implementation of Tree of Thoughts, which lets LLMs solve problems by searching over candidate reasoning steps instead of answering in one pass. Tree of Thoughts makes a language model reason by search. It proposes several candidate next steps, scores each one, prunes weak branches, and backtracks when a line of reasoning fails. This repository ships the TreeOfThoughts class, which now lives in the Swarms framework, and runs breadth-first or depth-first search over partial solutions.
- Is tree-of-thoughts free to use? What license does it have?
- tree-of-thoughts is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is tree-of-thoughts still maintained?
- Updated within 6 months. The last commit to tree-of-thoughts was on Sep 29, 2026.
- What can I use tree-of-thoughts for?
- Solving multi-step arithmetic or puzzle problems where a single model pass often fails. Exploring planning or scheduling options by keeping several partial solutions alive. Running case analysis that needs backtracking when a branch contradicts itself. Evaluating reasoning quality on math or logic benchmarks with checkable answers.
- How do I install tree-of-thoughts?
- Install the swarms package: pip3 install -U swarms Add your API key to a .env file in your working directory Run the Quickstart Python code using TreeOfThoughts: python examples/physics/hohmann_transfer.py
- Where can I get tree-of-thoughts?
- The source code and installation instructions are on GitHub: https://github.com/kyegomez/tree-of-thoughts
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A vectorless RAG engine that builds a hierarchical tree index of long documents and lets an LLM reason through it to retrieve answers.
A Python framework that benchmarks LLMs by having them play the Bulls and Cows code-breaking game through LiteLLM-compatible providers.
A PyTorch-based deep learning framework that automates training loops, multi-GPU scaling and engineering boilerplate while keeping full control of model code.
A suite of developer tools for building, testing, evaluating and deploying LLM-based applications, with a VS Code flow designer and a pf CLI.
AutoGPT is an open-source platform for building, running, and scheduling AI agents that carry out multi-step workflows from plain-English descriptions or a visual builder.