Skip to main content
ai tree of thought prompt

How to write a tree of thought prompt

With current LLMs, your best chances to get the model to think deeper is to use chain-of-thought (CoT) techniques, which in the simplest of cases is asking the model to “take its time”.

But with more advanced prompting techniques, like Tree-of-Thought (ToT) it takes it a step further and essentially ‘forces’ the LLM into exploring the realm of possible answers to any given prompt.

Tree of Thought (ToT)

Creating a prompt for the Tree of Thought (ToT) framework consists of breaking down a problem into smaller components, guiding the language model to generate and evaluate potential solutions, and selecting the most promising option to move forward. Follow these steps to craft a ToT prompt:

Define the problem statement:

 Begin with a clear description of the problem to be addressed. Ensure that the objective is concise, accurate, and comprehensible. Example: You are given four integers and asked to find a combination of addition, subtraction, multiplication, and division operations that result in a target number, specifically 24.

Determine the thought decomposition:

Decide how to divide the problem into smaller, manageable steps. Identify the types of intermediate thoughts that may contribute to the overall solution. Example: Three intermediate equations connecting the four integers in a logical manner.

Formulate the 'think' step: 

Guide the language model to generate potential intermediate thoughts by posing a series of questions or requests. Encourage the model to produce diverse and innovative ideas. Example: Generate three intermediate equations using the given integers, taking advantage of basic arithmetic operations (+, -, *, /). Make sure that each equation includes two of the integers, ultimately leading to a total of six involved integers.

Develop the 'evaluate' step:

 Design a method for the language model to assess the quality and relevance of the generated intermediate thoughts. Use a scoring scheme or classification criteria to rank the possibilities. Example: Classify each generated intermediate equation as definitely useful, maybe useful, or clearly irrelevant regarding obtaining the target number. Assign a score to each classification category—say, 1, 0.5, or 0 points, respectively. Calculate the weighted sum of scores for each group of three equations.

Create the 'select' step:

 Direct the language model to choose the highest-scoring sets of intermediate thoughts and construct a complete solution based on those elements. Example: Select the three sets of equations with the highest scores. Combine these equations in a single expression, taking care to preserve the appropriate order of operations. Verify whether the combined expression yields the desired target number, 24.

I created a Tree of Thought prompt generator on HuggingFace, here to try out. 

Putting everything together, you get a complete Tree of Thought prompt:

PROMPT: Consider the following problem: You are given four integers and asked to find a combination of addition, subtraction, multiplication, and division operations that result in a target number, specifically 24. Divide the problem into three intermediate equations, each containing two of the given integers and utilizing basic arithmetic operations (+, -, *, /). Now, generate three groups of these intermediate equations, attempting to maximize the chance of arriving at the target number. Evaluate the quality of each generated group by assigning a score: 1 point for definite utility, 0.5 points for uncertain utility, and 0 points for no utility. Sum the scores for each group of equations. Choose the top three sets of equations based on these calculated scores. Construct expressions combining these selected equations, preserving the proper order of operations. Check whether the resulting expressions yield the target number, 24.

This detailed prompt instructs the language model to apply the ToT framework, promoting structured and purposeful problem-solving. Remember to adjust the prompt based on the complexity of the problem and the intended outcome.