How does ReAct prompting work?
ReAct (Reason and Act) prompting is a prompting technique or paradigm used to enhance the problem-solving capabilities of Large Language Models (LLMs). It is categorized as a text-based technique.
Here's how ReAct prompting works:
- Combining Reasoning and Acting: The core idea behind ReAct is to interleave reasoning steps with actionable steps in a dynamic thought-action loop. It mimics how humans operate in the real world, where we reason verbally and can take actions to gain information or progress towards a solution.
- The Thought-Action Loop: The process typically follows these steps:
- The LLM first reasons about the problem and generates a plan of action.
- It then performs the actions specified in the plan. These actions can involve using external tools such as search engines, code interpreters, or interacting with external APIs to retrieve information. This represents a first step towards agent modeling.
- The LLM observes the results of these actions.
- It then uses these observations to update its reasoning and generate a new plan of action.
- This process continues iteratively until the LLM reaches a solution to the problem.
- Memory and Context: The history of thoughts, actions, and observations from previous steps is inserted into the prompt. This gives the LLM a memory of the process it has followed, allowing it to learn from past steps and refine its approach. Implementing this in practice requires continually resending previous prompts/responses, often with trimming of extra generated content.
- Performance: ReAct performs well against other prompt engineering approaches in a variety of domains. For example, in one case shown in the sources, a ReAct agent made a chain of searches, scraped results, and used observations to chain thoughts for subsequent searches to solve a problem involving calculating the total number of children of band members.
- Implementation: Frameworks like LangChain can be used to create ReAct agents, such as using
AgentType.ZERO_SHOT_REACT_DESCRIPTION
.
In summary, ReAct prompting enables LLMs to tackle complex tasks by allowing them to not only reason internally but also interact with the external world through tools, using a dynamic loop of thought, action, and observation, while maintaining a memory of the interaction history.