Skip to main content

ReAct prompting

Calculating read time…

You ask ChatGPT, “What’s the weather like in Tokyo right now?”

It might give you an outdated answer based on its training data, which cuts off in late 2023. It can’t *check* the weather.

You ask it, “Calculate the compound interest on a $10,000 investment at 5% APR over 10 years.”

It might try to do the math itself and… get it slightly wrong. LLMs are brilliant with words, but terrible at precise calculation.

The problem?
Standard AI prompting is like a brilliant student locked in a library with old books. They can reason, but they can’t go get new information or use a calculator.

The solution?
ReAct Prompting. It gives that student a key to the door, a phone to call the weather service, and a calculator.

DO - Think of ReAct as a Checklist:
It forces the AI to pause and follow a process:
THINK → DO → CHECK → REPEAT.
This structure is what makes it powerful.

ReAct Explained with a Simple Example

Let's forget the technical jargon for a moment. Imagine you're the AI, and I give you this task:

Task:
"Find out who is the current Prime Minister of the United Kingdom, and tell me one major policy they recently announced."

As a Basic AI (No ReAct):

  • You'd search your memory (training data).
  • You might say: "Rishi Sunak. A recent policy is the 'Smokefree Generation' plan."
  • Problem: Is that still current? You have no way to verify.

As a ReAct-Powered AI:

You have a tool: Search[query] that gets live web results. Your instructions are to follow the loop.

EXAMPLE - The ReAct Loop in Action:

Thought:
The user wants the current UK Prime Minister and a recent policy. My knowledge might be outdated. I should search for the most current information.

Act:
Search[current Prime Minister of the United Kingdom]

Observe:
Search results show "Sir Keir Starmer became Prime Minister on July 5, 2024."

Thought:
Good, I have the correct name. Now I need a recent major policy announcement from Keir Starmer.

Act:
Search[Keir Starmer recent major policy announcement July 2024]

Observe:
Articles indicate a major policy focus is on "kickstarting economic growth through a new National Wealth Fund."

Answer:
The current Prime Minister is Sir Keir Starmer. A major recent policy is the creation of a National Wealth Fund to drive economic growth.

See the difference? The ReAct AI didn't guess. It followed a clear process.

DON'T - Use ReAct for Everything:
Asking "What is the capital of France?" with ReAct is like using a satellite phone to call your neighbor. Use the right tool for the job.

Let's Build a ReAct Prompt Together

Here’s a hands-on example. We’ll create a prompt for an AI that has access to a Calculate(expression) tool.

Task for the AI:
"If a pizza is cut into 8 slices, and 3 friends eat 2 slices each, how many slices are left for me?"

Step 1: Set the Stage & Define Tools

Your prompt must start by explaining the rules.

PROMPT START:

You are a helpful assistant with access to a calculator.

To solve problems, always follow this format:

Thought: [Your reasoning about the problem]
Act: [The action, like Calculate[...]]
Observe: [The result from the action]
...repeat as needed...
Answer: [Your final answer]

Here is the problem:
"If a pizza is cut into 8 slices, and 3 friends eat 2 slices each, how many slices are left for me?"

Step 2: The AI's Likely ReAct Response

AI OUTPUT:

Thought:
I need to find out how many slices are left. First, calculate total slices eaten: 3 friends * 2 slices each.

Act:
Calculate[3 * 2]

Observe:
6

Thought:
The friends eat 6 slices. The pizza started with 8 slices. Subtract to find what's left.

Act:
Calculate[8 - 6]

Observe:
2

Answer:
There are 2 slices left for you.
DO - Celebrate the Small Win:
Even this simple example shows ReAct’s power. The AI offloaded math to a reliable tool, guaranteeing a correct answer.

ReAct vs. Other Methods: Side-by-Side

Let’s solve the same problem three ways.

Task:
"The temperature in NYC is 68°F. What is it in Celsius? Also, is that typically considered warm or cool for spring?"

1. Basic Prompting (The Risky Guess)

Prompt: "The temperature in NYC is 68°F. What is it in Celsius? Also, is that typically considered warm or cool for spring?"

AI Output (Possible):
"68°F is 20°C. That is a cool spring temperature."

Problem:
Did it calculate correctly? The "warm or cool" part is based on frozen training data, not current NYC norms.

2. Chain-of-Thought (The Reasoner)

Prompt: "Let's think step by step. The temperature in NYC is 68°F..."

EXAMPLE - Chain-of-Thought Output:

Step 1: Convert 68°F to Celsius. Formula: C = (F - 32) * 5/9.
(68-32)=36. 36 * 5/9 = 20. So, 20°C.

Step 2: Determine if 20°C is warm or cool for NYC spring.
In my knowledge, 20°C (68°F) is generally considered mild and pleasant.

Answer: 20°C, typically considered mild and pleasant for spring.

Improvement:
We see its reasoning! The conversion is likely correct. The opinion is still based on old knowledge.

3. ReAct Prompting (The Investigator)

Tools: Calculate(expression) and Search(query)
Prompt: "Solve the user's question. Use tools. Follow Thought/Act/Observe."

EXAMPLE - ReAct Output:

Thought:
The user wants a temperature conversion and a subjective assessment. First, convert 68°F to Celsius accurately using the calculator.

Act:
Calculate[(68 - 32) * 5 / 9]

Observe:
20

Thought:
It's 20°C. Now I need context. Search for what New Yorkers consider warm or cool in spring.

Act:
Search[Is 20°C warm or cool for New York City spring?]

Observe:
Weather articles suggest that 68°F (20°C) is considered very pleasant and comfortably warm for NYC spring.

Answer:
68°F is 20°C. This is generally considered a pleasantly warm temperature for spring in New York City.

Winner: ReAct. It guaranteed correct calculation and grounded its claim in current, contextual search.

DON'T - Skip the "Observe" Step:
The magic happens when the AI sees the result of its action. Always include the observation so the AI can use the new data.

Your Turn: A Practice Problem

Try to mentally write a ReAct prompt for this task. The AI has a Search tool.

Task:
"What was the score in the most recent UEFA Champions League final, and who scored the goals?"

Think It Through:

1. Thought 1:
The user wants live sports data. I need to find which match was the "most recent" final and get the score.

2. Act 1:
Search[most recent UEFA Champions League final score]

3. Observe 1:
You'd get the match result (e.g., "Real Madrid 2 - 1 Borussia Dortmund").

4. Thought 2:
Now I need details on goal scorers. I need a more specific search.

5. Act 2:
Search[goal scorers Real Madrid vs Borussia Dortmund 2024 final]

6. Answer:
Finally, compile the info.
DO - Practice with Different Tools:
Imagine tools like Calculator, Search, Database lookup, Email sender. Design ReAct prompts for each. This is how you master the framework.

When Should YOU Use ReAct?

Use this simple flowchart:

  • Q: Need live information (weather, news, scores)?
    → YES → Use ReAct.

  • Q: Require flawless precision (math, code, data)?
    → YES → Use ReAct.

  • Q: Multi-step task needing different lookups?
    → YES → Use ReAct.

  • Q: Simple fact, definition, or creative writing?
    → NO → Use basic or Chain-of-Thought.

The core idea is simple:
Think → Do → Check → Repeat.

You now understand the most powerful pattern for making AI interact with the real world. Go make it do something useful!

Comments