ReAct Prompting

Tier: Advanced · Task types: Agentic tasks, tool use, multi-step research · Difficulty: ⭐⭐⭐⭐☆

Table of contents
  1. Definition
  2. Use Cases
  3. Weak Prompt (No ReAct Structure)
  4. Improved Prompt (ReAct Structure)
    1. Improved Prompt Output (Gemini)
  5. Verdict
  6. Common Pitfalls

Definition

ReAct (Reasoning + Acting) prompting structures the model’s output as an interleaved sequence of Thought → Action → Observation steps. The model reasons about what to do next, specifies an action (e.g., search, calculate, retrieve), observes the result, and reasons again — forming a loop until it reaches a final answer.

ReAct is the foundational pattern underlying most LLM agent frameworks (LangChain, CrewAI, etc.).


Use Cases

  • Multi-step research tasks requiring iterative information gathering and synthesis
  • Tool-augmented pipelines where the LLM must decide which tool to call and what arguments to pass
  • Debugging agentic failures — the Thought/Action/Observation trace makes the model’s decision process transparent

Weak Prompt (No ReAct Structure)

What is the GDP per capita of the country with the highest HDI score?

The model answers from training data, which may be outdated, and provides no reasoning trace.


Improved Prompt (ReAct Structure)

Answer the following question using this Thought/Action/Observation format.
Available actions: search[query], calculate[expression], finish[answer]

Question: What is the GDP per capita of the country with the highest HDI score?

Begin:
Thought:

Improved Prompt Output (Gemini)

Thought: I need to find which country has the highest Human Development Index score, then find its GDP per capita.
Action: search[highest HDI country 2024]
Observation: Switzerland topped the 2024 HDI rankings with a score of 0.967.
Thought: Now I need Switzerland's GDP per capita.
Action: search[Switzerland GDP per capita 2024]
Observation: Switzerland's GDP per capita (PPP) in 2024 is approximately $91,000 USD.
Thought: I have both pieces of information needed to answer the question.
Action: finish[The country with the highest HDI score (Switzerland, 0.967) has a GDP per capita of approximately $91,000 USD (PPP, 2024).]

Assessment: The reasoning trace is transparent, the search steps are explicit, and the answer is grounded in stated evidence. In a real system, each search[] action would trigger an actual tool call.


Verdict

ReAct produces highly interpretable agent behaviour and is the right structure when you need to debug why an agent made a particular decision. The main limitation is that without actual tool integration, the “actions” are simulated — the model may hallucinate search results. ReAct is most powerful inside a framework that intercepts action outputs and feeds real tool results back as observations.


Common Pitfalls

1. Not integrating real tools Without actual tool execution, the model fabricates observations. This is useful for prototyping but dangerous in production.

2. Action loops without termination conditions An agent that never calls finish[] will loop indefinitely. Always define and enforce a maximum number of steps.

3. Hallucinated observations poisoning later reasoning If the model generates a false observation (e.g., wrong search result), all subsequent reasoning builds on a false premise. Intercept and validate observations from real tools.


Back to top

Built by [nihalshx](https://github.com/nihalshx). Techniques tested with the Google Gemini API.

This site uses Just the Docs, a documentation theme for Jekyll.