What is the ReAct pattern? Reason plus act for LLM agents
ReAct is the agent pattern where an LLM alternates thoughts, tool actions and observations. What the 2022 paper showed, with a runnable Python ReAct loop.

ReAct (short for “reasoning and acting”) is a prompting pattern in which a language model alternates between writing a thought, taking an action with a tool, and reading the observation that comes back, repeating until it can answer. It comes from the paper ReAct: Synergizing Reasoning and Acting in Language Models by Shunyu Yao and colleagues at Princeton and Google, posted on October 6, 2022 and published at ICLR 2023. Almost every tool-using agent since then runs some version of its loop.
What problem did ReAct solve?
In 2022 there were two separate lines of work. Chain-of-thought prompting got models to reason step by step, but only from what they already knew, so a wrong fact early in the chain carried through to a wrong answer. Action-only agents could click and search in an environment but had no space to plan, so they lost track of what they were doing.
ReAct puts both in one trajectory. The authors’ framing: reasoning helps the model “induce, track, and update action plans” (reason to act), and actions let it pull in outside information to reason with (act to reason). The model writes free-form thoughts between actions, and the environment’s responses are inserted into the prompt as observations.
How does the ReAct loop work?
For question answering, the paper gave the model a deliberately weak Wikipedia API with three actions:
search[entity]returns the first 5 sentences of the entity’s page, or suggests the top 5 similar entities.lookup[string]returns the next sentence on the page containing the string, like Ctrl+F.finish[answer]ends the task with an answer.
Each step in the prompt looks like this:
Thought 1: I need to find X, then use it to find Y.
Action 1: search[X]
Observation 1: <first sentences of X's page>
Thought 2: ...
The model writes the thought and the action. The harness stops generation, parses the action, runs it, appends the observation, and calls the model again. The prompts used a handful of hand-written example trajectories: 6 for HotpotQA and 3 for FEVER, all run on PaLM-540B.
What did the ReAct paper find?
The results were mixed in an instructive way.
On interactive tasks, ReAct won clearly. On ALFWorld, a text game of household tasks, the best ReAct trial reached a 71% success rate against 45% for the best action-only prompt and 37% for BUTLER, an imitation learning agent. On WebShop, a simulated shopping site, ReAct improved the success rate by an absolute 10 points over the previous best. In both, the agent without thoughts tended to lose track of its subgoals. The ALFWorld gap held across six controlled trials, with relative gains of 33% to 90% and an average of 62%.
On knowledge tasks, it traded accuracy for grounding. ReAct beat chain-of-thought on FEVER fact checking (60.9 vs 56.3 accuracy) but slightly trailed it on HotpotQA (27.4 vs 29.4 exact match). The authors then hand-labeled 200 trajectories to see why. Hallucination was chain-of-thought’s main failure mode, at 56% of its failures, while ReAct’s answers were grounded in what it retrieved. But ReAct had more reasoning errors, including a pattern where the model “repetitively generates the previous thoughts and actions” and never escapes the loop. And non-informative search results accounted for 23% of its errors: when retrieval returned nothing useful, the model struggled to recover.
Fine-tuning favored ReAct. With small models, ReAct prompting was the worst of the four methods, because learning to reason and act from a few examples is hard. Fine-tuned on 3,000 trajectories, it became the best: fine-tuned PaLM-8B ReAct beat every PaLM-62B prompting method. The authors’ explanation is that fine-tuning on facts teaches memorization, while fine-tuning on ReAct traces teaches a skill, how to look things up.
The best results combined both. Switching between ReAct and self-consistent chain-of-thought (backing off to chain-of-thought when ReAct ran out of steps, or to ReAct when the chain-of-thought samples disagreed) was the top prompting method on both HotpotQA and FEVER.
Two of those findings are still the two main failure modes of agents in 2026: loops that repeat, and bad retrieval that derails everything after it.
What does a ReAct loop look like in Python?
This script implements the paper’s three actions over a two-page toy wiki, parses Action N: tool[arg] lines with a regex, and feeds observations back. The model’s turns are scripted so it runs offline; in a real system each turn is an LLM call that receives the growing prompt. The second run shows the harness catching the repetition failure the paper describes.
# react.py: the ReAct loop with the paper's three actions, search[], lookup[] and finish[].
# Python 3 stdlib only. The LLM is replaced by scripted turns so it runs offline; the
# parsing, the tool calls, the observations and the loop guard are the real part.
import re
WIKI = {"Python (programming language)": "Python is a high-level programming language. "
"It was created by Guido van Rossum. Python was first released in 1991.",
"Guido van Rossum": "Guido van Rossum is a Dutch programmer. "
"He was born in Haarlem. He worked at Google and later at Dropbox."}
page = {"text": ""}
def search(entity):
if entity in WIKI:
page["text"] = WIKI[entity]
return WIKI[entity].split(". ")[0] + "."
return f"Could not find {entity}. Similar: {[k for k in WIKI if entity.split()[0] in k]}"
def lookup(term):
hits = [s for s in page["text"].split(". ") if term.lower() in s.lower()]
return hits[0] + "." if hits else f"No sentence with {term!r}."
ACTION = re.compile(r"Action \d+: (search|lookup|finish)\[(.*)\]")
def react(question, llm_turns, max_steps=6):
prompt, seen = f"Question: {question}\n", set()
for step, turn in zip(range(1, max_steps + 1), llm_turns):
prompt += turn + "\n" # the model's Thought + Action
print(turn)
kind, arg = ACTION.search(turn).groups()
if kind == "finish":
return arg
if (kind, arg) in seen: # the paper's repetitive-loop failure
print("Harness: same action twice, stopping.")
return None
seen.add((kind, arg))
obs = f"Observation {step}: " + (search(arg) if kind == "search" else lookup(arg))
prompt += obs + "\n" # fed back before the next turn
print(obs)
return None
turns = ["Thought 1: I need who created Python, then where that person was born.\n"
"Action 1: search[Python (programming language)]",
"Thought 2: The first sentence does not name the creator. I'll look for 'created'.\n"
"Action 2: lookup[created]",
"Thought 3: Guido van Rossum created it. Now find his birthplace.\n"
"Action 3: search[Guido van Rossum]",
"Thought 4: Search gave his nationality, not the place. Look up 'born'.\n"
"Action 4: lookup[born]",
"Thought 5: He was born in Haarlem.\nAction 5: finish[Haarlem]"]
print("Answer:", react("Where was the creator of Python born?", turns))
print("\n--- a model stuck in a loop ---")
stuck = ["Thought 1: Search the creator.\nAction 1: search[Guido]",
"Thought 2: Not found. Search again.\nAction 2: search[Guido]"]
print("Answer:", react("Where was the creator of Python born?", stuck))
Output (Python 3.14.5):
Thought 1: I need who created Python, then where that person was born.
Action 1: search[Python (programming language)]
Observation 1: Python is a high-level programming language.
Thought 2: The first sentence does not name the creator. I'll look for 'created'.
Action 2: lookup[created]
Observation 2: It was created by Guido van Rossum.
Thought 3: Guido van Rossum created it. Now find his birthplace.
Action 3: search[Guido van Rossum]
Observation 3: Guido van Rossum is a Dutch programmer.
Thought 4: Search gave his nationality, not the place. Look up 'born'.
Action 4: lookup[born]
Observation 4: He was born in Haarlem.
Thought 5: He was born in Haarlem.
Action 5: finish[Haarlem]
Answer: Haarlem
--- a model stuck in a loop ---
Thought 1: Search the creator.
Action 1: search[Guido]
Observation 1: Could not find Guido. Similar: ['Guido van Rossum']
Thought 2: Not found. Search again.
Action 2: search[Guido]
Harness: same action twice, stopping.
Answer: None
The first run is a two-hop question, the HotpotQA shape: the answer needs a fact from one page to know which page to open next. The thoughts do real work here. Thought 2 notices the observation didn’t answer the question and changes tactic from search to lookup. In the second run, the observation even suggested the right page, and the model ignored it. The harness, not the model, is what stops it.
Is ReAct still used, now that models have native tool calling?
The text format is mostly gone; the loop is everywhere. In 2022, actions were lines of text the harness had to parse with a regex, as above. Since 2023, tool calling gives the model a structured channel for actions, so parsing errors disappeared. And reasoning models can do the “thought” step in a dedicated thinking channel. The structure of thought, action, observation, repeat is the same loop that an AI agent runs today, and the failure modes ReAct named still apply. Anthropic’s description of agents in Building effective agents, LLMs “using tools based on environmental feedback in a loop”, is the ReAct loop with a structured action channel.
What has changed is the scale of the observation. The paper’s search returned five sentences. A modern agent can pull a 30,000-token web page into context, which makes bad retrieval more expensive and more dangerous: more noise to reason over, and more room for injected instructions.
What I would do
When I build anything ReAct-shaped, three rules come straight from the paper:
- Make actions small and observations short. The paper’s tiny API forced the model to reason about what to look up. Trim tool results to what the next step needs.
- Detect repetition in the harness. Hash each (tool, arguments) pair and stop or intervene on a repeat. Don’t count on the model to notice.
- Treat retrieval quality as the main lever. A quarter of ReAct’s errors came from non-informative searches. Better search beats a better prompt, which is the whole premise of agentic RAG.
FAQ
What does ReAct stand for?
Reasoning and acting. The model interleaves reasoning traces (thoughts) with actions (tool calls) and observations (tool results).
What is the difference between ReAct and chain-of-thought?
Chain-of-thought reasons only from what the model already knows. ReAct adds actions, so the model can fetch information mid-reasoning and correct itself. In the paper, that reduced hallucination but added new failure modes like repetitive loops.
Is ReAct the same as function calling?
No, but they fit together. ReAct is the loop pattern; function calling is the API feature that modern agents use to express the “act” step in structured JSON instead of parsed text.
Who wrote the ReAct paper?
Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan and Yuan Cao. It was first posted to arXiv on October 6, 2022 and appeared at ICLR 2023.
Sources
- Yao et al., ReAct: Synergizing Reasoning and Acting in Language Models, arXiv 2210.03629, v1 October 6, 2022, v3 (ICLR 2023 camera-ready) March 10, 2023
- Anthropic, Building effective agents, December 19, 2024