Introduction to the Tree of Thoughts Project
Overview
Tree of Thoughts (ToT) is a cutting-edge algorithm designed to enhance model reasoning. This tool is integral for those who wish to improve the decision-making and problem-solving capabilities of their AI models by up to 70%. With its user-friendly interface, ToT can be easily integrated with existing models to unlock superintelligence.
Getting Started
To start using the Tree of Thoughts algorithm, you only need to install it with a simple command:
$ pip3 install -U tree-of-thoughts
Configuration Requirements
Before getting started, ensure that you have the following variables set up in your .env
file:
WORKSPACE_DIR="artifacts"
OPENAI_API_KEY="your_openai_api_key"
These settings will enable the full functionality of the ToT algorithm.
Example Usage
The usage of the Tree of Thoughts algorithm revolves around flexible agents known as TotAgent
and ToTDFSAgent
. Here's a quick example to demonstrate how these components can be used:
-
Initialize the Environment:
- Load environment variables using
load_dotenv()
. - Instantiate a
TotAgent
.
- Load environment variables using
-
Define the Problem and Agent Parameters:
- Set up a
ToTDFSAgent
with a custom threshold for thought evaluation, maximum loops, and pruning parameters.
- Set up a
-
Problem Solving:
- Define an initial state that the algorithm will solve, such as using numbers and basic operations to achieve a specific goal.
- Run the Depth-First Search (DFS) algorithm and print the result in JSON format for clarity.
Here is a snippet of the Python code for this:
from tree_of_thoughts import TotAgent, ToTDFSAgent
from dotenv import load_dotenv
load_dotenv()
tot_agent = TotAgent(use_openai_caller=False)
dfs_agent = ToTDFSAgent(
agent=tot_agent,
threshold=0.8,
max_loops=1,
prune_threshold=0.5,
number_of_agents=4,
)
initial_state = "Your task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math"
final_thought = dfs_agent.run(initial_state)
print(final_thought)
Basic Prompts
Tree of Thoughts also supports complex reasoning scenarios, enabling multiple "experts" to solve problems collaboratively. These experts share and refine their thought processes through a structured table format using markdown. The prompts are designed to simulate a multi-step, collaborative reasoning process, enhancing the AI's ability to reach consensus on complex queries.
Future Enhancements and Features
The project team has a rich roadmap that includes:
- Completing the depth or max loops feature in the DFS class.
- Finalizing a new Breadth-First Search (BFS) algorithm.
- Implementing a Monte Carlo search algorithm.
- Developing a visual tool to convert JSON data into a visual tree of thoughts.
Acknowledgements
The project extends gratitude to researchers from Princeton University and Google DeepMind, whose insights and collaborations have been instrumental in developing the Tree of Thoughts algorithm. Special thanks also go to Phil Wang and Lucidrains for their inspirational contributions to open-source AI research.
Licensing
The Tree of Thoughts algorithm is distributed under the Apache license, promoting innovation and collaboration within the open-source community.