Search

Search papers and lessons

ReAct: Synergizing Reasoning and Acting in Language Models

Shunyu Yao, Jeffrey Zhao, Dian Yu et al. · 2022

ReAct prompts a frozen language model to interleave written reasoning with tool actions, so each observation can correct the next thought, and it beats reasoning-only and acting-only prompting.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • Neural network basics
  • Linear algebra
  • Language & LLMs
  • Architectures
  • Sign in to see your progress

TL;DR

A language model that only writes reasoning can invent facts, and one that only takes actions can lose track of its plan. ReAct prompts a frozen large model to write a short thought, then an action on an outside tool, then read the tool's observation, and repeat. Because each observation returns to the model's context, the next thought can use it to correct course. On HotpotQA and FEVER the method reduces hallucination compared with chain-of-thought prompting, and on ALFWorld and WebShop it beats imitation and reinforcement learning baselines that were trained on far more data, using only a few in-context examples.

Where you'll see it: in the tool-using agent loops that many current assistants and agent frameworks run, where a model alternates between thinking and calling tools.

The problem

By 2022 two lines of work had grown up apart. Chain-of-thought prompting showed that a large model writes out intermediate steps and answers multi-step questions more accurately (Chain-of-Thought Prompting). That reasoning is a closed box. The model's only source of facts is what it memorised during training, so when a fact is wrong or missing, the steps build on the error. The authors call this fact hallucination and error propagation.

The other line used language models as planners in interactive settings: a household simulator, a shopping website, a game. There the model emits actions, and the environment answers. Those "act-only" agents do not explain themselves, and they tend to lose track of subgoals, or to keep acting on a state that no longer matches what they believed.

The paper asks whether one prompt can combine both: reasoning that plans and adjusts, and actions that bring in outside information.

Key idea

The move is simple. The action space of the agent is widened to include language. A "thought" is an action that does not touch the environment and produces no observation. It only changes the context the model sees next.

The authors describe the loop as thought, action, observation, repeated until the model calls a finish action. Figure 1 of the paper shows four prompting styles on one HotpotQA question. Standard prompting answers directly. Chain-of-thought reasons with no tools. Act-only calls the search tool with no explanation, and the paper notes it cannot reason over the trajectory to produce the correct final action. ReAct interleaves thoughts and actions, so it can extract facts from observations and decide what to search next.

flowchart LR
    Q[Question or task] --> T[Thought: plan or reason in words]
    T --> A[Action: search, lookup or move]
    A --> O[Observation from tool or environment]
    O --> T
    T --> F[Finish with answer]

The model is frozen. No weights change. The method is a prompt: a few hand-written trajectories that show the thought, action and observation pattern, followed by the new task. This is the "few-shot" or "in-context" style described in In-Context Learning.

The method

Setting

At each time step tt the agent receives an observation oto_t and picks an action ata_t from a policy π(at∣ct)\pi(a_t \mid c_t). The context is the history ct=(o1,a1,…,ot−1,at−1,ot)c_t = (o_1, a_1, \ldots, o_{t-1}, a_{t-1}, o_t). ReAct extends the action set from A\mathcal{A} to A^=A∪L\hat{\mathcal{A}} = \mathcal{A} \cup \mathcal{L}, where L\mathcal{L} is the set of all natural-language strings. A thought a^t∈L\hat{a}_t \in \mathcal{L} leaves the environment unchanged and updates the context to ct+1=(ct,a^t)c_{t+1} = (c_t, \hat{a}_t).

The authors note the cost. The language space is unbounded, so learning a useful policy over it is hard without strong language priors. That is why they use a large frozen model, PaLM-540B, and rely on prompting rather than training. Appendix A.1 of the paper also reports GPT-3 runs, which are discussed under Results below.

Knowledge-intensive tasks

For HotpotQA (multi-hop questions over Wikipedia) and FEVER (claim checking against Wikipedia), the paper gives the model a deliberately weak Wikipedia interface with three actions:

  • search[entity] returns the first five sentences of an entity's page, or a list of similar entities if the page does not exist.
  • lookup[string] returns the next sentence containing the string, like Ctrl+F in a browser.
  • finish[answer] ends the episode with an answer.

The interface is weak on purpose. It can only fetch passages by exact title, so the model has to reason about how to phrase searches. The authors say this simulates how a person would use Wikipedia, and it forces the search strategy to appear in the thoughts.

Prompts use 6 hand-written trajectories for HotpotQA and 3 for FEVER, chosen from the training set. The authors report that more examples did not improve results. Thoughts in these trajectories do several jobs: decompose the question ("I need to search x, find y, then find z"), extract facts from observations, do simple arithmetic, suggest a new query when a search fails, and state the final answer.

Interactive decision-making tasks

