Back to paper library
Paper notesarXiv 2022ICLR 2023

ReAct

Knowing and Doing as One

Original paper

ReAct: Synergizing Reasoning and Acting in Language Models

Paper authors

Shunyu Yao · Jeffrey Zhao · Dian Yu …

Show all 7 authors

Shunyu Yao · Jeffrey Zhao · Dian Yu · Nan Du · Izhak Shafran · Karthik Narasimhan · Yuan Cao

Publication
ICLR 2023Conference
First submitted to arXiv
arXiv:2210.03629
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{transformersreact2022,
  title = {{ReAct: Synergizing Reasoning and Acting in Language Models}},
  author = {Shunyu Yao and Jeffrey Zhao and Dian Yu and Nan Du and Izhak Shafran and Karthik Narasimhan and Yuan Cao},
  year = {2022},
  eprint = {2210.03629},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2210.03629}
}
On this page

In 2022, Chain-of-Thought (CoT) showed everyone that asking a large language model to “think step by step” noticeably improves its arithmetic and commonsense reasoning.

But CoT does all its thinking inside its own head.

The model relies on knowledge stored in its parameters. If it misremembers a fact halfway through, every subsequent step builds on that mistake, eventually producing a very orderly argument for the wrong answer.

Meanwhile, other research let language models act in an environment, such as planning robot movements, clicking buttons on a web page, or calling a search engine. Most of those approaches predicted actions without giving the model much room to pause and think about the situation.

This paper from Princeton University and Google Research's Brain team proposes alternating the two, so the model can think a step, take an action, observe the result, then think about the next step. The authors call it ReAct, combining Reasoning and Acting.

It is also one of the starting points most often cited in the history of agents that look things up for themselves.

Defining the Problem

Start with the paper's motivating example. The question comes from HotpotQA, a multi-hop question-answering dataset that requires combining information from multiple Wikipedia sources:

Aside from the Apple Remote, what other device can control the program Apple Remote was originally designed to work with?

To answer, you first need to find the program Apple Remote was designed for, then look up what else can control it.

The authors have the model answer in four ways:

Four approaches to a HotpotQA question: Standard, CoT, and Act-Only answer incorrectly; ReAct alternates reasoning and search to answer correctly
Figure 1(1) from the paper, excerpted from page 2 of the v3 PDF, CC BY 4.0. Red marks errors or hallucinations; green marks correct information obtained through search. The ALFWorld example in the lower half of the original figure is omitted.

(1a) Standard: It answers “iPod” directly. Wrong.

(1b) CoT: The model starts reasoning step by step: “Apple Remote was originally designed for Apple TV; Apple TV can be controlled with an iPhone, iPad, and iPod Touch.” The reasoning flows smoothly, but the first statement is wrong. The red portions are hallucinations. Naturally, the answer is wrong too.

(1c) Act-Only: Search without reasoning. The model searches for Apple Remote, then Front Row, and even finds “Front Row (software).” But it cannot turn these observations into an answer. It eventually answers “yes.”

(1d) ReAct:

  • Thought 1: I need to search for Apple Remote and find out which program it was originally designed for.
  • Act 1: Search[Apple Remote]
  • Obs 1: Apple Remote is a remote control introduced by Apple in 2005… originally designed to control the Front Row media center program.
  • Thought 2: It was designed for Front Row. Next, search for Front Row to find what else can control it.
  • Act 2: Search[Front Row]
  • Obs 2: [Front Row] was not found. Similar entries: “Front Row Seat to Earth,” “Front Row Motorsports,” “Front Row (software)”…
  • Thought 3: Front Row was not found. I'll search for Front Row (software) instead.
  • Act 3: Search[Front Row (software)]
  • Obs 3: Front Row is a discontinued media center application…
  • Thought 4: Front Row (software) can be controlled with Apple Remote or keyboard function keys. So the answer is keyboard function keys.
  • Act 4: Finish[keyboard function keys]

Correct.

Compared side by side, the four approaches each get stuck in a different place:

  • Thinking without checking (CoT) can lead the model astray through misremembered facts.
  • Checking without thinking (Act) can retrieve information without knowing how to use it.

The authors want to know whether interleaving reasoning and action can make up for the weaknesses of each.

Solving the Problem

Treating Thought as an Action

The authors first describe the problem in an agent framework.

