ReAct Prompting
What it is about:
ReAct is a framework designed to improve the capabilities of large language models (LLMs) by combining reasoning and acting. LLMs are powerful tools for generating text, translating languages, and writing different kinds of creative content. However, they can struggle with tasks that require accessing and reasoning about information from the real world. ReAct addresses this limitation by allowing LLMs to interact with external sources like search engines and knowledge bases during the reasoning process.
How it works:
ReAct uses a three-step approach:
- Thought: The LLM generates a thought that describes a step in the reasoning process. This could involve breaking down a complex question, extracting information, or formulating a search query.
- Action: Based on the thought, the LLM takes an action. This might involve searching for information online, using a calculator tool, or looking up definitions.
- Observation: The LLM receives an observation from the external source it interacted with in the action step. This could be the retrieved search results, the answer from the calculator, or the definition of a word.
The LLM iterates through these steps, using the observations from each action to inform the next thought and action. This allows the LLM to dynamically reason about the task at hand and gather the information it needs to arrive at a solution.
Examples:
Question Answering:
Imagine you ask an LLM using ReAct: "What is the capital of France and what is its population?"
- Thought 1: I need to find the capital of France.
- Action 1: Search "capital of France".
- Observation 1: Paris is the capital of France.
- Thought 2: Now I need to find the population of Paris.
- Action 2: Search "population of Paris".
- Observation 2: The population of Paris is estimated to be around 2.1 million.
- Final Answer: Paris is the capital of France and its population is estimated to be around 2.1 million.
Fact Verification:
ReAct can be used to verify the accuracy of factual claims. For instance, if you ask: "Is the moon made of cheese?"
- Thought 1: I need to find information about the composition of the moon.
- Action 1: Search "composition of the moon".
- Observation 1: The moon is primarily composed of rock and dust.
- Final Answer: The claim that the moon is made of cheese is not supported by evidence.
Decision Making:
ReAct can also be applied to decision-making tasks. Let's say you're planning a trip and want to find a hotel that meets your criteria.
- Thought 1: I need to find hotels in [destination city].
- Action 1: Search "hotels in [destination city]".
- Observation 1: List of hotels with prices and amenities.
- Thought 2: I need to filter the hotels based on my budget (e.g., under $100 per night).
- Action 2: Filter search results based on price.
- (This process continues with the LLM reasoning about additional criteria like location, amenities, and reviews)
- Final Answer: Here are some hotel options that fit your budget and preferences.
When to use it:
ReAct is a valuable framework for tasks that require LLMs to go beyond simply processing and generating text. It's particularly beneficial for:
- Question Answering: When the answer requires information from external sources.
- Fact Verification: To assess the accuracy of claims.
- Decision Making: For tasks involving reasoning about multiple factors and criteria.
- Information Retrieval: When the LLM needs to gather specific data points.
By combining reasoning and acting, ReAct allows LLMs to become more versatile and effective tools for interacting with the real world.