Skip to main content

⚡ ReAct Prompting

ReAct (Reasoning + Acting) is a prompting pattern where the AI alternates between thinking about what to do and taking actions. It follows a Thought → Action → Observation loop. The AI reasons about the problem, performs an action (like a search or calculation), observes the result, and then reasons again based on what it learned.

Think of it like a detective: think about the case, investigate a lead, observe the evidence, think again, investigate another lead, and repeat until the case is solved.

Why This Matters

ReAct is the foundation of how modern AI agents work:

  1. Bridges reasoning and action — The AI doesn't just think, it can also do things and learn from the results
  2. Handles dynamic tasks — Tasks that require gathering real-time information or interacting with tools
  3. Transparent decision-making — Every action is preceded by a thought explaining why, making the process auditable
  4. Error recovery — If an action produces unexpected results, the AI can reason about what went wrong and try a different approach

The ReAct paper from Princeton and Google showed this pattern significantly outperforms reasoning-only or acting-only approaches on tasks like question answering and fact verification.

The Thought → Action → Observation Loop

Here's how the loop works:

Thought 1: I need to find out X to answer this question.
Action 1: Search for X
Observation 1: The search returned Y.

Thought 2: Now I know Y, but I also need Z.
Action 2: Look up Z
Observation 2: Z is W.

Thought 3: With Y and W, I can now answer the question.
Action 3: Provide final answer
Final Answer: [answer based on Y and W]

Each cycle builds on the previous one. The AI never acts blindly — every action has a reason.

Prompt Example

You are a research assistant. Answer the user's question by using the
Thought → Action → Observation pattern.

Available actions:
- Search[query]: Search for information about a topic
- Calculate[expression]: Perform a mathematical calculation
- Lookup[term]: Look up a specific fact or definition

Question: How much bigger is the GDP of Japan compared to South Korea
in percentage terms?

Begin your research:

Thought 1:
Action 1:
Observation 1:
... continue until you have a final answer.

❌ Bad Example

How much bigger is Japan's GDP than South Korea's in percentage terms?

Problem: The AI guesses or uses potentially outdated training data. No structured reasoning, no tool use, and no way to verify the information.

✅ Improved Example

You are a research assistant that solves questions step by step using
the Thought/Action/Observation framework.

Available actions:
- Search[query]: Look up current information
- Calculate[expression]: Do math
- Verify[claim]: Double-check a fact

Question: How much bigger is Japan's GDP compared to South Korea's GDP,
in percentage terms?

Thought 1: I need to find the current GDP of Japan and South Korea.
Action 1: Search[Japan GDP 2025]
Observation 1: [provide or simulate the result]

Continue the Thought/Action/Observation loop until you reach a
confident final answer. Show every step.

Why it works: The structured loop ensures every claim is backed by a lookup or calculation. The AI doesn't skip steps or make unsupported claims.

🧪 Try It Yourself

Edit the prompt and click Run to see the AI response.

Practice Challenge

Design a ReAct prompt for this task:

Task: Plan a 3-day trip to Tokyo for someone who loves food and history, with a budget of $200/day.

Create a prompt that:

  1. Defines available actions (Search, PriceCheck, Route)
  2. Uses the Thought/Action/Observation loop
  3. Has the AI research restaurants, historical sites, and transportation
  4. Produces a final day-by-day itinerary with estimated costs

The key is making each action provide information that feeds into the next thought.

Real-World Scenario

Customer Support Agent with ReAct:

You are a customer support agent. A customer has written in with a problem.
Use the Thought/Action/Observation framework to resolve their issue.

Available actions:
- LookupOrder[order_id]: Get order details
- CheckInventory[product_id]: Check if an item is in stock
- LookupPolicy[policy_type]: Check company policy
- CreateTicket[description]: Escalate to human agent
- IssueRefund[order_id, amount]: Process a refund

Customer message: "I ordered a laptop (Order #12345) two weeks ago.
It arrived with a cracked screen. I want a replacement but I see
it's now out of stock on your website."

Thought 1: I need to verify the order details first.
Action 1: LookupOrder[12345]
Observation 1: Order #12345 — Laptop Pro X, delivered 14 days ago,
price $999, within 30-day return window.

Thought 2: The customer wants a replacement. Let me check stock.
Action 2: CheckInventory[laptop-pro-x]
Observation 2: Out of stock. Next restock estimated in 3 weeks.

Thought 3: It's out of stock, so I need to check our policy for
damaged items when replacement isn't available.
Action 3: LookupPolicy[damaged_item_no_replacement]
Observation 3: Policy: Offer full refund OR store credit + 10% bonus
OR replacement when back in stock with expedited shipping.

Thought 4: I now have all the information to help the customer.
I should present all three options.

Final Response: [compose message to customer with options]

This pattern is exactly how AI agent systems like LangChain agents, AutoGPT, and custom AI assistants are built in production.

Interview Question

Q: What is the ReAct prompting pattern and how is it used in AI agent systems?

A: ReAct stands for Reasoning + Acting. It's a prompting pattern where the AI alternates between Thought (reasoning about what to do), Action (performing a task like searching or calculating), and Observation (processing the result). This loop continues until the task is complete. It's the foundation of modern AI agent systems because it combines the AI's reasoning ability with the ability to use external tools. In production, frameworks like LangChain implement ReAct by connecting LLMs to APIs, databases, and other tools. The thought step makes the agent's decisions transparent and debuggable, which is critical for production systems.

Summary
  • ReAct = Reasoning + Acting in a structured loop
  • Pattern: Thought → Action → Observation → repeat
  • The AI reasons before every action and learns from every observation
  • Foundation of AI agent systems (LangChain, AutoGPT, etc.)
  • Define available actions clearly in your prompt
  • Makes AI decisions transparent and auditable
  • Best for tasks requiring tool use, research, or multi-step problem solving
  • Outperforms both reasoning-only and acting-only approaches