Module 5: ReAct, Self-Consistency, and Advanced Patterns
1. Introduction: Beyond Chain-of-Thought
Overview
Chain-of-Thought (CoT) was a huge leap in prompt engineering: asking the model to "think out loud" dramatically improved its performance on mathematical, logical and multi-step reasoning. But CoT has fundamental limitations that show up the moment you face real-world problems.
This module explores four advanced techniques that get past those limitations:
- ReAct: Combines reasoning with real actions (tool calls)
- Self-Consistency: Generates multiple reasoning paths and votes by consensus
- Tree-of-Thought: Explores branches of solutions like a search tree
- Meta-prompting & Self-Refine: Uses LLMs to optimize and refine their own prompts and answers
Each technique has its ideal use case, its computational cost and its trade-offs. By the end of this module, you'll have a clear framework for deciding which technique to use in each situation.
The Limitations of Chain-of-Thought
Before looking at the solutions, let's understand exactly what breaks in CoT:
1. Internal reasoning only
CoT can only "think" with what it already knows. If a model was trained up to January 2024, it can't know the current price of oil, the result of last night's game, or the status of an order in an online store. There's no connection to the outside world.
# CoT fails here:
"How much does the Madrid-New York flight cost today?"
→ The model will make something up or give outdated prices
# CoT works fine here:
"If one train goes 120 km/h and another goes 80 km/h..."
→ It only needs mathematical reasoning
2. A single reasoning path
CoT generates one chain of thought. If the first step is wrong, the error propagates. There's no correction mechanism and no exploration of alternatives.
# If the model assumes wrong in step 1...
Step 1: "I assume X = 10" ← Error
Step 2: "So Y = X * 2 = 20" ← Error propagates
Step 3: "Therefore Z = Y - 5 = 15" ← Wrong answer
# With Self-Consistency, another path can reach the right answer
3. No exploration of strategies
Some problems have multiple valid approaches (divide and conquer, dynamic programming, heuristic search). CoT picks one implicitly, without evaluating which is best for the specific problem.
4. No self-correction mechanism
CoT has no way to detect that its own answer is wrong and fix it. Once generated, that's the final answer.
ReAct: Reasoning + Acting
ReAct (Reasoning + Acting) was proposed by Yao et al. in 2022. The core idea: LLMs should be able to interact with external tools during the reasoning process.
The ReAct loop
Thought: What do I need to know to answer this question?
Action: search("oil price today")
Observation: Brent crude: $78.5/barrel (March 8, 2026)
Thought: Now I have the current figure. I can compute the impact.
Action: calculator("78.5 * 0.15")
Observation: 11.775
Answer: The tax would be roughly $11.78 per barrel.
When to use ReAct
- When the answer requires real-time data
- When you need to verify calculations with a calculator
- When you must query external databases
- When the reasoning requires multiple verification steps
Limitations of ReAct
- Higher latency: every Action→Observation is an extra call
- Higher cost: multiple API calls
- It can get stuck in loops if the tools don't respond correctly
- You have to implement the tools
Self-Consistency: Many Paths, One Answer
Self-Consistency (Wang et al., 2022) is elegantly simple: instead of generating one answer, generate N answers with temperature > 0 (to introduce variation) and then vote for the most common one.
The intuition behind it
Imagine asking the same hard question to 5 people. If 4 out of 5 land on the same result by different routes, that result is very likely correct.
# With N=5 answers for "What is 15% of 480?"
Answer 1: "72" (Thought: 480 * 0.15 = 72)
Answer 2: "72" (Thought: 10% = 48, 5% = 24, total = 72)
Answer 3: "71" (Calculation error)
Answer 4: "72" (Thought: 480 / 100 * 15 = 72)
Answer 5: "72" (Thought: 72)
Majority vote: "72" ✓ (4/5 votes)
Typical empirical improvement
| N | Improvement vs baseline | Cost |
|---|---|---|
| 1 | 0% (baseline) | 1x |
| 3 | +5-8% on math | 3x |
| 5 | +8-12% | 5x |
| 10 | +10-15% | 10x |
The point of diminishing returns usually sits at N=5 for most tasks.
Tree-of-Thought: Exploring Branches
Tree-of-Thought (ToT, Yao et al., 2023) takes reasoning to another level: instead of a linear chain of thoughts, it builds a tree where each node is a partial state of the solution.
Tree structure
[Problem]
/ | \
[Branch A] [Branch B] [Branch C]
(0.7) (0.9✓) (0.5)
|
[Branch B1] [Branch B2]
(0.8✓) (0.6)
|
[Final solution]
Search strategies
- BFS (Breadth-First): Explore every branch at the same level before going deeper
- DFS (Depth-First): Follow the most promising branch all the way down
- Beam Search: Keep the K best branches at each level
When to use ToT
- Planning problems
- Puzzles with multiple possible solutions
- When CoT's first approach frequently fails
- When you have the budget for many API calls
Meta-Prompting and Self-Refine
Meta-prompting
Meta-prompting means using an LLM to generate or improve prompts for another task. Instead of hand-writing the perfect prompt, we ask the model to generate it.
Meta-prompt:
"Create the best possible prompt for: [classifying sentiment in restaurant reviews].
Consider: clarity, examples, expected output format, edge cases."
→ The model generates an optimized prompt
→ We use that prompt for the real task
Self-Refine
Self-Refine (Madaan et al., 2023) implements an iterative improvement loop:
- Generate: Produce an initial answer
- Critique: Evaluate the answer looking for errors and improvements
- Refine: Improve it based on the critique
This process can repeat 1-3 times before returns drop off significantly.
Comparing the Techniques
| Technique | Relative cost | Latency | Where it shines |
|---|---|---|---|
| CoT | 1x | Low | Pure reasoning |
| Self-Consistency (N=5) | 5x | Medium-High | Critical math/logic |
| ReAct | 3-10x | High | External data |
| Tree-of-Thought | 5-20x | Very high | Multi-strategy problems |
| Meta-prompting | 2-3x | Medium | Prompt optimization |
| Self-Refine | 2-4x | Medium | Critical quality |
Module 5 Roadmap
| # | Capsule | Topic | What you'll learn |
|---|---|---|---|
| 01 | Introduction | Beyond CoT | Overview of advanced techniques |
| 02 | ReAct | Thought → Action → Observation | Implementing it with function calling |
| 03 | Self-Consistency | N answers, majority vote | Sampling and voting |
| 04 | Tree-of-Thought | Exploring branches | BFS, DFS, evaluation |
| 05 | Meta-prompting and self-refine | Prompts that generate prompts | Refinement loops |
| 06 | Combining techniques | CoT + Self-Consistency, etc. | Combining strategies |
| 07 | Decision framework | Which technique to use | Decision tree |
| 08 | Project | Multi-Strategy Problem Solver | A complete system |
Module Prerequisites
Before you continue, make sure you're comfortable with:
- Chain-of-Thought (CoT): Knowing how to write basic CoT prompts
- Few-shot prompting: Understanding how examples shape behavior
- OpenAI Python SDK:
from openai import OpenAI,client = OpenAI() - Basic function calling: The idea that the model can "call functions"
If you need a refresher, Module 3 covers CoT in detail.
First Experiment: CoT vs Self-Refine
So you can see the difference right away, compare these two approaches for writing a professional email:
from openai import OpenAI
client = OpenAI()
task = "Write an email to turn down a job offer, professionally and warmly."
# Approach 1: plain CoT (a single generation)
response_cot = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{
"role": "user",
"content": f"Think step by step.\n\n{task}"
}],
temperature=0.7
)
email_cot = response_cot.choices[0].message.content
# Approach 2: Self-Refine (generate → critique → improve)
response_draft = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": task}],
temperature=0.7
)
draft = response_draft.choices[0].message.content
response_refined = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": f"""Here is a draft email:
{draft}
Evaluate: Is it professional enough? Is it warm without being vague?
Does it leave the door open for future opportunities?
Generate an improved version."""}],
temperature=0.3
)
email_refined = response_refined.choices[0].message.content
print("=== CoT ===")
print(email_cot[:300])
print("\n=== Self-Refine ===")
print(email_refined[:300])
The Self-Refine version costs 2x, but it typically produces more polished, better-balanced emails. The engineering question is: does your use case justify that cost?
A Real Use Case: Financial Analysis System
To ground this, here's a real scenario where each technique has its place:
Financial report analysis system:
1. CoT → Reason about financial ratios
2. ReAct → Look up current market data
3. Self-Consistency → Validate revenue projections
4. ToT → Explore investment scenarios
5. Self-Refine → Improve the quality of the final report
Don't use every technique for everything. The craft is knowing when each one applies.
Warm-up Exercises
Exercise 1: Spot CoT's limitations
For each of the following tasks, decide whether pure CoT is enough or whether you'd need an advanced technique. Justify your answer.
a) Determine whether 1337 is prime b) Find Apple's current stock price c) Solve an Einstein-style logic puzzle d) Write a poem about autumn e) Check whether a delivery date has already passed (today is March 8, 2026)
See solution
a) CoT is enough — It's pure computation. The model can reason about divisibility with no external data. (Answer: 1337 = 7 × 191, not prime)
b) ReAct required — It needs real-time data. CoT would invent an outdated or fake price.
c) CoT is enough (or ToT if it's very complex) — It's pure reasoning. A good CoT prompt can solve it.
d) No advanced technique — Creative tasks don't benefit from CoT, ReAct or Self-Consistency. Zero-shot or few-shot is enough.
e) ReAct required — It needs to know today's date. With CoT the model would assume a date that might not be right.
Exercise 2: Estimate the cost
If a gpt-4o-mini call costs $0.00015 per 1K input tokens and $0.00060 per 1K output tokens, and each answer averages 500 input tokens and 200 output tokens:
How much would it cost to solve 100 problems with:
- CoT (1 call)
- Self-Consistency N=5
- ReAct averaging 4 steps
See solution
Cost per call ≈ 0.00015 * 0.5 + 0.00060 * 0.2 = $0.000075 + $0.000120 = $0.000195
- CoT: 100 × $0.000195 = $0.0195
- Self-Consistency N=5: 500 × $0.000195 = $0.0975
- ReAct (4 steps): 400 × $0.000195 = $0.078
For 100 problems, the costs are tiny. For 100,000 problems:
- CoT: $19.5
- Self-Consistency: $97.5
- ReAct: $78
Cost scales linearly, so the choice of technique matters at scale.
Exercise 3: Design a workflow
You have a customer support system that receives user tickets. Tickets can be:
- Simple questions ("What are your hours?")
- Technical problems that require checking the account status
- Complaints that require careful analysis before replying
Design which technique you'd use for each ticket type, and why.
See solution
Simple questions: Zero-shot or few-shot. You need neither complex reasoning nor external data. Fast and cheap.
Technical problems: ReAct. You need to query internal APIs (account status, order history, ticketing system). The model has to fetch real data before answering.
Complex complaints: Self-Refine. Generate an initial answer, then critique the tone/content (is it empathetic? does it solve the problem?), and refine. Optionally Self-Consistency if the classification of the problem is ambiguous.
Summary
In this module you'll learn to go beyond CoT with four powerful techniques:
-
ReAct: For when you need to connect with the real world (APIs, databases, calculators). The model thinks → acts → observes → repeats.
-
Self-Consistency: For when precision is critical. Generate N answers and vote. Consensus is more reliable than a single answer.
-
Tree-of-Thought: For complex problems with multiple strategies. Explore branches, evaluate, expand the best one.
-
Meta-prompting and Self-Refine: To optimize prompts automatically and to iteratively improve the quality of the answers.
Every technique has a cost and a benefit. The decision framework in capsule 07 will help you pick the right one every time.
What This Module Does NOT Cover
Setting the boundaries matters, so you know exactly what to expect:
| Topic | Covered? | Where you'll find it |
|---|---|---|
| Implementing ReAct with function calling | Yes (Capsule 02) | This module |
| Self-Consistency with majority vote | Yes (Capsule 03) | This module |
| Tree-of-Thought with BFS/DFS | Yes (Capsule 04) | This module |
| Meta-prompting and Self-Refine | Yes (Capsule 05) | This module |
| Autonomous agents (AutoGPT, BabyAGI) | No | Outside the scope of this guide |
| Model fine-tuning | No | Needs a dedicated ML guide |
| Retrieval-Augmented Generation (RAG) | No | Separate RAG guide |
| Training custom tools | No | Function Calling guide |
The reason: this module focuses on prompting techniques you can apply today with any model via API, without training or modifying models. Autonomous agents are built on top of these techniques, but they need extra infrastructure that's out of scope.
Frequently Asked Questions
Do I need to master CoT before starting? Yes. The techniques in this module extend CoT. If you can't write a CoT prompt that works consistently, go back to Module 4 first.
Can I use these techniques with open-source models? Yes. ReAct, Self-Consistency, ToT and Self-Refine work with any LLM that supports chat completions. Quality varies with the model's capability, but the techniques are provider-agnostic.
Which technique is the most practical for production? Self-Refine is probably the most widely used in production because of its balance between cost and quality improvement. ReAct is essential if your system needs external data. Self-Consistency is ideal for tasks where precision matters more than cost.
Can the techniques be combined? Absolutely. Capsule 06 covers exactly that: CoT + Self-Consistency, ReAct + Self-Refine, and so on. The combinations are where these techniques really shine.
How much more do these techniques cost vs plain CoT? It depends on the technique. Self-Consistency N=5 costs 5x. ReAct with 3-4 steps costs 3-4x. Self-Refine with 2 iterations costs 3x. The comparison table in this capsule has the details. The decision framework in Module 07 helps you choose within your budget.
Additional resources
- ReAct: Synergizing Reasoning and Acting in Language Models (Yao et al., 2022)
- Self-Consistency Improves CoT Reasoning in LLMs (Wang et al., 2022)
- Tree of Thoughts: Deliberate Problem Solving (Yao et al., 2023)
- Self-Refine: Iterative Refinement with Self-Feedback (Madaan et al., 2023)
- Prompt Engineering Guide - Advanced Techniques
- OpenAI Cookbook - Prompt Engineering