The ReAct Pattern: How AI Agents Reason and Act in Loops

COMPLETE guide to the ReAct pattern for AI agents. How Thought-Action-Observation loops work, benchmarks, failure modes & LangGraph examples.

Quick Answer: The ReAct pattern is a Thought → Action → Observation loop that lets AI agents reason step-by-step while using real tools — the most widely deployed agent architecture in production today.


If you've ever watched a Claude or GPT-4 agent "think out loud" — "I need to search for this, then calculate that, then verify the result" — you've seen the ReAct pattern in action. It's the invisible engine behind most AI agents in 2026, from customer support bots to autonomous coding assistants.

The ReAct pattern (short for Reason + Act) was introduced by Shunyu Yao et al. at ICLR 2023 and immediately became the default architecture in LangChain. Three years later, it's still the mental model every agent developer needs to understand — even as native function calling has replaced hand-parsed text traces in most production systems.

This guide covers how ReAct works from first principles, why it outperforms pure Chain-of-Thought reasoning, how it fails in the wild, and how to implement it today using LangGraph.


What Is the ReAct Pattern?

ReAct solves a fundamental problem: language models know a lot, but their knowledge is frozen at training time and they can't take real-world actions.

Chain-of-Thought prompting helped models reason better by thinking step-by-step before answering. But the thoughts were still just... thoughts. No web search. No database query. No API call.

ReAct adds a second track to the reasoning loop: external actions. The model doesn't just think — it acts, receives feedback, and incorporates that feedback into its next thought.

The original paper tested ReAct on multi-hop question answering (HotPotQA), fact verification (FEVER), interactive decision-making (ALFWorld), and web shopping (WebShop). The results were striking:

  • ALFWorld: +34 percentage points over prior imitation/RL baselines
  • WebShop: +10 percentage points absolute improvement
  • HotPotQA: 35.1% exact match using a ReAct + CoT hybrid, vs. 28.7% for standard prompting

The key insight: grounding reasoning in real observations dramatically reduces hallucination.


The Thought → Action → Observation Loop

Every ReAct agent operates on the same three-step cycle:

  1. Thought — the model reasons about what to do next, in natural language
  2. Action — the model calls a tool (search, calculator, database, API)
  3. Observation — the result of the action is appended to the context

The loop repeats until the model emits a Final Answer.

Here's what a real ReAct trajectory looks like for the question "What is the current price of the most expensive item in the Amazon top 10 electronics list?":

Thought: I need to find the current Amazon top 10 electronics list.
Action: search["Amazon top 10 electronics 2026"]
Observation: [search result: list of 10 products with prices]

Thought: The most expensive item is the Sony Bravia XR-85 at $4,299.
Action: search["Sony Bravia XR-85 current price"]
Observation: [search result: $3,999 (sale price today)]

Thought: The current price is $3,999, lower than the list price.
Final Answer: The most expensive item is the Sony Bravia XR-85, currently priced at $3,999.

Each observation becomes part of the context. The model's next thought is informed by real data, not parametric memory.

The Full Context Trajectory

Every step is appended to the same context window. By step 5, the model sees the complete history of its own reasoning and all tool results. This is both ReAct's strength (coherent multi-step reasoning) and its main scaling challenge (long tasks overflow the context window).


ReAct vs. Chain-of-Thought: What's the Difference?

Chain-of-Thought prompting was a breakthrough — asking models to reason step-by-step before answering improved accuracy dramatically on complex problems. But CoT has a hard ceiling: it can only reason about what the model already knows.

DimensionChain-of-ThoughtReAct
External toolsNoYes (search, API, DB, code)
Hallucination riskHigh on factual questionsLower — grounded in observations
Token costLowHigher (full trajectory in context)
Best forMath, logic, structured reasoningFactual lookup, web tasks, CRUD operations
AdaptabilityFixed reasoning chainCan adapt based on what tools return
Context growthBoundedGrows with each step — can overflow

The practical takeaway: use Chain-of-Thought when the answer lives in the model's weights (math, code generation, classification). Use ReAct when the answer requires external state (current prices, live data, file systems, databases).

In practice, the two combine well. The original ReAct paper's best results came from a hybrid: use CoT when the model is confident, switch to ReAct when it needs to verify facts. LangGraph makes this easy to implement with conditional routing.


ReAct vs. Other Agent Patterns

ReAct isn't the only pattern in the toolkit. Here's where it sits in the broader landscape — also covered in our deep-dive on AI agent reasoning patterns:

PatternCore IdeaToken CostBest For
ReActInterleaved reasoning + tool useMediumMost general tasks
Plan-and-ExecutePlan all steps upfront, then executeLow per stepPredictable, structured workflows
ReWOOParallelize all tool calls upfrontVery lowToken-sensitive, predictable tasks
ReflexionReAct + self-critique across episodesHighTasks needing iterative improvement
Tree of ThoughtsExplore multiple reasoning branchesVery highMath, logic puzzles with clear eval

