Prompt Engineering

How Tree of Thoughts Prompting Works (Explained)

Learn how Tree of Thoughts (ToT) prompting helps AI create better and more creative solutions.

Robert Youssef13 min
How Tree of Thoughts Prompting Works (Explained)
On this page

What Is Tree of Thought Prompting?

Tree of thought (ToT) prompting has the model work a problem the way you'd work through a hard decision. It proposes several possible next steps, judges each one, drops the weak ones and continues from the best. Chain of thought follows a single line of reasoning to the end. ToT keeps a few lines alive at once and can back up when one runs into a dead end.

The method comes from a 2023 paper by researchers at Princeton and Google DeepMind. On the Game of 24 math puzzle, GPT-4 with chain-of-thought prompting solved 4% of tasks, while tree of thoughts solved 74%. In a chat window you can run a lighter version with a single prompt, and there's one to copy further down this page.

Key takeaway:

How Tree of Thoughts Prompting Works

1. ToT Prompting: Enhances AI by exploring and refining multiple ideas.

2. Expert Development: Created by Princeton and DeepMind researchers.

3. Creative Solutions: Generates diverse and accurate responses.

4. Versatile Use: Effective in marketing, content creation, and customer service.

5. Structured Steps: Follow clear steps to create effective ToT prompts.

Imagine you’re planning a surprise birthday party for your best friend. 

You start with a basic idea: a small gathering at a local park. 

But as you think about it more, you consider other options—a fancy dinner at a restaurant, a themed party at home, or even a weekend getaway. 

Each idea leads to more specific thoughts about decorations, guest lists, and activities. 

You weigh the pros and cons, discarding some ideas while developing others further, until you arrive at the perfect plan: “a themed party at home” (my choice though).

This process of exploring multiple ideas and refining them is similar to a technique called Tree of Thoughts (ToT) prompting, used to enhance AI’s decision-making. 

Introduced by researchers from Princeton and DeepMind, ToT helps AI evaluate multiple paths and reconsider previous options when needed, much like planning the birthday party.

Grab a cup of coffee as I show you how the Tree of Thoughts method works, why it’s effective, and how you can implement it.

I’ll break down the key findings from the original research, share insights on its practical application, and even provide a ready-to-use template that you can try out yourself.

By understanding and using the ToT method, you’ll be able to craft prompts that lead to better and more reliable AI outputs. 

Our goal is to provide you with clear, actionable advice based on real-world usage, ensuring you can improve your AI interactions with ease. 

Enough with the talk, let’s jump into the details;

ALSO READ: How to Optimize Long Prompts for Better AI Results

How Tree of Thoughts Prompting Works

Supercharge your Marketing with 100+ Mega-Prompts for ChatGPT!

Understanding Tree of Thoughts Prompting

Tree of Thoughts (ToT) prompting is a technique designed to make AI’s decision-making process more effective. 

Developed by researchers at Princeton and DeepMind, it allows AI to explore multiple ideas at the same time, similar to how people think. 

Instead of following one line of thought, ToT prompting creates several branches, each representing a different possibility. 

By evaluating each branch, the AI can find the best solution. 

The paper's biggest gains came on puzzles that need planning and backtracking, and its authors recommend ToT for tasks where chain-of-thought prompting struggles. 

30% in generating creative and accurate responses
30% in generating creative and accurate responses

ToT prompting helps in producing high-quality outputs by considering a wider range of options.

For example, when humans plan a vacation, they consider various destinations, activities, and accommodations. 

They consider the pros and cons of each option before making a final decision. 

Similarly, AI using ToT prompting can generate multiple responses to a query, evaluate each one, and select the best answer.

Another example is writing a marketing campaign.

Humans brainstorm different strategies, such as social media ads, email campaigns, and influencer partnerships. 

Each idea is considered, and the most effective strategies are chosen. 

AI with the help of ToT prompting can generate various marketing strategies, evaluate their potential success, and suggest the most effective ones.

How The TOT Mechanism Works

For you to get the whole concept of this prompt, I will explain the concepts of how it works.

ToT prompting structures the AI’s thought process like a tree. 

Here’s the concept; It begins with one idea and branches out into multiple potential responses. 

Each branch represents a different approach or perspective. 

The AI evaluates these branches, developing the most promising ones further and discarding less relevant ideas. 

This ensures that the AI looks at a wide range of possibilities, leading to more thorough and well-rounded outputs.

For instance, when humans brainstorm solutions to a problem, they might list various ideas and then evaluate each one. 

Some ideas are discarded while others are developed further, leading to the best solution. 

That’s exactly how an AI using ToT prompting generates multiple responses to a query, evaluates each one, and develops the most promising responses further.

The Four Parts of the Original Method

