ReAct Framework: Reason and Act Guide (2026)
The ReAct framework (Reason + Act) is the foundation for building autonomous LLM agents. By interleaving explicit reasoning with external tool calls, ReAct transforms language models from passive text generators into active problem-solvers that can retrieve real-time information, perform calculations, and execute multi-step workflows. Modern AI agents (including GPT-4o with tools, Claude with computer use, and Gemini with function calling) all implement ReAct principles.
What ReAct Solves: The Limitation of Pure Reasoning
Traditional chain-of-thought prompting works well for problems the model can solve with its training data. But what happens when you ask: "What is the current weather in Paris?" or "What was the score of the latest World Cup match?" or "Calculate the compound interest on $10,000 at 5% annual rate for 7 years?"
The model lacks real-time information or computational precision. Pure reasoning hits a wall.
ReAct solves this by giving the model a way to say, "I need to search for this" or "I need to calculate this," then pause and wait for the external system to provide the result. This loop—Thought → Action → Observation → Thought → …—continues until the model has enough information to answer.
The ReAct Loop: Three Core Components
1. Thought: Internal Reasoning
The model explicitly articulates its reasoning at each step. This serves three purposes:
- Planning: What does the model need to do next?
- Evidence: Why did the model choose this action over others?
- Auditability: A human can follow the agent's decision trail.
Example:
Thought: The user asked for the weather in Paris and the latest PSG match score.
Both require real-time data I don't have in my training set (April 2024 cutoff).
I should search for both pieces of information.
2. Action: Executable Command to External Tools
The model generates a structured request for an external tool. This is not a suggestion or a question—it is a command the system will parse and execute.
Common action formats:
Action: search(query="current weather Paris")
Action: calculate(expression="10000 * (1.05 ** 7)")
Action: fetch_data(api="psg_match_history", limit=1)
Action: http_get(url="https://api.example.com/weather?city=Paris")
The key: the action must be unambiguous enough that a parser can extract the tool name and arguments.
3. Observation: External System Response
After the system executes the action, it feeds the result back into the prompt as an observation. The model then uses this new information to inform its next thought.
Example:
Observation: The weather in Paris is 18°C, partly cloudy, light winds from the west.
A Complete Worked Example
Let's walk through how ReAct tackles a multi-step research question.
User Query: "What was the revenue of Apple in Q1 2026, and was it higher than their Q1 2025 revenue?"
ReAct Agent Loop:
Iteration 1: Search for Q1 2026 Apple Revenue
Thought: I need to find Apple's Q1 2026 revenue and compare it to Q1 2025.
I'll start by searching for their recent earnings report.
Action: search(query="Apple Q1 2026 earnings revenue")
System executes the search and returns:
Observation: Apple Q1 2026 (ended Dec 31, 2025): Revenue was $99.9 billion,
up 4.3% year-over-year. This was reported in their January 2026 earnings call.
Iteration 2: Confirm Q1 2025 Data
Thought: I found Q1 2026 revenue: $99.9 billion. The observation already states
it's up 4.3% year-over-year, which means Q1 2025 was lower. Let me calculate
the exact Q1 2025 revenue to provide complete information.
Action: calculate(expression="99.9 / 1.043")
System returns:
Observation: 99.9 / 1.043 = 95.78 billion
Iteration 3: Final Answer
Thought: I now have both values:
- Q1 2026: $99.9 billion
- Q1 2025: $95.78 billion
- Difference: $4.12 billion increase
This answers the user's question.
Final Answer: Apple's Q1 2026 revenue was $99.9 billion, which is higher than Q1 2025 revenue of approximately $95.78 billion—an increase of $4.12 billion or 4.3% year-over-year.
Notice: The agent made three decisions automatically:
- Recognized it needed external data (search)
- Recognized it could derive one value from another (calculation)
- Knew when it had enough information to answer
Implementing ReAct: System Requirements
A production ReAct system requires:
- An LLM configured to output in Thought/Action format (this usually requires few-shot examples in the system prompt)
- A tool registry listing available actions (e.g., search, calculate, fetch_data) with schemas and descriptions
- A parser that extracts the Action from the model's output (regex or structured parsing)
- An orchestration loop (typically in Python or JavaScript) that:
- Calls the LLM with the current prompt + observations
- Parses the Action
- Looks up the tool in the registry
- Executes the tool with validated arguments
- Appends the Observation to the prompt
- Loops until the model outputs "Final Answer"
- Error handling (invalid tool names, tool failures, timeout)
- Loop guards (max iterations, to prevent infinite loops)
Pseudocode for a ReAct Loop
def react_agent(user_query, max_iterations=10):
prompt = system_prompt + user_query
for iteration in range(max_iterations):
# Call LLM
response = llm.generate(prompt)
# Parse response for Final Answer
if "Final Answer:" in response:
return response.split("Final Answer:")[1].strip()
# Parse Action
action_match = regex.search(r"Action: (\w+)\((.*?)\)", response)
if not action_match:
raise ValueError("LLM did not produce a valid Action")
tool_name, tool_args = action_match.groups()
# Execute tool
try:
observation = tools[tool_name].execute(tool_args)
except ToolNotFound:
observation = f"Error: Tool '{tool_name}' not found."
except Exception as e:
observation = f"Error executing {tool_name}: {str(e)}"
# Append to prompt for next iteration
prompt += f"\nObservation: {observation}\n"
raise TimeoutError(f"Agent did not produce Final Answer in {max_iterations} iterations")
Why ReAct Excels: Advantages Over Pure Prompting
| Aspect | Pure Chain-of-Thought | ReAct |
|---|---|---|
| Real-time data | Limited to training cutoff | Can search current information |
| Calculations | Prone to errors, especially multi-step | Can delegate to precise tools |
| Verification | Model asserts facts; no validation | Tool results verify claims |
| Transparency | Reasoning visible but unverifiable | Reasoning + evidence trail visible |
| Scalability | Fixed context window | Can chain multiple tools/API calls |
Real-world impact: Systems using ReAct for customer support reduce hallucinated facts by ~70% and improve factual accuracy from 82% to 94% (Anthropic benchmark, 2024).
Common Pitfalls and How to Avoid Them
Pitfall 1: Tool Registry Mismatch
Problem: The system prompt lists 10 possible tools, but the orchestration loop only implements 5, so the model tries to call non-existent tools and the agent fails.
Fix: Generate the system prompt dynamically from the tool registry. Keep them in sync.
Pitfall 2: Ambiguous Action Format
Problem: The model outputs search for apple revenue instead of search("apple revenue"), and the regex parser fails.
Fix: Use few-shot examples in the system prompt showing the exact format expected. Include 3–5 complete worked examples with properly formatted actions.
Pitfall 3: Infinite Loops
Problem: The model keeps searching for information it doesn't find, and the loop never terminates.
Fix: Set a max_iterations limit. If the limit is hit, return the best answer found so far or request human intervention.
Pitfall 4: Over-Reliance on Tools
Problem: The model calls tools for information it already knows (wasting API calls and latency), or it delegates reasoning that should happen in-context.
Fix: In the system prompt, encourage the model to use its knowledge first: "Use your training data for questions answered after April 2024. Only call search() for real-time data or recent events."
Key Takeaways
- ReAct (Reason + Act) enables LLMs to overcome knowledge cutoffs and computational limits by interleaving reasoning with external tool calls.
- The core loop is: Thought (reason) → Action (tool call) → Observation (result) → repeat until Final Answer.
- Implementing ReAct requires an LLM, a tool registry, a parser, an orchestration loop, and error handling; frameworks like LangChain and LlamaIndex provide production-grade implementations.
- ReAct reduces hallucinated facts by ~70% and improves factual accuracy to 94% compared to pure reasoning prompts.
- Common pitfalls include tool registry mismatches, ambiguous action formats, infinite loops, and over-reliance on tools; all can be prevented with clear specs, examples, and guardrails.
Frequently Asked Questions
Is ReAct the same as function calling?
Function calling (supported by GPT-4, Claude 3, Gemini) is a technique that makes ReAct easier to implement. Instead of parsing text output, the model directly returns a JSON object with the tool name and arguments. ReAct is a framework (Thought-Action-Observation loop) that can be implemented with text parsing or function calling. Modern implementations prefer function calling because it's more reliable.
How many tools should a ReAct agent have?
Start with 3–5 essential tools (search, calculate, fetch_api, summarize). Too many tools confuses the model and increases errors. As you scale, organize tools into categories and let the model choose the right category before calling a specific tool.
Can ReAct agents learn from mistakes?
Basic ReAct doesn't include learning; the agent follows the same strategy for each query. To add learning, use Reflexion (a technique building on ReAct): after each action fails, the agent reflects on what went wrong and adjusts its strategy. This requires logging failed attempts and feeding summaries into future prompts.
How do I evaluate a ReAct agent?
Build a test set of 50–100 queries split across categories (simple searches, multi-step reasoning, calculations, recent events). For each, measure: Did the agent produce a Final Answer? Is the answer factually correct? How many tool calls did it use? Did it fail or loop? Track accuracy, efficiency (token usage), and reliability (% reaching Final Answer).
What's the relationship between ReAct and retrieval-augmented generation (RAG)?
RAG is a data strategy: pre-retrieve relevant documents and add them to the prompt. ReAct is an interaction pattern: dynamically call tools based on reasoning. They complement each other. A ReAct agent might use a RAG-powered search tool: it reasons about what to search for, then the search tool retrieves relevant documents and returns them as observations.
Further Reading
- ReAct: Synergizing Reasoning and Acting in Language Models – Original ReAct paper (Yao et al., 2022). Defines the framework and benchmarks it on multiple domains.
- LangChain ReAct Documentation – Implementation guide for ReAct agents using LangChain.
- LlamaIndex Agents Guide – Alternative framework for building and orchestrating agents with ReAct principles.
Now that you understand how agents reason and act, the next lesson explores Reflexion: how agents can analyze their own mistakes, learn from failures, and improve their performance over multiple attempts. This is the difference between agents that get stuck and agents that iterate toward success.