ReAct's advantage is adaptability — it can change course based on what tools return. Plan-and-Execute is more efficient when the task is predictable; ReWOO removes the full trajectory from context entirely (much cheaper), but can't handle unexpected observations. Reflexion adds a cross-episode memory layer on top of ReAct — after failing, the agent writes a self-critique and tries again smarter.

When to Default to ReAct

If you're not sure which pattern to use, start with ReAct. It handles the broadest range of tasks with reasonable token efficiency. Optimize to Plan-and-Execute or ReWOO once you know your task structure well.


How to Implement the ReAct Pattern

Minimal Python Implementation (from Scratch)

The core of ReAct is just a loop — call the model, parse the action, run the tool, append the observation, repeat:

import re
from anthropic import Anthropic

client = Anthropic()
tools = {
    "search": lambda q: web_search(q),      # your search function
    "calculate": lambda expr: eval(expr),   # simple calculator
}

def react_agent(question: str, max_steps: int = 10) -> str:
    messages = [{"role": "user", "content": question}]
    system = """You are a ReAct agent. For each step, output:
Thought: <your reasoning>
Action: <tool_name>[<input>]
...or when done:
Final Answer: <your answer>"""

    for _ in range(max_steps):
        response = client.messages.create(
            model="claude-sonnet-4-6",
            max_tokens=1024,
            system=system,
            messages=messages,
        )
        text = response.content[0].text
        messages.append({"role": "assistant", "content": text})

        # Check for final answer
        if "Final Answer:" in text:
            return text.split("Final Answer:")[-1].strip()

        # Parse and execute action
        match = re.search(r"Action: (\w+)\[(.+?)\]", text)
        if match:
            tool_name, tool_input = match.group(1), match.group(2)
            observation = tools.get(tool_name, lambda x: "Tool not found")(tool_input)
            messages.append({
                "role": "user",
                "content": f"Observation: {observation}"
            })

    return "Max steps reached without a final answer."

The max_steps guard is critical. Without it, a confused agent will loop forever.

Production Implementation with LangGraph

In production, use LangGraph's create_react_agent. It handles the loop, tool routing, state management, and streaming out of the box:

from langgraph.prebuilt import create_react_agent
from langchain_anthropic import ChatAnthropic
from langchain_community.tools.tavily_search import TavilySearchResults

model = ChatAnthropic(model="claude-sonnet-4-6")
tools = [TavilySearchResults(max_results=3)]

# Creates a full ReAct graph with tool nodes and routing
agent = create_react_agent(model, tools)

# Run the agent
result = agent.invoke({
    "messages": [("user", "What are the top 3 AI agent frameworks in 2026?")]
})

print(result["messages"][-1].content)

LangGraph compiles this into a stateful graph: a model node, a tool execution node, and an edge that routes back to the model after each tool call until it sees no more tool calls in the response.

LangGraph vs. LangChain AgentExecutor

LangGraph's create_react_agent (introduced in LangGraph 1.0, October 2025) replaced the older LangChain AgentExecutor pattern. LangGraph is the production standard — it's more debuggable, supports streaming, and handles interrupts for human-in-the-loop flows. For new projects, always use LangGraph.


ReAct Failure Modes (and How to Fix Them)

ReAct is powerful but brittle in specific scenarios. Knowing the failure modes saves you from embarrassing production bugs.

1. Infinite Loops

Symptom: The agent calls the same tool repeatedly with similar inputs, never converging on an answer.

Cause: The tool returns an ambiguous result, and the agent keeps trying to resolve it.

Fix: Always set max_iterations (LangGraph default: 25). Add loop detection that checks if the last 3 actions are identical.

2. Context Window Overflow

Symptom: Error after 10–15 steps on long tasks.

Cause: Every step appends to the context. A 10-step trajectory with 500-token observations can easily hit 15K+ tokens.

Fix: Use a summarization step that compresses older observations. LangGraph supports this via custom MessagesState with a trimmer.

3. Thought Hallucination

Symptom: The agent's reasoning is coherent, but it calls the wrong tool or misinterprets the observation.

Cause: The model is pattern-matching on the thought format rather than reasoning from observations.

Fix: Use native function calling instead of text-parsed actions — it's structurally impossible to "hallucinate" a malformed tool call when the model outputs JSON. This is why modern LangGraph uses native function calling under the hood.

4. Attention Dilution

Symptom: The agent "forgets" earlier context and makes decisions inconsistent with earlier observations.

Cause: Long trajectories cause the model to weight recent context more heavily than early context.