In the paper, setting up tree of thoughts for a task means answering four questions:

  1. Thought decomposition. How big is one step? In Game of 24 a "thought" is one line of equation. In the paper's creative writing task it's a whole paragraph-long writing plan.
  2. Thought generator. The model either samples several candidate steps independently or proposes a short list of them in one go.
  3. State evaluator: the model judges each partial solution, with a score from 1 to 10, a label such as sure, likely or impossible, or a vote across the options.
  4. Search algorithm. Breadth-first search keeps the few best states at every step. Depth-first search follows the most promising path until the evaluator says it can't succeed, then backs up and tries the next one.
Tree of thought prompting as a tree: one problem, three candidate first steps rated sure, likely and impossible, the impossible branch cut, the best branch continuing to an answer

So the full method is a program, and a single chat message can't reproduce it. Code calls the model many times, stores the tree and decides which branch to grow next. The authors published theirs on GitHub. It isn't cheap either: by the paper's own estimate, ToT can need 5 to 100 times more generated tokens than chain of thought.

Benefits of Tree of Thoughts Prompting

Tree of Thoughts prompting has many advantages. Here are five key benefits:

1. Creates Creative Ideas: By looking at many ideas at once, AI can come up with more creative and different responses. 

This approach helps the AI explore many solutions, leading to unique and innovative answers that might not come up with just one line of response.

2. Gives More Accurate Answers: ToT prompting helps AI give more accurate answers by considering different options. 

It checks multiple responses to make sure the final answer is the best and most relevant one, making the AI’s output more reliable.

3. Makes Responses Clearer: AI can go back and improve its ideas, making its answers clearer. 

This means refining and revisiting thoughts to make them more understandable and well-organized, resulting in clear and easy-to-read responses.

4. Helps in Making Better Choices: By carefully looking at different options, ToT prompting helps AI make better choices. 

It thinks about the good and bad points of each option, leading to more informed decisions that take more factors into account.

5. Solves Problems Better: AI can handle complex problems better by looking at many solutions. 

ToT prompting lets the AI break down problems into smaller parts, look at each possible solution, and pick the best one, making problem-solving more effective.

Next, let’s see how Tree of Thoughts prompting compares to other other forms of prompts.

ToT vs Other Prompting Methods

Tree of Thoughts (ToT) prompting is different from other methods. 

Here’s how:

1. Explores Many Ideas:

Explores Many Ideas
Explores Many Ideas

Traditional methods follow one idea at a time, but ToT looks at many ideas at once. 

For example, if an AI is asked to come up with marketing strategies, ToT will generate multiple different strategies instead of just one. 

This helps find the most creative and effective solution.

2. Checks and Improves Ideas:

ToT lets the AI check and improve several ideas. 

For instance, if AI is writing a customer service reply, it will look at different ways to respond and pick the best one. 

Other forms of prompting might not check as many options, leading to less accurate answers.

3. Flexible Approach:

flexibility approach graph
flexibility approach graph

ToT can change direction by looking at different ideas, making it more flexible.

If one idea isn’t working, it can quickly switch to another. 

While other forms of prompting might stick to one idea even if it’s not the best.

4. Goes Deeper:

ToT looks deeply into each idea, making them better. 

For example, if AI is creating a content plan, ToT will refine each idea to make sure it’s detailed and useful. 

Other methods might only touch on the surface of each idea.

5. Better Decisions:

better decision graph
better decision graph

By looking at many options, ToT helps AI make better choices. 

For example, when planning a project, it considers all possible approaches before deciding on the best one. 

Other methods might not consider as many options, leading to less informed decisions.

Tree of Thought vs Chain of Thought

Tree of thought builds on chain of thought. Inside each branch the model still reasons step by step; ToT adds the branching, the scoring and the option to go back. If you haven't used the simpler technique yet, start with chain of thought prompting and come back when one line of reasoning isn't enough.

Chain of thought Tree of thoughts (the paper) One-prompt ToT
What the model does Reasons step by step along one path Proposes several next steps, rates them, searches the tree Writes as several "experts" who reason in turns and drop out when they're wrong
Model calls One Many, run by a program One
Can back out of a dead end No Yes Partly: a wrong expert leaves
Cost Lowest 5 to 100 times the generated tokens of chain of thought, per the paper One long answer
Where it fits Math, logic, explanations Puzzles and plans that need lookahead Decisions and brainstorming in ChatGPT, Claude or Gemini

A Tree of Thought Prompt Example You Can Paste

The one-message version that spread in 2023 is Dave Hulbert's, published under the MIT license in his tree-of-thought-prompting repository. Paste it, then add your question after the last line:

Imagine three different experts are answering this question.
All experts will write down 1 step of their thinking,
then share it with the group.
Then all experts will go on to the next step, etc.
If any expert realises they're wrong at any point then they leave.
The question is...

For business decisions we adapt it. The experts get roles that pull in different directions, and each round ends with a rating borrowed from the paper's state evaluator:

