ReAct Prompt Framework: Enhancing AI’s Decision Making with Human-Like Reasoning

You may not be familiar with ReAct, a cutting-edge framework designed to enhance the decision-making capabilities of language models (LLMs).

By updating the LLM’s context window with new observations and prompting it to reassess the information, ReAct facilitates a level of reasoning akin to human thought processes, surpassing older techniques such as Chain-of-Thought prompting.

In this article, we qualitatively evaluate ReAct and put it to the test using Langchain' s agent module to initialize a zero-shot agent to tackle information retrieval problems.

What is ReAct?

ReAct in action (Source: Yao et al.)

The ReAct pattern, short for “Reasoning and Acting,” is a framework that separates the reasoning process from the action-taking process in AI models.

At its core, the ReAct pattern works by feeding observations to the LLM, allowing it to update its context window. The model re-evaluates the information and acts on these insights to improve its reasoning capabilities. This process stands in contrast to techniques like Chain-of-Thought (CoT) prompting, where the reasoning steps are embedded within a single prompt.

The ReAct framework improves the quality and coherence of LLM responses by providing a structured approach to handle complex queries. Instead of processing a query in one go, the LLM can independently analyse the information and generate a response that accurately reflects the information provided. This approach leads to more informed and precise outputs.

Its a multi-agent approach at its core which obviously involves chaining AI responses together.

AI Response Chaining

A key feature of ReAct and similar techniques is the chaining of AI responses instead relying on a single AI response.

AI response chaining enhances AI reasoning by artificially placing different thinking steps within prompts. For example, the initial AI response for a data analysis task might only perform one action which would be to extract the key insights from a report or chart, the next AI response might take those insights and perform a different action like search to find relevant articles to support the insights. The final response would be an aggregation of all these actions.

All tasks can be broken down and delegated to different AI’s essentially.

Why not just stuff everything in one prompt? Well despite the increasingly large context windows, the attention mechanism in an LLM has not improved to the same degree and information gets lost frequently as you increase your context window utilisation. This is not always the case and there is a lot of research being done to find ways to negate the large context window problem.

Even without this issue, LLMs still perform better when given one task at time at least at the moment.

Perplexity AI is a notable implementation, aggregating search results based on alternative queries to maximize relevance and breadth, thus simulating a comprehensive human-like search process and integrating diverse inputs meaningfully. We covered a similar topic in our last article about Google’s AI search engine failures and comparing their measly implementation to Perplexity AI.

An Example?

Importing Libraries and API Key Setup

!pip install --upgrade openai
pip install --upgrade langchain
pip install --upgrade python-dotenv
pip install google-search-results
 
# import libraries
import openai
import os
from langchain.llms import OpenAI
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from dotenv import load_dotenv
load_dotenv()
 
# load API keys; you will need to obtain these if you haven't yet
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
os.environ["SERPER_API_KEY"] = os.getenv("SERPER_API_KEY")

Configuring the AI and LLM

This example uses zero-shot prompting (no examples) when implementing the ReAct framework. This means that observations and thoughts are instruction based only with little-to no reasoning or relevant examples given to guide the AI.

You can configure you’re own model that employs few-shot with a few examples to encourage the AI to think in a slightly more tailored way to your task.

llm = OpenAI(model_name="text-davinci-003" ,temperature=0)
tools = load_tools(["google-serper", "llm-math"], llm=llm)
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)

Running the Chain

Upon execution, you’ll notice how the agent dynamically searches and gathers information to provide a coherent and detailed response.

agent.run("What is Asycd and what do they do in the space of AI?")

Entering new AgentExecutor chain...

Thought: I need to find out what Asycd is and what they do in the space of AI.

Action: Search

Action Input: "What is Asycd and what do they do in AI?"

Observation: Asycd is a company focused on using AI to revolutionize art creation and user interaction.
They leverage AI technologies to provide innovative tools that enhance the creative process
and offer personalized user experiences.

Thought: I need more details about Asycd's specific activities and platforms related to AI.

Action: Search

Action Input: "Asycd AI innovations and platforms"

Observation: Asycd offers several AI-driven solutions including:

An AI-based platform for generating unique art pieces.
Tools for artists to collaborate with AI to expand their creative boundaries.
User-centric AI applications that personalize and enhance user interactions with art and other creative content.
Thought: I now have a comprehensive understanding of Asycd's role in the AI space."

Final Answer: Asycd is a company dedicated to transforming art creation through artificial intelligence. They offer a variety of AI-driven solutions such as an AI-based platform for generating unique artwork, collaborative tools for artists to push creative limits with AI, and user-centric applications that tailor and enrich user interactions with creative content.

> Finished chain.

You can see, step-by-step, the flow actions taken by AI to first of all search the query presented by the user on Google to see if it can find an answer by directly searching Google.

The agent evaluates the search results and has another thought which would likely be along the lines of “These results do not answer the users query but it is a useful starting point”. It would maybe pick up keywords from the search result and use those keywords in its next search which would be its next action.

Eventually, the AI finds the correct information regarding Asycd’s AI activities and uses that to formulate its final response to the initial query.

Alternatives

There are several alternative prompting frameworks that aim to align human and AI decision-making, similar to ReAct:

1.Chain-of-Thought (CoT) prompting: This framework encourages LLMs to generate step-by-step reasoning traces or “chains of thought” to arrive at a final answer. It helps make the model’s reasoning process more transparent and interpretable, aligning it with human-like reasoning.

2. Self-Consistency prompting: This approach prompts LLMs to generate multiple possible solutions and then cross-check them for consistency, mimicking how humans double-check their work. It can improve the reliability and coherence of LLM outputs.

3. Recursive Reward Modeling (RRM): RRM trains LLMs to recursively model the reward function of a task, allowing the model to reason about the task’s objectives and constraints in a more human-aligned manner.

4. Debate: This framework prompts LLMs to generate multiple perspectives or arguments on a given topic, similar to a human debate. It can help surface different viewpoints and considerations, promoting more well-rounded decision-making.

5. Iterated Amplification (IA): IA involves iteratively refining an LLM’s outputs by having it critique and improve its own responses, akin to how humans refine their thinking through self-reflection and iteration.

6. Cooperative AI: This approach involves prompting multiple LLMs to collaborate and share knowledge, mimicking how humans often work together to solve complex problems.

All these techniques are agentic in nature and would differ only in prompt configuration as well as the structure of AI responses.


Researching ReAct has been incredibly valuable, enabling us to explore various innovative approaches to enhancing the effectiveness of our chatbots and AI tools. We hope you found the insights shared here both informative and inspiring as well!

For further exploration of our ongoing research, check out the TEV1 page to find out how you can access a state of the art image generation model for all your content creation need. Utilizing prompt engineering techniques like the ReAct framework, we unlocked the next frontier of digital art.

Previous
Previous

The Problem with AI Image Generation + How We Made it Better with TEV1

Next
Next

Where is Google’s AI Search Engine? How Will it Compare to Perplexity AI?