How ReAct Agents Work
ReAct agents combine reasoning and action to enable large language models to use external tools, preventing hallucinations and providing up-to-date information.
In depth
Large language models (LLMs) are powerful text predictors, but their knowledge is limited to their training data. ReAct agents extend LLMs by enabling them to interact with external tools, allowing them to access real-time information and perform calculations.
The Problem with Static Knowledge
Standard LLMs cannot answer questions requiring current information, such as today's weather or live stock prices, because their knowledge is fixed at the time of their last training update. To overcome this, LLMs can be equipped with tools like web search APIs or calculators. The challenge then becomes how the LLM intelligently decides when to use these tools, what inputs to provide, and how to interpret the results.
Introducing ReAct: Reason and Act
ReAct, short for "Reason and Act," addresses this by prompting the LLM to follow a continuous loop of Thought, Action, and Observation. This structured approach forces the model to plan its steps and verify information, significantly improving accuracy and reducing hallucinations.
The Thought-Action-Observation Loop
1. Thought: Before taking any action, the model generates a "Thought." This is a crucial Chain of Thought step where the LLM articulates its reasoning, breaking down the problem and outlining its next move. For example, to find the age of the French president, the initial thought might be: "I need to find the current president, then find their age."
2. Action: Based on its thought, the model outputs a structured "Action" command. This command specifies the tool to use (e.g., `search`) and the query (e.g., `current president of France`).
3. Observation: An external orchestrator intercepts the Action, executes the specified tool, and then feeds the result back to the LLM as an "Observation." For the previous example, the observation might be: "Emmanuel Macron."
This loop repeats. With the new observation, the model generates another thought (e.g., "I now need to find Emmanuel Macron's birth year"), triggers another action (e.g., `search: Emmanuel Macron birth year`), and receives a new observation (e.g., "Born December 1977"). Finally, it can perform a calculation and provide a factual answer.
Orchestration in Practice
An external orchestrator is essential for ReAct agents. It wraps the LLM, continuously parsing its text output. When it detects a specific stop sequence (e.g., `Action:`), it pauses the LLM, executes the tool, appends the result as an `Observation:`, and then resumes the LLM's generation. This seamless integration allows the LLM to interact dynamically with the real world.
Loop:
Generate Thought
Generate Action(tool, input)
Execute tool with input
Receive Observation from tool
If final answer, breakKey Takeaways
- ReAct agents enable LLMs to use external tools for up-to-date and factual information.
- They operate on a continuous Thought-Action-Observation loop.
- The "Thought" step is a Chain of Thought, improving reasoning and planning.
- An external orchestrator manages tool execution and feeds observations back to the LLM.
- This approach significantly reduces hallucinations and enhances problem-solving capabilities.
Got a different question? SeaThru generates a fresh video for any topic where systems talk or data structures move.
Ask your own question →