Hand-drawn doodle titled "Reasoning and Action" with icons, charts, and arrows linking them on a dark background

Introduction

In the rapidly evolving landscape of artificial intelligence, agentic workflows have emerged as a pivotal concept, enhancing the capabilities of large language models (LLMs) like ChatGPT. Among the various design patterns that facilitate these workflows, ReAct stands out as a powerful strategy that integrates reasoning and action to produce more thorough and accurate responses. I write about agentic workflows in my other posts, check them out!

Background on Agentic Workflows

What Are Agentic Workflows?

Agentic workflows refer to processes where AI models act with a degree of autonomy, making decisions and taking actions based on their reasoning. Unlike traditional software workflows that follow a fixed sequence of operations, agentic workflows allow models to dynamically interact with their environment, enabling more sophisticated problem-solving and decision-making.

The Role of Reasoning and Action in AI

Integrating reasoning into AI models allows them to break down complex problems into manageable steps, ensuring that each part of the solution is justified and logical. Action, on the other hand, enables AI to interact with external systems, execute functions, and retrieve information, thereby expanding their functional capabilities beyond mere text generation.

Understanding the ReAct Design Pattern

ReAct: Reasoning and Action Combined

The ReAct design pattern is a prompting strategy that encourages LLMs to engage in both Reasoning and Action.

  • Reasoning involves the model breaking down a problem into smaller steps, justifying each step before arriving at a final answer.
  • Action allows the model to call functions or generate structured outputs, then use the results of these actions to inform further reasoning.

Reasoning in ReAct

By prompting the model to reason, ReAct ensures that responses are methodical and well-justified. This involves:

  • Step-by-Step Problem-Solving: The model decomposes complex queries into sequential steps.
  • Justification: Each step is explained, providing transparency and enhancing the reliability of the final output.
# Example of a ReAct prompt for reasoning
prompt = """
You are asked to solve a math problem. Break down the problem into steps and explain each step before providing the final answer.

Problem: Calculate the area of a triangle with base 5 units and height 10 units.
Reasoning:
1. The formula for the area of a triangle is (base * height) / 2.
2. Substitute the given values into the formula.
3. Calculate the area.
"""

Action in ReAct

Action involves the model making decisions to execute specific functions or generate structured data that can aid in solving the problem. This creates an iterative loop where reasoning leads to action, and the results of actions inform further reasoning.

# Example of a ReAct prompt with action
prompt = """
You are solving a data retrieval task. Break down the task and decide which functions to call.
Task: Fetch the latest weather data for New York City.
Reasoning:
1. Identify the necessary data source for weather information.
2. Use the weather API function to retrieve current data.
Action:
CALL fetch_weather_data(location="New York City")
"""

Advantages and Challenges of ReAct

Benefits of the ReAct Design Pattern

  • Enhanced Thoroughness: By iterating between reasoning and action, responses are more comprehensive and accurate.
  • Improved Problem-Solving: The structured approach allows models to tackle complex issues more effectively.
  • Transparency: Detailed reasoning provides clarity on how conclusions are reached.

Challenges Associated with ReAct

  • High Token Consumption: The iterative back-and-forth between reasoning and action requires a significant number of tokens, which can be resource-intensive and can lead to increased costs.
  • Complexity Management: Coordinating multiple interactions between reasoning and action phases can complicate the workflow and require sophisticated handling.

ReAct as the Foundation for OpenAI’s Advanced Models

Scaling ReAct with OpenAI’s Infrastructure

OpenAI has harnessed the ReAct pattern by training models on millions, even billions, of problem-solving examples. This extensive training enables models like ChatGPT to excel in both reasoning and actioning, making them highly effective at function calling and executing complex tasks. This is precisely how the ChatGPT o1 models were trained.

Chain of Thought vs. ReAct

While both Chain of Thought and ReAct involve reasoning, ReAct explicitly incorporates actions, allowing models to interact with external functions and systems. This combination enhances the model’s ability to not only think through problems but also take actionable steps to solve them.

Function Calling Excellence

OpenAI’s models are adept at function calling due to their training on vast datasets that include numerous examples of function interactions. This proficiency ensures that when a model needs to execute a function, it can do so accurately and efficiently, seamlessly integrating the results into its reasoning process.

The Strawberry Model and Training Insights

Introducing the Strawberry Model

The Strawberry Model serves as a foundational component in generating prompts that teach the main LLM (later named o1) how to effectively utilize reasoning and action. By producing prompts in specific formats, the Strawberry Model facilitates the training process, ensuring that the LLM can replicate these patterns during real-world interactions.

Teaching Through Structured Prompts

Structured prompts are crucial for instilling the desired reasoning and action behaviors in the model. Examples include:

  • Reasoning Prompts: Break down problems into logical steps.
  • Action Prompts: Define clear function calls and expected outputs.
# Example of a structured reasoning and action prompt
prompt = """
You are tasked with retrieving the current stock price of Apple Inc. 
Reasoning:
1. Identify the function required to fetch stock prices.
2. Call the function with the appropriate parameters.
Action:
CALL get_stock_price(ticker="AAPL")
"""

ReAct in Practice: Perplexity’s Implementation

Perplexity’s Approach to ReAct

Perplexity adapts the ReAct pattern by integrating reasoning and action into its workflows. This involves:

  • Dynamic Data Retrieval: Actively fetching relevant information from the internet to inform responses.
  • Enhanced Token Utilization: Efficiently managing tokens to maintain thoroughness without excessive resource consumption.

Feeding More Tokens for Enhanced Responses

To achieve detailed and accurate responses, Perplexity increases token usage by:

  • Iterative Interactions: Engaging in multiple rounds of reasoning and action to build comprehensive answers.
  • Balancing Efficiency: Ensuring that the token consumption remains manageable while maintaining response quality.
# Example of Perplexity's token management in ReAct
prompt = """
You need to provide a detailed explanation of the ReAct design pattern. Reasoning:
1. Define ReAct and its components.
2. Explain how reasoning and action work together.
3. Illustrate with examples.
Action:
CALL fetch_additional_information(topic="ReAct design pattern")
"""

The Significance of ReAct in Modern AI

The ReAct design pattern plays a crucial role in advancing the capabilities of large language models. By seamlessly integrating reasoning and action, ReAct enhances the thoroughness, accuracy, and functionality of AI responses, making it a cornerstone of modern agentic workflows.

Looking Ahead

As AI technology continues to evolve, the principles underlying ReAct will likely inspire new design patterns and methodologies. The ongoing refinement of reasoning and action strategies promises to further enhance AI-driven problem-solving and autonomous decision-making, shaping the future of intelligent systems.