AI Summary Hub

ReAct (Reasoning + Acting)

Interleaving reasoning and action in agents.

Definition

ReAct is a paradigm where the model alternates reasoning (what to do next, why) and acting (tool calls). The observation from the environment feeds back into the next reasoning step, forming a loop until the task is done. This interleaving reduces errors caused by blind or repetitive tool use, because each action is preceded by an explicit rationale.

The core contribution of the ReAct paper is showing that combining reasoning traces and action steps in a single LLM call outperforms either alone: pure reasoning (CoT) misses factual grounding, and pure action (tool calling without thought) is error-prone and hard to debug. By making thoughts visible, ReAct also produces interpretable agent traces that humans can inspect and correct.

It is the standard pattern for agents that use tools. Often combined with chain-of-thought (reasoning inside the thought step) and with RDD when retrieved specifications should guide each decision.

How it works

Thought–action–observation loop

Agent decision flow

Prompt format is Thought → Action → Observation → Thought → … → Final Answer. The user gives a task; the agent produces a thought (reasoning about what to do), then an action (e.g. tool call). The environment/tools return an observation, which is appended to the context for the next thought. The model decides when to call tools and when to conclude. Frameworks like LangChain and LlamaIndex implement ReAct-style agents with tool registration and message handling.

When to use / When NOT to use

ScenarioUse ReActDon't use ReAct
Agent using multiple tools (search, calculator, API)Yes — thought before action reduces tool misuseNo — if only one tool is needed, simpler function calling suffices
Debuggable agent behavior requiredYes — thought traces are inspectable and loggableNo — for black-box pipelines where traces aren't needed
Multi-step research with evolving contextYes — each observation informs the next thoughtNo — single-shot retrieval + generation is faster and cheaper
High-reliability tasks (e.g. code execution)Yes — reasoning before acting catches likely errorsNo — for simple CRUD tasks with no ambiguity
Very low latency requirementsNo — thought generation adds tokens per stepYes — direct function calling is faster when reasoning is unnecessary

Comparisons

PatternHas explicit thoughtHas tool useLoopBest for
CoTYesNoNoStatic reasoning tasks
ReActYesYesYesTool-using agents
Function calling (no thought)NoYesNoSimple, deterministic tool invocations
RDDYes (spec-guided)YesYesCompliance and spec-driven agents

Pros and cons

ProsCons
Reduces blind or repetitive tool callsExtra tokens per step (thought overhead)
Produces interpretable, debuggable tracesLoop can run too long if stopping criteria are weak
Works well with LangChain/LlamaIndex out of the boxRequires well-defined tool schemas and error handling
Naturally handles multi-step tasksThought quality depends on the underlying model

Code examples

from langchain_openai import ChatOpenAI
from langchain.agents import create_react_agent, AgentExecutor
from langchain_community.tools import DuckDuckGoSearchRun
from langchain import hub

# Load a pre-built ReAct prompt template
prompt = hub.pull("hwchase17/react")

# Define tools
tools = [DuckDuckGoSearchRun()]

# Create ReAct agent
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
agent = create_react_agent(llm=llm, tools=tools, prompt=prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True, max_iterations=5)

# Run — the agent will produce Thought/Action/Observation traces
result = executor.invoke({"input": "What is the current population of Tokyo?"})
print(result["output"])

Practical resources

Sources

See also