☼
⌃
☰

ReAct Prompting & Context-Awareness

Table of Contents

ReAct Prompting & Context-Awareness

Description

ReAct is a prompt engineering framework designed to enable LLMs to solve complex, dynamic, and factual problems by integrating reasoning (to decide what to do) and acting (to execute a step or retrieve information)

Core Mechanism (Reasoning and Acting)

The ReAct loop explicitly guides the LLM to alternate between three steps until a goal is achieved:

  1. Thought (Reasoning): The LLM uses its internal knowledge and the context of the current goal to formulate a logical plan, assess the situation, and decide the next best step. This is essentially a Chain-of-thought step.
  2. Action (Acting): The LLM then selects and executes a specific external tool or function (e.g., a search engine, a calculator, a code interpreter, or a database query).
  3. Observation: The LLM receives the output (the result) from the executed tool, which provides new, up-to-date, or factual information.

The model uses the Observation to refine its next Thought, ensuring its reasoning is based on real-time and external data, rather than just its potentially outdated training data.

Context-Awareness and Purpose

ReAct significantly enhances the context-awareness of an LLM by:

  • Factual Grounding: It allows the LLM to retrieve and incorporate current, factual information from external APIs (like Google Search), overcoming the limitations of static knowledge encoded during training.
  • Planning and Error Correction: The explicit Thought step makes the LLM better at planning multi-step solutions and provides a mechanism for self-correction when an Action yields an unexpected Observation.
  • Tool Usage: It formalizes the process by which an LLM can use external tools, effectively making the model an agent capable of interacting with the real world.

Examples

Scenario: Factual Query Requiring a Search Tool

The goal is to find the current age of a famous person. Since the person's current age changes daily, the LLM needs a search tool to get the current date and birth date.

Step Type Prompt/Response Description
User Prompt What is Emma Stone's current age? The initial task.
Thought I need to find Emma Stone's birth date and the current date to calculate her age. I will use a search tool. The LLM reasons about the required information.
Action Search(Emma Stone birth date) The LLM calls the external search tool.
Observation Emma Stone was born on November 6, 1988. The factual result from the search engine.
Thought Her birth date is November 6, 1988. I will use the calculator tool to find the number of years between that date and today (December 8, 2025). The LLM plans the next step using the new observation.
Action Calculator(YearsBetween("Nov 6, 1988", "Dec 8, 2025")) The LLM executes the calculation.
Observation 37.08 years The calculated result.
Thought The calculation shows her age is 37.08, so she is currently 37 years old. I will state the final answer. The LLM forms the final conclusion.
Final Answer Emma Stone is currently 37 years old (born November 6, 1988). The final, grounded answer.

Scenario: Coding and ebugging

A task requiring code execution and error handling.

Step Type Prompt/Response Description
User Prompt What is the output of (5 + 3) * 2? The initial task.
Thought This is a simple calculation. I will use the Code Interpreter tool to ensure accuracy. The LLM decides on the appropriate tool.
Action Code_Interpreter(print((5 + 3) * 2)) The LLM executes the code.
Observation 16 The output from the code execution tool.
Final Answer The output of the expression (5 + 3) * 2 is 16. The LLM provides the final answer based on the observation.