Skip to main content

Concepts

Agents: the reason-act-observe loop (ReAct)

Intuition

Think of someone cooking from a recipe: between one step and the next, they talk to themselves ("I've already chopped the onion, the garlic is left; I don't have garlic, let me see what could substitute for it") and, when information is missing, they go look in the pantry or search elsewhere. Thinking alone, without looking at the world, leads to making things up; acting without thinking leads to charging ahead with no plan. ReAct makes a language model work in the mixed way: it thinks a little, makes a query or action, looks at what came back, and thinks again from there.

How it works

ReAct expands an agent's action space to include free-form language as well: an action in that space is a thought (a reasoning trace), which does not change the external environment and therefore produces no observation in return; it is only added to the context, which accumulates everything that has happened so far, to support the reasoning and actions that follow. Thoughts serve to decompose the goal into a plan, inject commonsense, extract what matters from an observation, track progress, and handle exceptions. Actions, by contrast, go to an external tool or environment and return an observation. In the paper, the HotpotQA and FEVER tool is a simple Wikipedia API with three actions: search[entity] (first 5 sentences of the page), lookup[text] (next sentence containing the text, like Ctrl+F), and finish[answer]. The authors say this API is weaker than modern retrievers and that the purpose of the design is to simulate how people interact with Wikipedia and to force the model to decide what to search for through explicit reasoning. The loop is: the thought decides what to search for, the action queries, the observation brings back the result, and the next thought interprets it, possibly reformulating the search before answering. The model (PaLM-540B, frozen) is guided only by a few human-written examples in the prompt, with thoughts, actions, and observations; in tasks with many actions, thoughts appear sparsely and the model itself decides where to insert them. The failure modes described are: the rigid structure reduces reasoning flexibility (47% of the analyzed ReAct failures were reasoning errors, versus 16% for CoT), the model can repeat the same thoughts and actions without leaving the loop, and 23% of failures come from searches that return no useful information and mislead the model.

In practice

In the paper, the loop was tested on HotpotQA and FEVER with the Wikipedia API and in two interactive environments: on ALFWorld, ReAct's best trial had a 71% success rate versus 45% for the best Act, and on WebShop it had 40.0% versus 59.6% for expert humans. Compared with chain-of-thought, the observed trade-off was less hallucination (hallucination was 56% of CoT's failures and 0% of ReAct's failure samples) in exchange for more reasoning errors, and so the authors propose combining the methods, falling back to CoT with self-consistency if ReAct does not answer within 7 steps on HotpotQA or 5 on FEVER. The authors also caution that connecting a language model to actions in the world brings risks, and they restricted the experiments to Wikipedia and WebShop.

Use it in a design

Practice the cases that rely on this concept in the System Design school.