What Is ReAct?
ReAct (Reasoning + Acting) is a prompting framework introduced by Yao et al. in 2022. Instead of just outputting an answer, the model generates a reasoning trace before each action — explaining what it knows, what it needs, and why it is choosing a particular tool. This interleaving of Thought → Action → Observation makes agents significantly more accurate and much easier to debug.
The ReAct Loop in Detail
Thought: I need to find the current CEO of OpenAI.
Action: search("OpenAI CEO 2024")
Observation: Sam Altman is the CEO of OpenAI as of 2024.
Thought: I have the answer.
Action: finish("Sam Altman is the CEO of OpenAI.")
Observation: Task complete.
Each Thought is the model's internal monologue — not shown to the user, but it crucially guides which action comes next. This is why ReAct agents make far fewer irrelevant tool calls than direct-action agents.
Why ReAct Works
- Grounding: Reasoning is grounded in real observations from tool outputs, not just parametric knowledge.
- Error recovery: If an action fails, the next Thought can reflect on why and try a different approach.
- Interpretability: You can read the thought trace to understand exactly why the agent acted as it did.
- Reduced hallucination: The agent commits to searching before answering — it cannot just make up facts.
On HotpotQA, ReAct reduced hallucination by 63% compared to chain-of-thought prompting alone.
Implementing ReAct from Scratch
SYSTEM_PROMPT = """You have access to these tools:
- search(query): Search the web
- calculator(expr): Evaluate math
- finish(answer): Return the final answer
Format:
Thought: [reasoning]
Action: tool_name(arguments)
Observation: [tool output — filled in for you]
... repeat ...
Thought: I now know the answer.
Action: finish(your answer)"""