DEV Community

Cover image for Tree of Thoughts: A New Way to Prompt AI
Hamza Ahmed
Hamza Ahmed

Posted on

Tree of Thoughts: A New Way to Prompt AI

What's Tree of Thoughts (ToT) Prompting All About?

ToT prompting is a fresh take on how to work with prompts in AI. Instead of just giving a single question to the AI like in zero-shot prompting, or a list of questions to go through one by one like in chain-of-thought, ToT prompting uses a tree-like set of questions and answers. You can add more branches, cut them off, or go back and change earlier ones as needed.


TOT PROMPT CHART

"The image shows different ways to tackle problems using language models. Each box stands for a thought, which is a complete set of words that helps in solving the problem." credit: https://arxiv.org/pdf/2305.10601.pdf

Why ToT Prompting is Useful

ToT prompting helps the AI come up with multiple and logical solutions. It can also self-improve or get better based on feedback. The research shows that ToT is better than zero-shot and chain-of-thought methods for new tasks that need some planning or searching, like the Game of 24, writing creatively, and solving Mini Crosswords.


ToT Prompting in Creative Writing - A Simple Example

Say you need to write a story about a Mowgli.The ToT prompt could look like this:

1. Write a story featuring Mowgli.   
    *Choice 1: Mowgli is lonely and wants friends.    
    *Choice 2: Mowgli is adventurous and 
      wants to explore the villages.   
    *Choice 3: Mowgli is curious and wants 
      to learn about the human kingdom               
2. Pick one choice and keep writing the story.  
3. Check your story for how creative, clear, 
   and well-written it is.

Enter fullscreen mode Exit fullscreen mode

ToT Prompting for Online Searches - A Simple Example

1. Imagine you're trying to find a good place to go on vacation. 
   Your needs are:
   *Find a good vacation spot. Keep in mind: 
   *Must be in India. 
   *Good for families. 
   *Has fun outdoor activities. 
   *Has interesting historical places. 
   *Summer weather should be bearable.

2. Choices for looking up places: 
   *Choice 1: Look at places in Northern India. 
     *More choices: Himachal Pradesh or Uttarakhand. 
   *Choice 2: Look at places in Southern India. 
     *More choices: Kerala or Tamil Nadu. 
   *Choice 3: Look at places in Western India. 
     *More choices: Goa or Rajasthan.

3. Pick a choice and dig deeper.
4. Compare all the places you found based on your needs.

Here, you can use a 'browser' tool to help you look for
info along the path you chose. The AI can follow a path,  do
the searching, and check how good the options are based on
what you need.  This way of solving problems can give you more
complete and fitting answers. 
Enter fullscreen mode Exit fullscreen mode

Using ToT Prompting with Web-Enabled GPT-4 : An Example

Three experts with exceptional logical thinking and
experienced programming skills are collaboratively answering a
question using a tree of thoughts method. Each expert be allowed
one web search and then use that search data with their own
thought and share process in detail.  Each expert will share their
thought process in detail, taking into account the previous
thoughts of others and admitting any errors.  They will iteratively
refine and expand upon each other's ideas, giving credit where
it's due. The process continues until a conclusive answer is
found.  Use step by step thinking & organize the entire response
in detailed steps in a {{markdown table format}}.  Once this
table is complete, provide a summary of the proposed
recommendations. 
My question is how to learn and get advanced in chess?
Enter fullscreen mode Exit fullscreen mode

You can also give expert a character, example:

1 of the expert is a seasoned digital marketing analyst
with 10 years of experience, the other one is a programmer who
is an optmizing enthusiast,  he strives to follow the beast
practice,  find best design pattern and follow clean code principles
...etc 
Enter fullscreen mode Exit fullscreen mode

You can also fine tune the prompt to make sure when asking the follow-up it dont get data from same article.

the prompt can also be used without internet by removing the below line. [Recommended].

Remember with using GPT-4 with browsing capablity it produce unexpected result and most of the time the results is heavily dependent on the plugin, same question with different plugin will generate different quality content. So use it with caution

Each expert be allowed one web search and then use that
search data with their own thought and share process in detail.
Enter fullscreen mode Exit fullscreen mode

*For the full chat, check *
OFFLINE
ONLINE

To Wrap Up

ToT prompting brings a new layer to how we solve problems. It lets us have a more open and branching chat instead of a straight line of orders. This can make the AI come up with new, smart, and clear answers and lets it get better from feedback. ToT prompting can be used for many things like writing stories, learning stuff, or hard research. It shows how AI can do more than just follow orders; it can actually help us think and make choices.

Top comments (0)