Fix: Re-inject key facts at each step ("Remember: the user's budget is $500") or use a dedicated memory/state layer. See our guide to context engineering for AI agents for techniques.


ReAct in Production Frameworks (2026)

Most modern agent frameworks implement ReAct under the hood — often transparently:

FrameworkHow ReAct Is Implemented
LangGraphcreate_react_agent — stateful graph, native function calling, streaming
LangChainAgentExecutor with create_react_agent prompt (legacy, still works)
CrewAIDefault agent loop is ReAct-compatible; uses LLM's function calling
AutoGen / AG2GroupChat with tool-use agents wrapping ReAct behavior
OpenAI Agents SDKNative function calling = ReAct without text parsing overhead
Claude APITool use API provides native ReAct-equivalent behavior
Text Parsing vs. Native Function Calling

The original ReAct paper used text-parsed actions ("Action: search[query]"). Modern models support native function calling — the model outputs a structured JSON tool call instead of free-text. Native function calling is strictly better: no regex parsing, no malformed action errors, and the model is fine-tuned to use it correctly. When choosing a framework, prefer one that uses native function calling over text-parsed ReAct.


When NOT to Use ReAct

ReAct isn't always the right tool. Skip it when:

  • The task is fully deterministic — use a pipeline or workflow (n8n, Make) instead of an LLM reasoning loop
  • Token cost is critical — for tasks where the structure is known upfront, ReWOO or Plan-and-Execute will be 3–5x cheaper
  • The task has no useful tools — pure reasoning tasks (math proofs, classification) work better with Chain-of-Thought
  • Latency is paramount — each tool call adds a round-trip; a 5-step ReAct agent takes 5x longer than a single-call CoT response

For team-based workflows where you need multiple agents collaborating, ReAct is typically one node within a larger orchestration — not the entire architecture. See our guide to AI agent architecture patterns for the full picture.


Putting It All Together

The ReAct pattern is deceptively simple: reason, act, observe, repeat. But this loop is the foundation that lets an AI agent do things no pure language model can — query live data, write and run code, interact with APIs, and adapt to unexpected results.

In 2026, ReAct has evolved from text-parsed prompts to native function calling, from single-agent loops to sub-agents within larger multi-agent graphs. But the core insight from the original paper holds: grounding reasoning in real observations makes agents dramatically more reliable.

Whether you're building a personal automation agent or a production customer support system, understanding the ReAct loop means you can debug it when it breaks, optimize it when it's slow, and replace it with something better when the task calls for it.

cowork.ink gives your team a shared workspace for building, testing, and collaborating on AI agents — including ReAct-based workflows with real tool integrations. Set up your first agent in minutes.


Get Started

Ready to build your first ReAct agent? Start with LangGraph's create_react_agent for production use, or use the minimal Python implementation above for learning. For a deeper look at all agent reasoning patterns, see our guide to how AI agents reason.

Try cowork.ink free — collaborate on AI agents as a team, without the infrastructure headaches.

Frequently Asked Questions

What is the ReAct pattern in AI agents?
ReAct (Reason + Act) is an agent architecture where the model interleaves internal reasoning traces ("Thought: I need to look up X") with external tool calls ("Action: search[X]") and their results ("Observation: X is Y"). This loop repeats until the agent produces a final answer. Introduced by Yao et al. at ICLR 2023, it is the default agent pattern in LangChain and LangGraph.
How is ReAct different from Chain-of-Thought prompting?
Chain-of-Thought (CoT) keeps reasoning entirely inside the model — no external tools. ReAct extends CoT by adding tool actions between reasoning steps, grounding each thought in real observations. CoT is cheaper but relies on the model's parametric memory; ReAct reduces hallucination by checking facts against external sources at every step.
What are the main failure modes of the ReAct pattern?
The most common failure modes are infinite loops (the agent cycles through the same actions without progress), context window overflow (long trajectories exceed the model's context limit), and thought hallucination (the model reasons correctly but calls the wrong tool). A max_iterations guard and a context-length budget are essential safeguards in production.
Is the ReAct pattern still used in 2026?
Yes, but in evolved form. Most production agents use native function calling (GPT-4o, Claude 3.x, Gemini 2.x) which is functionally equivalent to ReAct but more reliable than text-parsed Thought/Action traces. The ReAct mental model — reason, act, observe, repeat — remains the dominant paradigm. LangGraph's create_react_agent is the standard production implementation.
What is the best framework for ReAct agents in 2026?
LangGraph (v1.0, GA October 2025) is the production standard. It implements ReAct as a stateful graph where nodes handle tool calls and edges route based on the model's next action. For simpler use cases, LangChain's create_react_agent still works. For multi-agent systems, CrewAI and AutoGen wrap ReAct internally.
Home Blog Company