gitmyhub

tree-of-thoughts

Python ★ 4.6k updated 10mo ago

Plug in and Play Implementation of Tree of Thoughts: Deliberate Problem Solving with Large Language Models that Elevates Model Reasoning by atleast 70%

Tree of Thoughts is a Python package that implements a reasoning technique for large language models developed by researchers at Princeton University and Google DeepMind. The idea is that instead of asking an AI to answer a question in one straight pass, you have it generate and evaluate multiple chains of reasoning simultaneously, like a tree with many branches. The system scores each branch and prunes weak ones, focusing effort on the most promising lines of thought. The repository's description claims this improves reasoning accuracy by up to 70%.

To use it, you install the package with pip and provide an OpenAI API key through an environment file. The core objects are TotAgent, which manages the language model calls, and ToTDFSAgent, which runs a depth-first search through the reasoning tree. You set parameters for how strictly to prune low-quality branches, how many reasoning agents to run in parallel, and how many loops to allow. The README shows an example solving a classic puzzle: combine four numbers with basic arithmetic to reach 24.

For people who do not want to write code, the README also lists plain prompt templates you can paste into any chat interface. These prompts instruct the AI to behave as three experts debating a problem step by step, which approximates the tree-of-thoughts approach without any programming.

The project is an independent open-source implementation based on the original academic paper. The README notes it is still in progress: breadth-first search and Monte Carlo search variants are listed as to-do items, and a visualization feature for the reasoning tree is also planned. The license is Apache 2.0.