Skip to main content
Prompt Engineering Tutorial
CHAPTER 19 Beginner

Advanced Prompting Frameworks (ReAct, ToT)

Updated: May 14, 2026
20 min read

# CHAPTER 19

Advanced Prompting Frameworks (ReAct, ToT)

1. Introduction

Chain-of-Thought (CoT) prompting taught the AI to think step-by-step. But what if the problem requires the AI to search the internet, test a hypothesis, realize it made a mistake, and try a different path? To achieve autonomous, high-level reasoning, researchers have developed complex Prompting Frameworks. In this chapter, we will explore the bleeding edge of Prompt Engineering: ReAct and Tree of Thoughts (ToT).

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Understand the limitation of linear reasoning in LLMs.
  • Implement the ReAct (Reason + Act) framework for Agentic AI.
  • Explain the Tree of Thoughts (ToT) methodology.
  • Identify when to use advanced frameworks vs. standard prompts.

3. Beginner-Friendly Explanation

Imagine you lose your keys. Standard AI: Guesses immediately. "They are in the car." (Usually wrong). Chain-of-Thought AI: Thinks linearly. "I had them this morning. I walked to the kitchen. Therefore, they are in the kitchen." (Better, but still guessing). Tree of Thoughts AI: Brainstorms multiple paths. "Path 1: Kitchen. Path 2: Bedroom. Let me evaluate Path 1. The kitchen makes sense. Let me evaluate Path 2. I didn't go in the bedroom. I will abandon Path 2 and follow Path 1." ReAct AI: Thinks AND acts. "Thought: I need to find the keys. Action: Walk to kitchen. Observation: Keys are not here. Thought: I was wrong. Action: Walk to car. Observation: Keys found." Advanced frameworks turn the AI from a static text-generator into a dynamic, experimenting scientist.

4. ReAct (Reasoning and Acting)

ReAct is the framework used to build AI Agents (like AutoGPT). It forces the AI into a strict, repetitive loop: Thought, Action, Observation.

The prompt provides the AI with "Tools" (like Google Search or a Calculator).

The ReAct Prompt Loop:

text
1234567891011
Task: What is the exact age of the actor who played Iron Man?

[AI GENERATES:]
Thought: I need to find out who played Iron Man.
Action: Search_Google("Who played Iron Man")
Observation: Robert Downey Jr.
Thought: Now I need to find his age.
Action: Search_Google("Robert Downey Jr age")
Observation: 59 years old.
Thought: I have the answer.
Final Answer: Robert Downey Jr. is 59 years old.

*Why it works:* The AI is fact-checking itself in real-time by interacting with the outside world, completely eliminating factual hallucinations.

5. Tree of Thoughts (ToT)

When a problem requires deep creativity or logic (like writing a complex software algorithm or solving a puzzle), linear thinking fails. Tree of Thoughts forces the AI to brainstorm multiple different solutions, score them, and explore the best ones.

The ToT Prompt Structure:

text
1234
Task: Solve this complex logical puzzle.
Step 1: Brainstorm 3 distinct, different possible ways to solve this. (Generate Path A, Path B, Path C).
Step 2: Act as an expert critic. Evaluate the viability of Path A, Path B, and Path C. Score each out of 10.
Step 3: Discard the lowest scoring paths. Take the highest scoring path and expand it into a final, detailed solution.

*Why it works:* By forcing the AI to critique its own ideas *before* committing to an answer, you simulate high-level human problem-solving.

6. Meta-Prompting (Self-Correction)

A simpler advanced technique is Meta-Prompting, where the AI critiques its own output in a loop.
text
123456
# Prompt 1
Write a Python script to scrape a website.

# Prompt 2
Review the script you just generated. Identify any security flaws, inefficiencies, or syntax errors. 
Output a revised, optimized version of the script.

Never accept the AI's first draft of code. Always pass it through a Meta-Prompting review.

7. Python Example: The ReAct Loop

Developers use loops to execute ReAct. (Note: Frameworks like LangChain automate this entirely).
python
123456789101112131415161718
# Conceptual ReAct Loop
while True:
    # Get AI's next thought/action
    response = call_llm(prompt_history)
    
    if "Final Answer" in response:
        print(response)
        break
        
    elif "Action:" in response:
        # Extract the command (e.g., Search_Google)
        action = extract_action(response)
        
        # Execute the Python tool to search the internet
        observation = execute_tool(action)
        
        # Feed the real-world observation back to the AI
        prompt_history += f"Observation: {observation}\nThought: "

8. Mini Project

The Critic Prompt: You want the AI to write a marketing slogan for a new energy drink. Instead of just asking for a slogan, write a Tree of Thoughts style prompt that asks the AI to generate 3 slogans, critique them based on target audience appeal, and then pick the winner. *(Answer Example: "Task: Write a slogan for an extreme energy drink. Step 1: Generate 3 entirely different slogans. Step 2: Critique each slogan based on its appeal to extreme sports athletes. Identify the weaknesses in each. Step 3: Based on your critique, select the best slogan and refine it into the Final Answer.")*

9. Best Practices

  • Token Awareness: Advanced frameworks (especially ToT) burn through massive amounts of tokens because the AI generates paragraphs of brainstorming and critique before giving the final answer. Use these frameworks *only* for highly complex tasks, not simple requests.

10. Common Mistakes

  • Infinite Loops in ReAct: If an AI Agent is poorly prompted, it might get stuck in an infinite loop (e.g., searching the same Google phrase over and over and getting confused). Developers must implement "Max Iteration" limits (e.g., stop the loop after 5 actions) to prevent the AI from running forever and racking up API bills.

11. Exercises

  1. 1. Explain the difference between linear "Chain-of-Thought" prompting and the branching logic of "Tree of Thoughts."

12. MCQs with Answers

Question 1

What does the "ReAct" prompting framework force the AI to do?

Question 2

Why is the "Tree of Thoughts" (ToT) framework effective for highly complex logical problems?

13. Interview Questions

  • Q: Describe the ReAct framework. How does integrating real-time "Observations" from external tools solve the LLM hallucination problem?
  • Q: In an enterprise environment, when would you justify the high token cost of using a Tree of Thoughts (ToT) prompt architecture over a simple Chain-of-Thought (CoT) prompt?

14. FAQs

Q: Are these frameworks built into ChatGPT? A: The newest models (like OpenAI's "o1") actually have Tree-of-Thoughts and Chain-of-Thought built natively into their architecture! When you ask them a hard math question, they automatically brainstorm and critique themselves invisibly for 10 seconds before showing you the answer.

15. Summary

In Chapter 19, we reached the pinnacle of prompt engineering. By moving past static instructions, we engineered dynamic cognitive architectures. The ReAct framework transforms the AI into an autonomous Agent capable of fact-checking itself via external tools. The Tree of Thoughts framework grants the AI the ability to brainstorm, critique, and self-correct. These advanced frameworks represent the future of software: systems that don't just compute, but reason.

16. Next Chapter Recommendation

You have mastered the curriculum. Now it's time to prove it. Proceed to the final chapter, Chapter 20: Prompt Engineering Interview Questions and Practice, to prepare for the job market.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·