tezvyn:

ReAct: Teaching LLMs to Think, Then Act

AI-drafted, machine-checkedSource: arXivadvanced

ReAct teaches LLMs to 'think then do,' interleaving reasoning steps with actions like querying a database. Instead of just generating a final answer, the model forms a thought, acts on it, observes the result, and then thinks again. This is crucial for complex question-answering where the model must gather external information to ground its reasoning. The main footgun it avoids is hallucination, where models invent facts instead of looking them up.

### The mental model

ReAct gives a language model a simple, powerful loop for solving problems: **think, act, observe**. Instead of trying to reason its way to a final answer in one shot, the model first thinks about what it needs to do, performs an action to gather information, and observes the result to inform its next thought. This mimics how humans solve complex problems: we form a hypothesis, test it in the real world, and update our understanding based on the outcome.

### How it works

ReAct works by prompting an LLM to generate a sequence of thoughts, actions, and observations in an interleaved manner. The model's output isn't the final answer, but a step-by-step trajectory. For example:

1. **Thought:** The model generates a private reasoning step, like "I need to find out the population of the city the Eiffel Tower is in." 2. **Action:** The model generates a command to execute, like `search("city with Eiffel Tower")`. 3. **Observation:** An external tool (like a search API) executes the action and feeds the result back to the model, e.g., "Paris".

This cycle repeats, with the new observation feeding into the next thought, until the model has enough information to generate a final answer.

### When to use it

* **Complex Question Answering:** For questions that require synthesizing facts from multiple sources (e.g., HotpotQA). * **Fact Verification:** When a model must check claims against a trusted knowledge base like Wikipedia to avoid hallucination. * **Interactive Agents:** For agents that need to navigate environments like websites or game worlds to complete a task (e.g., WebShop, ALFWorld).

### When NOT to use it

* **Simple, Self-Contained Tasks:** If the answer is likely within the model's pretrained knowledge and requires no external verification, the overhead of actions is unnecessary. * **Latency-Critical Applications:** Each action step involves an external API call, which adds significant delay compared to a single inference pass.

### One canonical example

To answer "What is the elevation of the capital of the country where the 2022 FIFA World Cup was held?", a ReAct agent would:

1. **Thought:** I need to find the host country of the 2022 World Cup. 2. **Action:** `search("2022 FIFA World Cup host")` 3. **Observation:** Qatar 4. **Thought:** Now I need the capital of Qatar. 5. **Action:** `search("capital of Qatar")` 6. **Observation:** Doha 7. **Thought:** Now I need the elevation of Doha. 8. **Action:** `search("elevation of Doha")` 9. **Observation:** 10 meters 10. **Thought:** I have all the information. The final answer is 10 meters.

Read the original → arxiv.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.