At time tt, the agent receives an observation oto_t from the environment and chooses an action ata_t based on the context so far, ct=(o1,a1,…,ot−1,at−1,ot)c_t=(o_1,a_1,\dots,o_{t-1},a_{t-1},o_t).

ReAct's idea is to expand the action space to include language.

A^=A∪L\hat{\mathcal{A}}=\mathcal{A}\cup\mathcal{L}

A\mathcal{A} contains the original actions that affect the environment, such as search; L\mathcal{L} is the language space. An “action” selected from L\mathcal{L} is a thought.

A thought does not change the environment, so it produces no new observation. Its role is to organize the current context and write the result back into it for the next step:

ct+1=(ct,a^t)c_{t+1}=(c_t,\hat{a}_t)

In the example above, thoughts serve several purposes, including breaking down the problem (Thought 1), extracting key facts from observations (Thoughts 2 and 4), adjusting the plan after an exception (Thought 3), and assembling the final answer (Thought 4).

A Minimal Wikipedia Tool

For the two knowledge tasks, HotpotQA and FEVER, the authors design a very basic Wikipedia API with just three actions:

  1. search[entity]: If the entry exists, return the first five sentences of the page. Otherwise, list the top five similar entries found by the search engine.
  2. lookup[string]: Return the next sentence on the current page containing that string, much like Ctrl+F in a browser.
  3. finish[answer]: Submit the answer and end the task.

The authors emphasize that these actions generally retrieve short passages using exact entity names, making them much weaker than the best lexical or neural retrievers of the time. This is deliberate, because they want to imitate how people browse Wikipedia and make the model use language reasoning to decide what to look up.

FEVER is a fact-verification dataset in which each claim is classified as “supports,” “refutes,” or “not enough information.” For both tasks, the model receives only the question or claim, without any reference passages.

How Do You Get the Model to Do This?

The main experiments train no new model. They use a frozen PaLM-540B with only a few demonstrations in the prompt.

The authors randomly choose six HotpotQA questions and three FEVER claims from the training sets, manually write complete thought–action–observation trajectories, and include them as examples. They also report that adding more examples did not help.

At inference time, it runs as a loop. The model continues the prompt with this step's thought and action and stops just before “Obs”; the program then actually runs the search and appends the result to the prompt as the observation, and the model writes the next step. The loop ends when the model writes finish or runs out of steps. The observations come from the environment; the model does not make them up.

When Should It Trust Itself?

While analyzing the results, the authors find that ReAct and CoT have different strengths, with ReAct more grounded in facts and CoT better at organizing a reasoning structure.

They therefore design two hybrids. Here CoT-SC is the self-consistency version of CoT, which samples 21 reasoning paths at temperature 0.7 and takes the majority answer.

  • ReAct → CoT-SC: If ReAct cannot answer within the step budget, fall back to CoT-SC. HotpotQA allows seven steps and FEVER five. Among successful trajectories, only 0.84% and 1.33%, respectively, use all seven or five steps.
  • CoT-SC → ReAct: If the most common answer among nn CoT-SC samples appears fewer than n/2n/2 times, the model lacks confidence in its knowledge and switches to ReAct to check.

Discussion

Results on Knowledge Tasks

MethodHotpotQA (EM)FEVER (accuracy)
Standard28.757.1
CoT29.456.3
CoT-SC33.460.4
Act25.758.9
ReAct27.460.9
CoT-SC → ReAct34.264.6
ReAct → CoT-SC35.162.0
Supervised SoTA67.589.5

Compiled from Table 1 of the paper. The model is PaLM-540B.

Between ReAct and Act, ReAct is better on both tasks. Both can search, but adding thought changes their ability to assemble an answer.

Against CoT, ReAct wins on FEVER (60.9 versus 56.3) but does slightly worse on HotpotQA (27.4 versus 29.4). The authors explain that “supports” and “refutes” in FEVER can differ by a small detail, making accurate information especially important.

The best results come from the two hybrids, with ReAct → CoT-SC reaching 35.1 on HotpotQA and CoT-SC → ReAct reaching 64.6 on FEVER. In additional curves over sample counts, both hybrids match the performance of CoT-SC with 21 samples using just three to five.

The last row, however, shows that all these prompting methods remain far behind the best supervised models. HotpotQA's 67.5 and FEVER's 89.5 come from systems trained specifically for those tasks.

What Goes Wrong?

To understand the difference between ReAct and CoT on HotpotQA, the authors sample 50 correct and 50 incorrect trajectories from each, 200 in total, and manually label their success and failure types:

TypeDescriptionReActCoT
Success: true positiveCorrect reasoning and facts94%86%
Success: false positiveCorrect answer, but fabricated reasoning or facts6%14%
Failure: reasoning errorFaulty reasoning, including getting stuck repeating steps47%16%
Failure: search result errorSearch returns nothing or no useful information23%—
Failure: hallucinationFabricated reasoning or facts0%56%
Failure: label ambiguityCorrect answer with wording different from the reference29%28%

Compiled from Table 2 of the paper. Success and failure percentages are calculated separately.

The table breaks down the causes of success and failure separately.

Hallucination is CoT's biggest problem. Among CoT's incorrect cases, 56% involve hallucination. Even among correct answers, 14% happen to arrive at the right answer through invented reasoning. Among ReAct's incorrect cases, hallucination accounts for 0%.

But ReAct has problems of its own. Reasoning errors account for 47% of its failures, far above CoT's 16%. The authors observe a failure pattern specific to ReAct: the model keeps repeating earlier thoughts and actions and cannot escape the loop. Interleaving thoughts, actions, and observations grounds the reasoning, but also makes it less flexible.

Failed searches can derail ReAct. In 23% of failures, search finds no useful information, and the model struggles to reorganize its reasoning.

The authors also find that some HotpotQA reference answers are outdated.

Smaller Models Come Out Ahead After Fine-Tuning

With prompting alone, ReAct is the worst of the four approaches on PaLM-8B and 62B, since smaller models struggle to learn both reasoning and action from a handful of examples.

The authors then fine-tune smaller models on 3,000 successful trajectories generated by ReAct itself. The results reverse.

  • Fine-tuned PaLM-8B ReAct beats every prompting method using PaLM-62B.
  • Fine-tuned PaLM-62B ReAct beats every prompting method using PaLM-540B.

Fine-tuning Standard or CoT is much less effective. The authors explain the distinction this way: those approaches teach the model to memorize potentially hallucinated facts, whereas ReAct teaches it how to reason and look things up on Wikipedia—skills that generalize better.

Beyond Question Answering

The authors also test two interactive decision-making tasks:

  • ALFWorld: A text-based household game, with tasks such as finding a pepper shaker and putting it in a drawer. The best ReAct trial achieves an average success rate of 71%, versus a best of 45% for action-only Act and 37% for the imitation-learning method BUTLER.
  • WebShop: A simulated shopping website with 1.18 million real products, where the agent finds products matching a user's description.

According to the abstract, with only one or two demonstrations, ReAct improves success rates on the two tasks by 34 and 10 percentage points over imitation-learning and reinforcement-learning methods, respectively. Those comparison methods train on 10310^3 to 10510^5 task examples.

You Can Build It Without a Framework

Another attraction of ReAct is its simplicity. You barely need a framework.

In March 2023, Simon Willison wrote a simple Python implementation using gpt-3.5-turbo. A system prompt asks the model to output Thought, Action, PAUSE, and Observation in sequence, followed by an Answer. The program uses a regular expression to extract the Action: line, runs the corresponding tool—Wikipedia search, his own blog search, or a calculator—and sends the result back as an Observation:, for at most five rounds.

He also warns that the calculator directly uses Python's eval(), which is extremely dangerous and should run in a sandbox such as WebAssembly. The implementation is also still quite fragile.

Once the model decides which tools to call, safety and robustness become engineering concerns. The paper spends relatively little time on them.

Conclusion

At its core, ReAct adds thought to the agent's action space, allowing the language model to alternate reasoning and action.

The paper's evidence shows:

  1. Looking things up without thinking wastes information. With the same search access, ReAct beats action-only Act on both HotpotQA and FEVER.
  2. Thinking without checking invites hallucination. Hallucination accounts for 56% of CoT's incorrect cases and 0% of ReAct's, although ReAct makes more reasoning errors and can get stuck in loops.
  3. Combining the two works best. Switching between ReAct and CoT-SC based on confidence or step limits produces the best prompting results on both knowledge tasks.
  4. Fine-tuning amplifies the effect. After training on 3,000 trajectories, smaller ReAct models beat the prompting approaches of larger models.

These prompting methods still lag far behind task-specific trained systems, and the Wikipedia tools are deliberately weak.

But the loop—think, look something up, observe, think again—stuck around. Later coding agents that search files and run commands follow much the same pattern. The tools have simply changed from three Wikipedia actions to grep, file reading, and a terminal.