ALFWorld is a text game that mirrors the embodied ALFRED benchmark. An agent must complete one of six kinds of household task, such as examining an object under a lamp, using text actions like going to a location, taking an object or using a tool. A task instance can have more than 50 locations and take an expert policy more than 50 steps, so the agent has to plan, track subgoals and guess where items are likely to be.

WebShop is a simulated online store with 1.18 million products and 12,000 human instructions. The agent searches, opens products, picks options and buys. Success means the chosen product meets every requirement in the instruction.

On both tasks the prompt is a few trajectories with thoughts (ReAct) or without (Act). The authors also build an ablation called ReAct-IM, which replaces free-form thoughts with dense, inner-monologue-style feedback that just restates the environment state.

Baselines

To isolate what each part contributes, the paper builds several prompts from the same ReAct trajectories by removing pieces. Standard prompting removes thoughts, actions and observations. Chain-of-thought removes actions and observations. Act removes thoughts. CoT-SC samples 21 chain-of-thought answers at temperature 0.7 and takes the majority. The combined methods switch between a ReAct policy and CoT-SC. ReAct to CoT-SC falls back to CoT-SC when ReAct does not finish within 7 steps on HotpotQA or 5 steps on FEVER. CoT-SC to ReAct does the reverse when the majority answer of the sampled chains appears in fewer than half the samples, which signals that the model's internal knowledge is unsure.

Fine-tuning

Writing reasoning traces by hand does not scale. The authors bootstrap instead: they collect 3,000 trajectories with correct answers from ReAct and the other prompts, and use them to fine-tune smaller PaLM models (8B and 62B) to produce the whole trajectory of thoughts, actions and observations. The approach follows the bootstrapping idea of STaR (Zelikman et al., 2022).

Results

Question answering and fact checking

The table below reports the paper's Table 1 for PaLM-540B with few-shot prompting. HotpotQA scores are exact match (EM). FEVER scores are accuracy.

MethodHotpotQA EMFEVER accuracy
Standard28.757.1
Chain-of-thought (CoT)29.456.3
CoT with self-consistency (CoT-SC)33.460.4
Act only25.758.9
ReAct27.460.9
CoT-SC to ReAct34.264.6
ReAct to CoT-SC35.162.0

ReAct beats Act on both tasks, which the authors credit to reasoning helping the model use observations, especially when it has to write the final answer. ReAct beats CoT on FEVER by about 4.6 points (60.9 against 56.3) but trails CoT slightly on HotpotQA (27.4 against 29.4). The authors' explanation is that FEVER claims often differ only slightly between supported and refuted, so accurate, current retrieval matters more.

The best results come from combining the two. ReAct to CoT-SC is best on HotpotQA and CoT-SC to ReAct is best on FEVER. The paper also shows that these combinations reach the performance of CoT-SC with 21 samples using only 3 to 5 samples.

Where the errors are

To see why ReAct and CoT differ on HotpotQA, the authors labelled 50 trajectories from each method by hand. Their findings:

ObservationReActCoT
False positives (answer right, reasoning wrong)6%14%
Failures where the reasoning trace is wrong47%16%
Failures from an empty or unhelpful search23%none
Failures from hallucinated facts0%56%

So CoT's main failure is hallucination, and ReAct's main failure is reasoning error, often a repetitive loop of the same thought and action, which the authors suspect is caused by greedy decoding. The structure that keeps ReAct grounded also makes it less flexible.

Decision-making

On ALFWorld with PaLM-540B, the best ReAct trial reaches 71% success, against 45% for the best Act trial and 37% for the BUTLER imitation baseline. Even the weakest ReAct trial, at 48%, beats the best trial of Act and BUTLER. Across six controlled trials ReAct beats Act by a relative 33% to 90%, averaging 62%. The ablation ReAct-IM reaches 53%, so the free-form reasoning, which can set subgoals and recall where objects are likely to be, matters beyond simply reporting feedback.

On WebShop, one-shot Act already matches the imitation and imitation-plus-RL methods the authors compare against. Adding sparse reasoning gives an absolute improvement of about 10 points in success rate over the previous best. The paper's qualitative example is a model that reasons its way to choose a product whose options fit the instruction. Human experts still do better, mainly because they search more and reformulate queries more.

Other models and finetuning

Using GPT-3 (text-davinci-002, greedy decoding), ReAct scores 78.4% on the 134 unseen ALFWorld validation tasks, against 70.9% for PaLM-540B. The authors read this as evidence that the prompting method does not depend on one model.

For fine-tuning, the paper's scaling figure shows that prompting ReAct is the weakest of four methods at small sizes, because the model has to learn reasoning and acting from few examples. After fine-tuning on 3,000 trajectories, ReAct becomes the strongest of the four. The paper reports that fine-tuned PaLM-8B with ReAct beats prompted PaLM-62B, and fine-tuned PaLM-62B beats prompted 540B on HotpotQA. Fine-tuning on Standard or CoT trajectories helps much less, which the authors attribute to those teaching the model to memorise facts rather than to look them up.

