ReAct: The Prompting Pattern That Powers Modern AI Agents
ReAct interleaves reasoning traces with actions, enabling LLMs to use tools while maintaining a reasoning chain - the foundational pattern behind LangChain agents and modern AI assistants.
Mahmudul Haque Qudrati
CEO & ML Engineer
One AI engineering post, weekly
LLM benchmarks, prompt techniques, and token-cost breakdowns — not another AI news roundup.
Chain-of-thought prompting teaches LLMs to reason through problems step-by-step, but reasoning alone cannot access external information or take actions in the world. Action-only approaches (API calls, web search) lack the reasoning chain to handle multi-step problems that require planning. The ReAct paper (arXiv:2210.03629) by Yao et al. proposed combining both.
The Thought-Action-Observation Loop
ReAct follows a strict interleaved pattern:
- Thought: The model reasons about what it knows and what it needs to do next
- Action: The model calls a specific tool with arguments
- Observation: The tool returns a result
- Repeat until the answer is reached or the reasoning concludes
Example trace for "What is the elevation of the highest mountain in the country that won the 2022 FIFA World Cup?":
Thought: I need to find which country won the 2022 FIFA World Cup.
Action: Search[2022 FIFA World Cup winner]
Observation: Argentina won the 2022 FIFA World Cup, defeating France.
Thought: The highest mountain in Argentina is Aconcagua. I need its elevation.
Action: Search[Aconcagua elevation]
Observation: Aconcagua is 6,961 meters (22,838 feet) above sea level.
Thought: I have all the information needed.
Action: Finish[6,961 meters]
Team workspace
Ship faster with chat, meetings, and projects in one place — Zlyqor.
Why Pure CoT Fails for Tool Use
CoT without tools confabulates - it invents facts it doesn't know. A pure CoT chain might answer the question above by hallucinating that France won or guessing an incorrect elevation. Without grounding in external sources, even correct reasoning on incorrect premises produces wrong answers.
Why Pure Action Fails
Pure action sequences (just calling APIs in sequence) lack the reasoning to decide which action to take next, how to interpret conflicting observations, or when to stop. The Thought steps provide the planning layer that makes action selection coherent.
from langchain.agents import create_react_agent, AgentExecutor
from langchain_openai import ChatOpenAI
from langchain import hub
from langchain.tools import DuckDuckGoSearchRun
llm = ChatOpenAI(model="gpt-4", temperature=0)
tools = [DuckDuckGoSearchRun()]
# Use the standard ReAct prompt template from LangChain hub
prompt = hub.pull("hwchase17/react")
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
verbose=True, # Shows Thought/Action/Observation traces
max_iterations=10,
)
result = agent_executor.invoke({
"input": "What is the population of the capital of the country that hosts CERN?"
})
Benchmark Results
On HotpotQA (multi-hop reasoning), ReAct with Wikipedia search reduced hallucination rate by 34% compared to CoT alone. On WebShop (web shopping agent), ReAct outperformed action-only baselines by 10% in success rate. On ALFWorld (interactive household tasks), ReAct achieved 71% success versus 45% for action-only agents.
Modern Variants
Reflexion adds a self-reflection step after failures: the agent critiques its failed attempt and stores the reflection in memory for future episodes. REWOO separates planning from execution, generating the full plan before making any tool calls. Toolformer internalizes tool use into the model weights rather than relying on prompting.
Further Reading
Mahmudul Haque Qudrati
CEO & ML Engineer
Visionary leader with extensive experience in machine learning and software development. Drives strategic innovation and business growth.
More from Mahmudul
Related Articles
GPT-6 Astra AGI: How to Actually Use It and Get Its Best Performance
GPT-6 Astra is OpenAI's most capable model, but 'AGI' is a marketing claim. This guide shows you how to access, use, and get the best from it with practical endpoints, pricing, and agent patterns.
What is Codex starts encrypting sub-agent prompts? A Practical Overview
OpenAI Codex now encrypts sub-agent prompts by default. This change affects how agentic systems share context between sub-agents. Here's what it means for your AI pipelines.
Building reliable agentic AI systems: A Practical Overview
A practical guide to building reliable agentic AI systems covering structured outputs, observability, fallbacks, and cost controls with real code examples.
// discussion
Comments