The ReAct Pattern
Knowledge
ReAct stands for Reasoning + Acting and is the fundamental pattern behind nearly all AI agents. The idea is simple yet powerful: the LLM thinks out loud, performs an action, and observes the result -- in a loop, until the task is complete.
Loop:
1. THINK -- What do I know? What do I still need? What's the next step?
2. ACT -- Call a tool, query an API, execute code
3. OBSERVE -- Evaluate the result, adjust the plan
4. Back to 1 (or done)
Think
The agent analyzes the question and considers which tool could help.
The ReAct Loop in Code
Here's what a minimal ReAct loop looks like in pseudocode:
def react_agent(task, tools, max_steps=10):
context = f"Task: {task}"
for step in range(max_steps):
# THINK
thought = llm.generate(
f"{context}\n\nThink: What is the next step?"
)
context += f"\nThought: {thought}"
# Decide: Done or keep going?
if "FINAL ANSWER" in thought:
return extract_answer(thought)
# ACT
action = llm.generate(
f"{context}\n\nChoose a tool and formulate the action."
)
context += f"\nAction: {action}"
# OBSERVE
result = execute_tool(action, tools)
context += f"\nObservation: {result}"
return "Maximum steps reached."
Understand
Why ReAct Works
The secret behind ReAct lies in the explicit thinking step. If you simply let an LLM tackle a complex task, it often jumps straight to the answer and makes mistakes. By forcing it to "think" first (reasoning), the quality improves dramatically.
This is the same principle as chain-of-thought prompting -- but in a loop with real actions.
iResearch Background
The ReAct paper (Yao et al., 2022) demonstrated that combining reasoning and acting improves results on complex tasks by 20-30% compared to pure reasoning or pure acting alone.
Example: A Research Agent
Imagine you're building an agent that needs to answer the question: "Which European country made the highest per-capita investment in renewable energy in 2025?"
A simple chatbot would guess or use outdated data. A ReAct agent approaches it like this:
Step 1: THINK
I need to find current data on renewable energy investments in Europe. For that, I need a reliable source. Let me start by searching for recent reports from Eurostat or the IEA.
Step 2: ACT
search("renewable energy investment per capita Europe 2025 Eurostat")
Step 3: OBSERVE
The search returns a Eurostat report from Q1 2026. Denmark leads with EUR 1,840 per capita, followed by Norway (EUR 1,620) and Germany (EUR 980). But Norway isn't an EU country -- the question says "European," not "EU."
Step 4: THINK (new iteration)
Norway is geographically European, even if it's not in the EU. I should clarify whether the question means "EU" or "Europe." Since the question says "European," Norway counts. But I should verify the numbers with a second source.
Step 5: ACT
search("IEA renewable energy investment Denmark Norway 2025 per capita")
Step 6: OBSERVE
The IEA confirms: Denmark leads among EU countries, Norway leads among all European countries. The figures match.
Final Answer
Based on current data from Eurostat and the IEA, Denmark (among EU countries) and Norway (among all European countries) made the highest per-capita investment in renewable energy in 2025.
*Notice the Quality
The agent didn't just guess. It researched, identified an ambiguity ("European" vs. "EU"), consulted a second source, and provided a nuanced answer. That's the power of ReAct.
Why is the explicit THINK step in the ReAct pattern so important?
Complete the three steps of the ReAct loop:
Apply
When to Use ReAct?
ReAct is the default pattern for most agent tasks. Use it when:
- The task requires multiple information sources
- Intermediate results influence the next steps
- You can't predict how many steps will be needed
- Errors need to be detected and corrected
However, ReAct is not optimal when:
- The task involves many parallel steps (since ReAct works sequentially)
- You need strict cost control (every thinking step costs tokens)
- The task is complex enough that a separate planning step would be beneficial (then check out Plan-and-Execute)
An agent is supposed to check 50 product pages simultaneously for price changes. Is ReAct the right pattern?
Reflect
ReAct combines reasoning and acting in a loop: think, act, observe. This pattern is ideal for tasks where the next step depends on the result of the previous one. For parallel tasks, it is less suitable -- other patterns like fan-out work better there.