Why it mattered

ReAct is among the first papers to put a reasoning trace and a tool call in the same loop for a language model, and the pattern became a standard way to build agents. Later systems that let a model call search, code or other tools while it writes its own plan use this interleaving, often with native tool-calling APIs instead of hand-written text.

The paper also made two lessons concrete. First, a model's reasoning is only as good as its facts, so grounding matters as much as the chain of steps. Second, the trace is readable: a person can see why the agent searched, and can edit a bad thought to change the outcome. The paper's appendix (A.3) shows a human editing two thoughts to make a failed ALFWorld run succeed, showing that a person can inspect and correct the agent's reasoning trace.

Some of the work it inspired is not in the paper itself. Its main limitations, a weak search tool, greedy decoding that loops, and reliance on very large frozen models, are the problems later agent research attacked, through better retrieval, sampling, and training on agent trajectories. The connection to Retrieval-Augmented Generation is direct: ReAct's Wikipedia lookup is a retrieval step that the model chooses to make.

Reading guide

Read the paper in this order, with these prerequisites in mind.

  1. Section 1 (Introduction). Needs Language Model and Chain-of-Thought Prompting. Figure 1 is the best single picture of the method.
  2. Section 2 (ReAct). Needs ReAct Prompting and In-Context Learning for the prompt format, and Markov Decision Process for the notation of states, actions and observations. The policy and context definitions are plain notation once that is clear.
  3. Section 3.1 to 3.2 (knowledge tasks: setup and methods). Needs Retrieval-Augmented Generation as background for why a retrieval tool helps, and Beam Search for the note on greedy decoding in footnote 6.
  4. Section 3.3 (results). Needs Softmax Temperature to understand the temperature 0.7 used in CoT-SC, and the majority-vote idea in self-consistency, which is covered in the paper's references.
  5. Section 3.2 (finetuning) and Section 3.3 (scaling). Needs Fine-Tuning.
  6. Section 4 (decision making). Needs Reinforcement Learning for the comparison with imitation and RL baselines, and Markov Decision Process for sparse reward.
  7. Section 5 (related work) and the appendix. Optional. The human-in-the-loop example in Appendix A.3 (Figure 5) needs nothing beyond this lesson.

Check yourself

QuestionRecall: what is the difference between a thought and an action in ReAct, and why does a thought produce no observation?Show answer

An action is a call to the environment, such as a search or a move, and it returns an observation. A thought is a piece of language written into the context. It does not change the external world, so the environment has nothing to report back. It only changes what the model sees on its next step, which is what lets the model plan and track progress without touching the world.

QuestionComputation: on HotpotQA, ReAct scores 27.4 EM and CoT scores 29.4. The paper's hand analysis finds hallucination in 56% of CoT failures. What share of CoT's failures are not hallucinations, using only the numbers in the analysis table?Show answer

The failure-mode shares for CoT are 16% reasoning error, 0% search error, 56% hallucination and 28% label ambiguity, which sum to 100%. The non-hallucination share is 100−56=44%100 - 56 = 44\%, made up of 16% reasoning error and 28% label ambiguity (right prediction that did not match the label exactly). The 14% false-positive figure is a different quantity: it is the share of CoT's successes whose reasoning or facts were hallucinated.

QuestionWhy: the paper says that ReAct helps on FEVER but not on HotpotQA compared with CoT. What property of the two tasks does the paper use to explain this?Show answer

The paper points to how FEVER claims are labelled. Supported and refuted claims can differ by only a small detail, so the answer depends on accurate and up-to-date facts, which retrieval supplies. HotpotQA questions depend more on multi-step reasoning that the rigid thought-action structure can make harder, and the search tool often returns unhelpful passages, so CoT's flexibility wins slightly there.

QuestionApplied: you want an agent that answers questions about your company's internal documents, using a search tool and a reasoning trace. The search tool returns empty results on about a quarter of queries. Using the paper's error analysis, what should you change first?Show answer

The paper's largest ReAct-specific failure after reasoning errors is unhelpful search, at 23% of failures. The first fix is the search tool, not the prompt: better retrieval, such as indexing and query expansion, so that fewer searches come back empty. Next, add a fallback like the paper's ReAct to CoT-SC switch, so that the agent answers from sampled reasoning when a search keeps failing. Finally, watch for the repetitive loop the paper observes, which a step cap and a different decoding strategy can limit.

Sources

Read the full paper

Shunyu Yao, Jeffrey Zhao, Dian Yu et al., 2022. arXiv:2210.03629