ReAct – Mangrove

GlossaryAgents and tools

ReAct

Definition: ReAct is a prompting method in which a language model alternates written reasoning steps with actions, such as searches, and reads each result.

A ReAct prompt shows a model a few worked examples, and the model then solves a new task as a series of steps. Each step has a thought, which is text the model writes to plan, interpret a result or decide what to do next; an action, such as a search; and an observation, which is the result of the action, added to the model’s context before the next step. Writing a thought calls nothing outside the model, so it returns no observation. In the paper’s question-answering and fact-verification tests, the actions were calls to a simple Wikipedia API that could search for a page, look up a phrase within it and submit a final answer. Chain of thought, a separate entry, produces reasoning steps without actions, and tool use, another entry, is the mechanism that runs an action a model requests. ReAct alternates the two. For example, an agent built this way may write that it needs the latest price of an asset, call a price tool, read the price that comes back and then write its next step.

The authors prompted the large language model PaLM-540B with hand-written examples and did not retrain it. In ALFWorld, a text game in which an agent completes household tasks such as examining a paper under a desk lamp, ReAct prompts succeeded in 57% of 134 unseen games on average across six prompts and in 71% at best. The best of six prompts built from the same examples with the thoughts removed succeeded in 45%. In WebShop, a simulated shopping site with 1.18 million real products, ReAct bought a product that met every requirement of a written instruction for 40.0% of 500 test instructions, against 29.1% for a method trained on 1,012 human demonstrations and 59.6% for expert humans.

On HotpotQA, a set of questions that each need facts from two or more Wikipedia passages, ReAct alone gave an exactly matching answer to 27.4% of questions, slightly fewer than the 29.4% from chain-of-thought prompting. The authors labeled 50 failed answers from each method by hand. Hallucinated facts or reasoning caused 56% of chain of thought’s failures and none of ReAct’s. ReAct failed more often through reasoning errors, 47% of its failures against 16% for chain of thought, including repeating its own earlier thoughts and actions, and 23% of its failures followed searches that returned nothing useful. Among the prompting methods tested, the highest HotpotQA score, 35.1%, came from switching to chain-of-thought prompting with a majority vote over 21 samples whenever ReAct gave no answer within seven steps. The same table lists 67.5% for the best model trained on HotpotQA itself.

Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan and Yuan Cao, of Princeton University and Google Research’s Brain team, introduced the method in ReAct: Synergizing Reasoning and Acting in Language Models, posted to arXiv on 6 October 2022 and published at the 2023 International Conference on Learning Representations. They wrote that, to their knowledge, ReAct was the first demonstration of a large language model combining reasoning and action in an interactive environment where the results of its actions fed back into its next steps, and they named Inner Monologue (Huang et al., 2022) as perhaps the closest earlier work.