jixiaxue 知识库
evidence · 2026-04-15

T3-1-dairai-react

/Users/shanfang/Documents/pe/jixiaxuegong/research/提示工程教程/evidence/T3-basics/T3-1-dairai-react.md

来源:https://www.promptingguide.ai/techniques/react 爬取日期:2026-03-22

ReAct Prompting

Yao et al., 2022 introduced a framework named ReAct where LLMs are used to generate both reasoning traces and task-specific actions in an interleaved manner.

Generating reasoning traces allow the model to induce, track, and update action plans, and even handle exceptions. The action step allows to interface with and gather information from external sources such as knowledge bases or environments.

The ReAct framework can allow LLMs to interact with external tools to retrieve additional information that leads to more reliable and factual responses.

How It Works

ReAct is inspired by the synergies between “acting” and “reasoning” which allow humans to learn new tasks and make decisions or reasoning.

Chain-of-thought (CoT) prompting has shown the capabilities of LLMs to carry out reasoning traces to generate answers to questions involving arithmetic and commonsense reasoning, among other tasks. But its lack of access to the external world or inability to update its knowledge can lead to issues like fact hallucination and error propagation.

ReAct is a general paradigm that combines reasoning and acting with LLMs. ReAct prompts LLMs to generate verbal reasoning traces and actions for a task. This allows the system to perform dynamic reasoning to create, maintain, and adjust plans for acting while also enabling interaction to external environments (e.g., Wikipedia) to incorporate additional information into the reasoning.

ReAct Prompt Example

The first example from the paper shows a combined example of reasoning + acting. The approach follows a pattern of:

Thought → Action → Observation (repeated)

Question: What is the elevation range for the area that the eastern sector
of the Colorado orogeny extends into?

Thought 1: I need to search Colorado orogeny, find the area that the eastern
sector of the Colorado orogeny extends into, then find the elevation range
of the area.

Action 1: Search[Colorado orogeny]

Observation 1: The Colorado orogeny was an episode of mountain building
(an orogeny) in Colorado and surrounding areas.

Thought 2: It does not mention the eastern sector. I need to look up
eastern sector.

Action 2: Lookup[eastern sector]

Observation 2: (Result 1 / 1) The eastern sector extends into the High Plains.

Thought 3: The eastern sector of the Colorado orogeny extends into the
High Plains. I need to search High Plains and find its elevation range.

Action 3: Search[High Plains]

Observation 3: High Plains refers to one of two distinct land regions...

Thought 4: I need to instead search High Plains (United States).

Action 4: Search[High Plains (United States)]

Observation 4: The High Plains are a subregion of the Great Plains. From east
to west, the High Plains rise in elevation from around 1,800 to 7,000 ft
(550 to 2,130 m).

Thought 5: High Plains rise in elevation from around 1,800 to 7,000 ft,
so the answer is 1,800 to 7,000 ft.

Action 5: Finish[1,800 to 7,000 ft]

Performance Results

Knowledge-Intensive Tasks

The paper evaluates ReAct on knowledge-intensive reasoning tasks like question answering (HotPotQA) and fact verification (Fever). PaLM-540B is used as the base model for prompting.

Key findings:

Decision-Making Tasks

The paper also reports results demonstrating ReAct’s performance on decision making tasks. ReAct is evaluated on two benchmarks called ALFWorld (text-based game) and WebShop (online shopping website environment). Both involve complex environments that require reasoning to act and explore effectively.

Key findings:

LangChain Implementation

A practical example of how ReAct works using LangChain:

from langchain.llms import OpenAI
from langchain.agents import load_tools
from langchain.agents import initialize_agent

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)

Example execution:

agent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?")

> Entering new AgentExecutor chain...
I need to find out who Olivia Wilde's boyfriend is and then calculate his age
raised to the 0.23 power.

Action: Search
Action Input: "Olivia Wilde boyfriend"
Observation: Olivia Wilde started dating Harry Styles after ending her
years-long engagement to Jason Sudeikis...

Thought: I need to find out Harry Styles' age.
Action: Search
Action Input: "Harry Styles age"
Observation: 29 years

Thought: I need to calculate 29 raised to the 0.23 power.
Action: Calculator
Action Input: 29^0.23
Observation: Answer: 2.169459462491557

Thought: I now know the final answer.
Final Answer: Harry Styles, Olivia Wilde's boyfriend, is 29 years old and
his age raised to the 0.23 power is 2.169459462491557.

> Finished chain.