All papersFoundationsClassic
Let the model think, act, look, then think again
Paper: ReAct: Synergizing Reasoning and Acting in Language Models
Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, Yuan Cao · ICLR 2023 · Posted · 18 min read · arXiv 2210.03629
- Models were taught to reason or to act, not both.
- Reasoning alone cannot check facts in the world.
- That leads to made-up facts and error spread.
- Acting alone has no plan and loses track.
71%success rate for ReAct on ALFWorld, versus 37% for the best imitation agent.
- They used PaLM-540B with a few examples in the prompt.
- Tasks: question answering, fact checking, a text game and web shopping.
- They compared with reason-only, act-only and trained agents.
- They also finetuned smaller models.
- ReAct beats acting alone on every task.
- It made up facts in 0% of failures, versus 56% for chain of thought.
- Mixing ReAct and chain of thought scored best on question answering.
- On WebShop, it beat the best success rate by 10%.
ReAct beats imitation learning and acting only on ALFWorldFrom Table 3Hover, tap or focus a bar to read its exact value.
| Method | Success (%) |
|---|
| BUTLER (best of 8) | 37 |
| Act (best of 6) | 45 |
| ReAct-IM (best of 6) | 53 |
| ReAct (best of 6) | 71 |
- The agent can get stuck in loops that repeat the same step.
- It makes more reasoning errors than chain of thought.
- Hard tasks need more examples than the prompt can hold.
- Tool access has risks. The paper kept tests to safe sites.
Jump to
Every detail from the paper
Cards follow the paper's own order. Dotted words link to Words to know. Numbers match the paper.
The idea
- Language models were studied for reasoning and for acting as separate topics.
- The authors let one model do both, taking turns.
- They call the method ReAct.
Why both
- Reasoning helps the model make, track and update action plans.
- It also helps with exceptions.
- Actions let the model get new facts from outside sources, such as a knowledge base.
The results
- On HotpotQA and Fever, ReAct cuts hallucination and error spread seen in chain of thought.
- It uses a simple Wikipedia API.
- On ALFWorld and WebShop, ReAct beats imitation and reinforcement learning by 34% and 10%.
- It needs only one or two examples in the prompt.
Reasoning and acting together
- People mix actions with inner speech.
- Cooking example: "now that everything is cut, I should heat up the pot of water".
- Or: "I don't have salt, so let me use soy sauce and pepper".
- Or: "how do I prepare dough? Let me search on the Internet".
- Acting then supports reasoning: open the fridge, check ingredients.
Reasoning alone
- Chain of thought shows models can reason in steps.
- But it is a static black box.
- It uses only the model's own memory, not the outside world.
- That leads to made-up facts and error propagation.
Acting alone
- Other work lets language models plan and act in interactive worlds.
- These models predict actions from language priors.
- They do not reason about high-level goals or keep a working memory.
Four ways to answer a questionFrom Figure 1- Standard: answer straight away
- Chain of thought: reason only
- Act only: search, no thoughts
- ReActReAct: think, act, observe
The example question asks what other device can control the Apple Remote's program. Only ReAct finds the right answer.
The idea
- ReAct prompts a model to write thoughts and actions in turns.
- Reason to act: thoughts create, keep and adjust plans.
- Act to reason: actions bring in new information from outside.
Tests
- Four benchmarks: HotPotQA (question answering) and Fever (fact checking).
- ALFWorld (a text game) and WebShop (web shopping).
Findings
- On HotPotQA and Fever, ReAct beats acting alone and is close to chain of thought.
- The best result is ReAct plus CoT: internal and outside knowledge together.
- On ALFWorld and WebShop, one or two examples win.
- They beat methods trained on 10^3 to 10^5 tasks.
- Gains: 34% and 10% in success rate.
- Humans can inspect thoughts and see which facts came from outside.
Four contributions
- 1. ReAct: a prompt-based way to combine reasoning and acting.
- 2. Tests across diverse benchmarks.
- 3. Ablations on acting in reasoning tasks and reasoning in action tasks.
- 4. Limits under prompting, and early finetuning tests.
The setup
- An agent gets an observation and picks an action at each step.
- The context is the full history of observations and actions.
- Mapping context to action is hard when it needs much thinking.
- Figure 1 (1c): an acting-only agent fails to give the final answer.
- Figure 1 (2a): it misses that sinkbasin 1 has no peppershaker, so it repeats.
The idea
- ReAct adds language to the action space.
- A thought is an action in language.
- A thought does not change the world, so it gets no observation.
- It reasons over the context and adds to it for later steps.
The ReAct loopFrom Section 2 and Figure 1- Task question
- ThoughtThought: plan next step
- ActAction: search a source
- ObsObservation: result comes back
- Thought: update plan
- Final answer
Thoughts and actions repeat until the model can answer.
Kinds of useful thoughts
- Break a goal into an action plan.
- Add commonsense knowledge.
- Pull key facts from observations.
- Track progress and change plans.
- Handle exceptions and adjust.
How they run it
- The language space is unlimited, so learning there needs strong language priors.
- So they use a frozen PaLM-540B with a few-shot prompt.
- Each example is a human trajectory of actions, thoughts and observations.
- Reasoning-heavy tasks alternate thought and action.
- Tasks with many actions use sparse thoughts, placed where useful.
- The model decides when to think.
Four features
- A) Easy to design. People type thoughts on top of actions.
- B) General. It works with different action spaces and reasoning needs.
- C) Strong. It learns from one to six examples. It is robust to prompt choice.
- D) Human aligned. People can inspect and fix thoughts.
- Editing a thought can steer the agent (Figure 5).
Two datasets
- HotPotQA: multi-hop questions over two or more Wikipedia passages.
- FEVER: claims labeled SUPPORTS, REFUTES or NOT ENOUGH INFO.
- Both use a question-only setup. The model has no support text.
- It must use its memory or search.
Wikipedia API: three actions
- search[entity] returns the first 5 sentences of the page, or the top-5 similar entities.
- lookup[string] returns the next sentence in the page with the string, like Ctrl+F.
- finish[answer] ends the task with an answer.
A weak tool, on purpose
- It can only find a small part of a page by exact name.
- That is much weaker than state-of-the-art search.
- The aim is to copy how people use Wikipedia.
- It forces the model to search through explicit reasoning.
ReAct prompts
- For HotpotQA they pick 6 cases from the training set. For Fever, 3.
- They write ReAct trajectories by hand.
- More examples do not help.
- Thoughts split questions, pull facts, use commonsense or arithmetic, and guide search.
- Thoughts also synthesize the final answer.
Baselines
- Standard: no thoughts, actions or observations.
- CoT: thoughts only, no actions.
- CoT-SC: 21 CoT samples at temperature 0.7, take the majority answer.
- Act: actions only, no thoughts.
Mixing ReAct with chain of thoughtFrom Section 3.2- ReAct finds no answer in steps
- ReAct→CoT-SCFall back to CoT-SC
- CoT-SC majority below half
- CoT-SC→ReActFall back to ReAct
ReAct has 7 steps for HotpotQA and 5 for Fever. More steps did not help.
Combining both
- ReAct is more factual and grounded.
- CoT forms better reasoning but can invent facts.
- So the model switches to the other method with two rules.
- Rule A: if ReAct gives no answer in 7 steps (5 for Fever), use CoT-SC.
- Rule B: if the CoT-SC majority is under n/2, back off to ReAct.
Finetuning
- Manual traces do not scale, so they bootstrap.
- They take 3,000 correct ReAct trajectories.
- They finetune smaller models, PaLM-8B and 62B, on them.
ReAct versus Act
- ReAct beats Act on both tasks.
- Reasoning guides acting, most for the final answer.
- Finetuning confirms it.
Combining ReAct and chain of thought scores best on both tasksFrom Table 1HotpotQA (EM)Fever (accuracy)
Hover, tap or focus a bar to read its exact value.
| Method | HotpotQA (EM) (%) | Fever (accuracy) (%) |
|---|
| Standard | 28.7 | 57.1 |
| CoT | 29.4 | 56.3 |
| CoT-SC | 33.4 | 60.4 |
| Act | 25.7 | 58.9 |
| ReAct | 27.4 | 60.9 |
| CoT-SC then ReAct | 34.2 | 64.6 |
| ReAct then CoT-SC | 35.1 | 62.0 |
Table 1 notes
- Supervised state of the art: 67.5 on HotpotQA and 89.5 on Fever.
- HotpotQA EM for Standard, CoT, CoT-SC in Wang et al is 27.1, 28.9, 33.8.
ReAct versus CoT
- ReAct beats CoT on Fever: 60.9 versus 56.3.
- It trails CoT on HotpotQA: 27.4 versus 29.4.
- Fever claims can differ by a slight amount, so exact outside facts matter.
| Type | What it means | ReAct | CoT |
|---|
| True positive | Right reasoning and facts | 94% | 86% |
| False positive | Made-up reasoning or facts | 6% | 14% |
| Reasoning error | Wrong reasoning, or stuck in a loop | 47% | 16% |
| Search result error | Search empty or not useful | 23% | - |
| Hallucination | Made-up reasoning or facts | 0% | 56% |
| Label ambiguity | Right but did not match the label | 29% | 28% |
Table 2: success and failure on HotpotQA (50 samples each)
They labeled 200 examples: 50 right and 50 wrong each for ReAct and CoT.
CoT fails by making things up; ReAct fails by bad reasoningFrom Table 2ReActCoT
Hover, tap or focus a bar to read its exact value.
| Type | ReAct (%) | CoT (%) |
|---|
| True positive | 94 | 86 |
| False positive | 6 | 14 |
| Reasoning error | 47 | 16 |
| Hallucination | 0 | 56 |
| Label ambiguity | 29 | 28 |
Key observations
- A) Hallucination hurts CoT: 14% false positives against 6%, and 56% of its failures.
- ReAct is more grounded and fact-driven.
- B) The ReAct format is less flexible, so reasoning errors rise.
- A common one is repeating earlier thoughts and actions in a loop.
- C) Useless search causes 23% of ReAct errors, and recovery is hard.
Outdated labels
- Some HotpotQA answer labels are outdated.
- Figure 4 is one example.
ReAct plus CoT-SC
- The best prompts: ReAct then CoT-SC on HotpotQA, CoT-SC then ReAct on Fever.
- Both beat CoT-SC at every sample count (Figure 2).
- They reach CoT-SC at 21 samples using only 3-5 samples.
Finetuning (Figure 3)
- With PaLM-8B and 62B prompts, ReAct is worst of four.
- It is hard to learn both skills from examples.
- After finetuning on 3,000 examples, ReAct is best.
- Finetuned PaLM-8B ReAct beats all PaLM-62B prompting methods.
- Finetuned PaLM-62B ReAct beats all 540B prompting methods.
Why finetuned ReAct wins
- Finetuning Standard or CoT teaches the model to memorize facts that may be false.
- Finetuning ReAct or Act teaches it how to find facts.
- That skill transfers better.
The two tasks
- ALFWorld and WebShop need long runs of actions and sparse rewards.
- That is why reasoning to guide acting matters.
ALFWorld: setup
The game
- A text game with 6 task types, such as "examine paper under desklamp".
- Actions look like "go to coffeetable 1" or "take paper 2".
- A task can have more than 50 locations and need more than 50 steps.
- The agent must guess likely places, such as desklamps on desks.
The prompts and baseline
- They write 3 trajectories per task type with sparse thoughts.
- Thoughts split the goal, track subgoals, pick the next subgoal, and use commonsense.
- They test on 134 unseen games.
- They build 6 prompts per task type from pairs of 2 of the 3 trajectories.
- Act uses the same trajectories without thoughts.
- The baseline BUTLER is an imitation agent trained on 10^5 expert trajectories per task type.
WebShop: setup
The task
- An online store with 1.18M products and 12k human instructions.
- The agent must buy a product that fits an instruction.
- Example: a nightstand with drawers priced lower than $140.
- Scoring is average score and success rate on 500 test instructions.
- Act actions: search, choose product, choose options, buy.
- ReAct adds thoughts on what to explore, when to buy and which options matter.
Baselines
- Imitation learning (IL) used 1,012 human annotated trajectories.
- IL plus reinforcement learning (IL + RL) also used 10,587 training instructions.
| Method | Pick | Clean | Heat |
|---|
| Act (best of 6) | 88 | 42 | 74 |
| ReAct (avg) | 65 | 39 | 83 |
| ReAct (best of 6) | 92 | 58 | 96 |
| ReAct-IM (avg) | 55 | 59 | 60 |
| ReAct-IM (best of 6) | 62 | 68 | 87 |
| BUTLERg (best of 8) | 33 | 26 | 70 |
| BUTLER (best of 8) | 46 | 39 | 74 |
Table 3 (part 1): ALFWorld success rates (%)
| Method | Cool | Look | Pick 2 |
|---|
| Act (best of 6) | 67 | 72 | 41 |
| ReAct (avg) | 76 | 55 | 24 |
| ReAct (best of 6) | 86 | 78 | 41 |
| ReAct-IM (avg) | 55 | 23 | 24 |
| ReAct-IM (best of 6) | 57 | 39 | 33 |
| BUTLERg (best of 8) | 76 | 17 | 12 |
| BUTLER (best of 8) | 100 | 22 | 24 |
Table 3 (part 2): ALFWorld success rates (%)
BUTLER and BUTLERg are from Shridhar et al. All use greedy decoding except BUTLER, which uses beam search.
ReAct beats acting only and imitation learning on ALFWorldFrom Table 3Hover, tap or focus a bar to read its exact value.
| Method | Success (%) |
|---|
| BUTLERg (best of 8) | 22 |
| BUTLER (best of 8) | 37 |
| Act (best of 6) | 45 |
| ReAct-IM (best of 6) | 53 |
| ReAct (avg) | 57 |
| ReAct (best of 6) | 71 |
ALFWorld results
- The best ReAct trial scores 71%. The best Act scores 45%. BUTLER scores 37%.
- Even the worst ReAct trial (48%) beats the best trial of both.
- ReAct beats Act in all 6 controlled trials, by 33% to 90%, 62% on average.
- Without thoughts, Act fails to split goals or loses track of the state.
| Method | Score | Success rate (%) |
|---|
| Act | 62.3 | 30.1 |
| ReAct | 66.6 | 40.0 |
| IL | 59.9 | 29.1 |
| IL + RL | 62.4 | 28.7 |
| Human expert | 82.1 | 59.6 |
Table 4: WebShop
WebShop results
- One-shot Act already matches IL and IL + RL.
- ReAct adds an absolute 10% over the best before.
- Thoughts help bridge noisy page text and the right choice.
- Expert humans still do much better. They explore more and rewrite queries.
Reasoning versus feedback
- The closest earlier work is Inner Monologue (IM).
- Its "monologue" is only feedback about the environment and the goal.
- ReAct thoughts are flexible and sparse, with many types.
- They tested IM-style dense feedback (ReAct-IM).
ReAct versus IM
- ReAct beats ReAct-IM overall: 71 versus 53.
- It wins on five of six task types.
- ReAct-IM often misjudged when subgoals were done.
- It lacked goal splitting and commonsense on where items sit.
Conclusion
- ReAct is simple and works across question answering, fact checking and interactive tasks.
- It gives readable decision traces.
- Hard tasks with many actions need more examples than the input length allows.
- Finetuning on HotpotQA looks promising.
- Next: multi-task training and reinforcement learning.
Reproducibility
- Main tests use PaLM, which is not open.
- All prompts are in Appendix C. GPT-3 results are in Appendix A.1.
Ethics
- Hooking a model to outside actions has risks.
- Examples: reading private information, or taking harmful actions.
- The tests used only Wikipedia and WebShop, with no private data or dangerous actions.
- Models cannot really buy products or edit Wikipedia.
| Task | PaLM-540B | GPT-3 |
|---|
| HotpotQA (exact match) | 29.4 | 30.8 |
| ALFWorld (success rate %) | 70.9 | 78.4 |
Table 5: PaLM-540B versus GPT-3 with ReAct
GPT-3 is text-davinci-002. HotpotQA uses 500 validation questions. ALFWorld uses 134 tasks.
A.1 GPT-3
- GPT-3 does better than PaLM-540B on both.
- It may be because GPT-3 is finetuned to follow instructions.
- So ReAct works across models.
A.2 Up-to-date knowledge
- Some HotpotQA labels are outdated, such as a hotel's room count.
- Standard and CoT hallucinate. Act fails without reasoning.
- Only ReAct gets the new answer.
A.3 Human in the loop
- A human can edit two thoughts (Act 17 and Act 23) in a failed run.
- ReAct then changes behavior and succeeds.
- This is far easier than typing tens of actions.
- Act and reinforcement learning methods cannot be fixed this way.
B.1 HotpotQA finetuning
- Batch size is 64.
- PaLM-8B: ReAct and Act train 4 thousand steps.
- PaLM-8B: Standard and CoT train 2 thousand steps.
- PaLM-62B: ReAct and Act train 4 thousand steps.
- PaLM-62B: Standard and CoT train 1 thousand steps.
- ReAct and Act gain from more steps. Standard and CoT degrade soon.
B.2 ALFWorld IM-style
- IM-style traces use dense feedback thoughts.
- They only decompose the goal and the current subgoal.
- They lack thoughts on when a subgoal is done and what is next.
- They also lack thoughts on where items are.
What is there
- C.1 HotpotQA prompts, C.2 Fever prompts.
- C.3 WebShop prompts, C.4 ALFWorld prompts.
- They hold the full few-shot examples for Standard, CoT, Act, ReAct and ReAct-IM.
Examples
- D.1 Fever trajectories. D.2 ALFWorld ReAct, Act and ReAct-IM trajectories.
- D.3 WebShop trajectories.
Examples
- E.1 shows examples for each success and failure mode in Table 2.
- Search results and non-representative steps are cut to save space.
- This write-up covers the main paper in full and each appendix at summary level.
Words to know
- Agent: A model that picks actions and sees the results.
- API: A way for a program to call a service.
- Chain of thought: Reasoning steps written in plain words before the answer.
- Exact match: A score that counts an answer only if it equals the label.
- Hallucination: When a model states made-up facts as if they were true.
- Imitation learning: Training a model to copy expert examples.
- Reinforcement learning: Training a model by reward for good results.
- Self-consistency: Sample many answers and take the most common one.
- Trajectory: The full list of thoughts, actions and observations in one run.
Ask AI about this paper
Stuck on a word or an idea? Ask in plain words. The answer comes from the write-up on this page.
Jump to