Three experts are solving the problem below: a pricing analyst, an operations manager and a customer support lead.
Each expert writes one step of their thinking, then shares it with the group.
After each round, every expert rates the other two experts' latest steps as sure, likely or impossible, with one line of reasoning.
An expert whose step is rated impossible by both others leaves.
Continue until one path reaches a recommendation. Then give the recommendation, the path that led to it and the biggest risk left.

Problem: [the decision, the numbers you have, the deadline]

Know what this is. The three experts are the same model writing in turns, inside one answer, so it's a structured brainstorm rather than a real search. Read the result the way you'd read any other answer and check the numbers yourself.

Our Experiment: ToT Prompt for ChatGPT 

We did an experiment where ChatGPT AI used Tree of Thoughts (ToT) prompting to come up with creative marketing ideas for promoting new cat toys. 

The goal was to think of unique and engaging ways to attract cat owners.

Checkout our prompt and ChatGPT response.

ToT Prompt

Act like a marketer who needs to promote a new line of cat toys. In a table think of 3 fun and creative marketing stunts to catch the attention of cat owners and get them to buy these toys. Use 3 different platforms and methods to reach your target audience. Generate 3 ideas and check their potential impact, cost, and engagement. While doing this, come up with three ideas, check each one for how effective it might be, how much it will cost, and how engaging it will be. Go back and improve each idea to make the marketing strategies clearer and more organized. Carefully look at the pros and cons of each marketing stunt. Break down the marketing challenge into smaller parts, look at each possible solution, and pick the best one based on your findings.

What to Note

In this section, we analyze our ToT prompt for chatGPT and explain how you can create similar prompts.

1. Define the Role: Ask the AI to act like a specific professional, in this case, a marketer. 

This sets the context for the type of ideas the AI should generate.

Example: “Act like a marketer who needs to promote a new line of cat toys.”

2. Specify the Task: Clearly state the task, such as promoting a new line of cat toys. 

This helps focus the AI’s responses on the specific goal.

Example: “Think of fun and creative marketing stunts to catch the attention of cat owners and get them to buy these toys.”

3. Encourage Creativity: Ask for a range of ideas to ensure the AI explores multiple possibilities

Example: “Use three platforms and methods to reach your target audience. 

Generate three ideas and check their potential impact, cost, and engagement.”

4. Evaluate Ideas: Include a step to check each idea for impact, cost, and engagement.

This helps in refining and selecting the best strategies.

Example: “While doing this, come up with three ideas, check each one for how effective it might be, how much it will cost, and how engaging it will be.”

5. Detail the Plan: Ask the AI to go back and improve each idea to make the strategies clearer and more organized.

Example: “Go back and improve each idea to make the marketing strategies clearer and more organized.”

6. Solve the Challenge: We broke down the marketing challenge into smaller parts, for the AI tool to look at each possible solution, and pick the best one.

Example: “Break down the marketing challenge into smaller parts, look at each possible solution, and pick the best one based on your findings.”

By following these steps, you can create your own ToT prompts to generate creative and effective solutions for various tasks with ChatGPT 

Winding Down: How Tree of Thoughts Prompting Works

Tree of Thoughts (ToT) prompting is a powerful technique that enhances AI’s ability to generate creative, accurate, and well-organized solutions. 

By exploring multiple ideas simultaneously and refining each one, ToT prompting helps AI make better decisions and solve problems more effectively. 

By following the structured approach of defining the role, specifying the task, encouraging creativity, evaluating ideas, detailing the plan, and solving the challenge, you can create your own ToT prompts to achieve outstanding results in various tasks.

This method not only makes AI outputs more reliable and creative but also ensures that the solutions are well-thought-out and practical as demonstrated in our experiments with ChatGPT.

Feel free to try out ToT prompting in your projects and experience the benefits firsthand.

Tree of Thought Prompting FAQ

What is a tree of thought prompting example?

The three-experts prompt above is the one people copy. In the paper's own example, Game of 24, every step proposes one equation using the remaining numbers, and the model rates whether 24 can still be reached from there.

Does tree of thought work in ChatGPT?

Yes, the one-prompt version. The full method needs code that calls the API many times.

Is tree of thought the same as self-consistency?

They're related. Self-consistency samples several complete chain-of-thought answers and keeps the answer they agree on most. Tree of thoughts compares partial solutions at every step, which lets it abandon a bad path halfway instead of finishing it. The ToT paper itself calls its voting step similar in spirit to a step-wise self-consistency, so if you already run self-consistency in a pipeline, ToT is the next step up in cost and control.

Prompts for this topic

Put this article to work with ready-to-use prompts from the God of Prompt library.

Keep reading

The best of the blog, in your inbox

One email when notable prompts, tools, and model updates land. No spam, unsubscribe anytime.

Join 100,000+ subscribers. One email a week, real prompts, tools, and model updates. Unsubscribe anytime.