I. What Is ReAct?
ReAct is a combination of Reasoning + Acting, an Agent execution paradigm that combines a language model's reasoning process with interaction with external tools.
Traditional large models mainly generate answers based on the input context, usually completing reasoning and answering in a single generation process.
However, complex tasks often require external information, actual operations, and multi-round feedback. For example:
- Query real-time weather.
- Search the web and organize materials.
- Query a database and analyze data.
- Write code, run tests, and fix errors.
- Operate a browser to complete multi-step business processes.
These tasks cannot be reliably completed by relying solely on the model's internal knowledge.
The core idea of ReAct is: the model first reasons based on the current information and decides the next action; after executing the action, it observes the result returned by the external environment, and then continues reasoning based on the new information.
Its basic loop is:
Thought → Action → Observation → Thought
Where:
| Concept | Meaning | Responsibility |
|---|---|---|
| Thought | Reasoning | Analyze the current state and decide the next step |
| Action | Action | Call tools or perform operations |
| Observation | Observation | Obtain results returned by the external environment |
| Final Answer | Final answer | Output the result that meets the goal |
ReAct is not simply about having the model call tools continuously; rather, it establishes a closed loop among reasoning, action, and environmental feedback.
II. The Core Ideas of ReAct
1. Differences Between Traditional LLMs and ReAct
Traditional LLMs usually execute as follows:
- Receive user input.
- Reason based on model parameters and context.
- Generate the final answer.
They mainly rely on existing knowledge and the current context, and cannot automatically obtain external information that has not yet been provided.
ReAct, by contrast, allows the model to actively interact with the external environment during reasoning.
For example, a user asks:
How much did a company's revenue grow in the most recent quarter? Please analyze it based on the latest financial report.
A traditional LLM may answer directly based on its training knowledge, but the data may be outdated.
ReAct can first search for the latest financial report, then extract revenue data, calculate the growth rate, and finally form an analytical conclusion.
Differences between the two approaches:
| Comparison Dimension | Traditional LLM | ReAct |
|---|---|---|
| Information source | Model knowledge and input context | Model knowledge, context, and external environment |
| Execution mode | Direct generation | Alternating reasoning and action |
| Tool calling | Usually no closed-loop mechanism | Can continuously call tools |
| Environmental feedback | Usually not actively obtained | Obtained through Observation |
| Dynamic adjustment | Limited capability | Adjusts based on execution results |
| Applicable scenarios | Q&A, text generation | Search, analysis, operations, and complex tasks |
2. The Core Loop of ReAct
The execution process of ReAct can be summarized as:
flowchart TD
A["Receive user task"] --> B["Thought: Analyze current state"]
B --> C{"Is external action required?"}
C -->|"No"| D["Generate Final Answer"]
C -->|"Yes"| E["Action: Select tool and generate parameters"]
E --> F["Execute tool"]
F --> G["Observation: Obtain execution result"]
G --> H["Update context and task status"]
H --> I["Perform Thought again"]
I --> C
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style C fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style D fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style F fill:#EAF3EC,stroke:#83A995,color:#315D49
style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style H fill:#EAF3EC,stroke:#83A995,color:#315D49
style I fill:#EAE8FA,stroke:#A49BD5,color:#51477D
This loop can continue for multiple rounds until the model considers the goal completed, or the system triggers a timeout, budget limit, or termination condition.
3. Differences Between ReAct and Standard Tool Calling
ReAct and Tool Calling are closely related, but they are not the same concept.
- Tool Calling mainly addresses how the model generates structured tool call requests.
- ReAct mainly addresses how reasoning, action, and environmental feedback are organized in alternating cycles.
Tool Calling can serve as the implementation mechanism for Actions in ReAct.
For example:
Thought: Need to query the latest sales data.
Action: Call the sales database query tool.
Observation: Return the sales records for the last three months.
Thought: Need to calculate the growth rate for each month.
Action: Call the Python calculation tool.
Observation: Return the growth rate statistics.
Thought: The data is sufficient, and conclusions can be generated.
Final Answer: Output the sales analysis.
ReAct does not require that every action call an external tool. The model can also continue reasoning based on the current information, or directly output the final result.
III. The Four Core Components of ReAct
1. Thought: Reasoning
Thought is the process by which the model analyzes the task state based on the current context, identifies problems, and decides on the next action.
It mainly includes:
- Understanding the user's goal.
- Analyzing the information currently known.
- Identifying missing information.
- Determining whether a tool needs to be called.
- Choosing the next action.
- Determining whether the termination condition has been reached.
For example:
User goal:
Query a company's latest quarterly revenue.
Thought:
The current context does not provide the latest quarterly revenue data.
The model's internal knowledge may not be up to date.
It is necessary to obtain the latest financial report through an external search,
and then extract the revenue data.
The role of Thought is to guide action, not to directly execute operations.
It should be noted that production systems should not rely on the model exposing its complete internal chain of thought to implement ReAct. Concise decision summaries, structured action rationales, and state information can be used to drive execution, and internal reasoning content should be avoided being unconditionally shown to users.
2. Action: Taking Action
Action represents the specific operation that the model decides to execute.
Actions can be:
- Calling a search tool.
- Querying a database.
- Executing Python code.
- Reading a file.
- Operating a browser.
- Calling a business API.
- Requesting additional information from the user.
An action typically includes:
| Field | Description |
|---|---|
| action_type | Action type |
| tool_name | Tool name |
| arguments | Call arguments |
| action_id | Action identifier |
| expected_output | Expected output |
| risk_level | Risk level |
For example:
{
"action_type": "tool_call",
"tool_name": "search_web",
"arguments": {
"query": "a company's latest quarterly financial report revenue"
},
"action_id": "action_001"
}
After the model generates an Action, it needs to be parsed and executed by the Agent Runtime.
Arbitrary text generated by the model cannot be directly treated as an executable command.
3. Observation: Observation
Observation is the information returned after tool execution or interaction with the external environment.
For example:
{
"action_id": "action_001",
"status": "success",
"result": {
"title": "Company Quarterly Financial Report",
"revenue": 125000000,
"currency": "CNY",
"period": "2026-Q3"
}
}
Observation is not just the tool's return value; it can also include:
- Whether the execution succeeded.
- Error information.
- Execution time.
- Environment state.
- Data source.
- Whether the task has changed.
Observation is one of the important differences between ReAct and a single tool call.
The model needs to use the actual execution results to update its judgment, rather than assuming that the action will definitely succeed.
4. Final Answer: The Final Answer
When the model determines that the goal has been achieved, or the system decides to terminate the task, the final result needs to be output.
The final answer should satisfy the following:
- Answer the user's original question.
- Use verified information.
- Explain important data sources.
- Do not mistake tool call records for the final conclusion.
- Clearly state information that cannot be confirmed.
- Keep the result complete and understandable.
The final answer is not necessarily just text; it can also be structured data, files, reports, or other execution results.
IV. The Complete Execution Mechanism of ReAct
ReAct is not just the model generating three kinds of text—Thought, Action, and Observation; rather, it requires the Agent Runtime to cooperate in completing the full execution lifecycle.
1. Initialization Phase
After the Agent receives the user's task, it needs to prepare the runtime environment:
- Load system instructions.
- Obtain the conversation context.
- Load available tools.
- Initialize the task state.
- Set the execution budget.
- Configure the maximum number of loops.
The purpose of initialization is to provide clear context and constraints for subsequent reasoning and action.
2. Reasoning Phase
The model decides the next step based on the user's goal, context, and tool definitions.
Three situations may arise:
- The current information is sufficient — answer directly.
- The information is insufficient — a tool call is needed.
- The goal or constraints are unclear — ask the user.
Not every round of reasoning has to produce a tool call.
3. Action Phase
If the model decides to execute a tool, the Runtime must:
- Resolve the tool name.
- Parse the call arguments.
- Validate the argument schema.
- Check invocation permissions.
- Determine the risk level.
- Execute the tool.
- Catch exceptions.
4. Observation Phase
After the tool finishes executing, the Runtime wraps the result as an Observation.
The model must reassess based on the observation:
- Whether the tool succeeded.
- Whether the returned data is valid.
- Whether the current sub-goal is satisfied.
- Whether other tools are still needed.
- Whether previous judgments need to be corrected.
- Whether the task should be terminated.
5. Loop Termination
ReAct must have explicit termination conditions.
Common conditions include:
- The user's goal has been achieved.
- The necessary information has been obtained.
- Tool execution failed unrecoverably.
- The maximum number of loop iterations has been reached.
- The time or cost budget has been exceeded.
- The user cancels the task.
- User authorization is required but was not granted.
6. Complete Run Flow
flowchart TD
A["Initialize Agent Runtime"] --> B["Load context and tools"]
B --> C["Receive user task"]
C --> D["LLM Thought"]
D --> E{"Is action needed?"}
E -->|"No"| F["Check whether it can end"]
F --> G{"Is goal satisfied?"}
G -->|"Yes"| H["Generate Final Answer"]
G -->|"No"| I["Request additional info or re-plan"]
I --> D
E -->|"Yes"| J["Generate Action"]
J --> K["Argument validation and permission check"]
K --> L{"Is execution allowed?"}
L -->|"No"| M["Reject execution or request approval"]
L -->|"Yes"| N["Call tool"]
N --> O["Get Observation"]
O --> P["Update context and state"]
P --> Q{"Budget or iteration count exceeded?"}
Q -->|"Yes"| R["Terminate and explain why"]
Q -->|"No"| D
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style F fill:#EAF3EC,stroke:#83A995,color:#315D49
style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style H fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style I fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style J fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style K fill:#EAF3EC,stroke:#83A995,color:#315D49
style L fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style M fill:#F7EAE7,stroke:#C98D7C,color:#754438
style N fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style O fill:#EAF3EC,stroke:#83A995,color:#315D49
style P fill:#EAF3EC,stroke:#83A995,color:#315D49
style Q fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style R fill:#F7EAE7,stroke:#C98D7C,color:#754438
V. Prompt Design for ReAct
The execution quality of ReAct is closely tied to prompt design.
The prompt must specify the model's role, available tools, decision requirements, output format, and termination conditions.
1. Traditional ReAct Prompt
Classic ReAct research uses formats such as Thought, Action, and Observation to organize the model's reasoning and actions.
Simplified example:
You are an intelligent Agent capable of using external tools.
Please complete the task according to the following rules:
1. Analyze the current task and known information.
2. Determine whether a tool needs to be called.
3. If needed, select an appropriate tool.
4. Generate a call request that meets the tool parameter requirements.
5. Continue reasoning based on the tool's returned result.
6. If the information is sufficient, output the final answer.
7. If the task cannot be completed, explain the specific reason.
Tools:
- search_web(query)
- get_weather(city)
- calculate(expression)
Output structure:
Thought: Current judgment
Action: Tool name
Action Input: Tool parameters
In the traditional ReAct text paradigm, the model can output something like the following:
Thought: Need to obtain the latest information.
Action: search_web
Action Input:
{
"query": "a company's latest quarterly financial report"
}
After the tool executor completes the call, it feeds the result back to the model in the form of an Observation.
2. Modern Structured ReAct
Modern Agent systems usually no longer rely entirely on plain text to parse Thought, Action, and Observation.
A more common approach is:
- The model expresses action decisions through structured output.
- The Tool Calling interface carries the tool name and parameters.
- The Runtime manages calls and execution state.
- Tool results are fed back through a standard message structure.
- A state machine controls the loop and termination.
For example:
{
"decision": "act",
"action": {
"tool": "search_web",
"arguments": {
"query": "某公司最新季度财报"
}
},
"reason_summary": "需要获取最新财报数据"
}
Here, reason_summary is a brief rationale for execution management and does not need to expose the full internal chain of thought.
The structured approach has several advantages:
- It does not rely on fragile text parsing.
- It makes Schema validation easier.
- It makes it easier to record execution state.
- It can be integrated with a tool registry.
- It makes permission and audit control easier to implement.
6. A Practical Example of ReAct in Operation
Take the question raised by the user as an example:
Check today's weather in Beijing, determine whether it is suitable for outdoor running, and give suggestions.
The Agent can use two tools:
get_weather: query the weather.analyze_running_condition: analyze outdoor exercise conditions based on weather indicators.
1. First Reasoning
The model determines that the current context does not contain real-time weather data.
Thought:
Need to obtain today's weather data for Beijing.
There is currently no real-time weather information, so I cannot answer based solely on the model's internal knowledge.
2. First Action
The model generates a tool call:
{
"tool": "get_weather",
"arguments": {
"city": "北京"
}
}
3. First Observation
The tool returns:
{
"city": "北京",
"temperature": 18,
"humidity": 45,
"wind_speed": 2,
"condition": "晴"
}
4. Second Reasoning
The model reasons based on the weather result:
Thought:
Temperature, humidity, wind speed, and weather conditions have been obtained.
These indicators still need to be combined to determine whether outdoor running is suitable.
5. Second Action
Call the analysis tool:
{
"tool": "analyze_running_condition",
"arguments": {
"temperature": 18,
"humidity": 45,
"wind_speed": 2,
"condition": "晴"
}
}
6. Second Observation
{
"suitable": true,
"risk_level": "low",
"suggestions": [
"适当热身",
"根据个人体能控制运动强度",
"注意补水"
]
}
7. Final Answer
The model generates the final answer based on the results of the two tool calls.
The entire process is as follows:
flowchart TD
A["User asks about weather and running advice"] --> B["Thought: missing real-time weather"]
B --> C["Action: query Beijing weather"]
C --> D["Observation: weather data"]
D --> E["Thought: need to assess exercise conditions"]
E --> F["Action: call exercise condition analysis"]
F --> G["Observation: exercise suitability result"]
G --> H["Thought: information is sufficient"]
H --> I["Final Answer: weather and running advice"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAF3EC,stroke:#83A995,color:#315D49
style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style G fill:#EAF3EC,stroke:#83A995,color:#315D49
style H fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style I fill:#DCEFE5,stroke:#4F8B70,color:#24563F
This example demonstrates a typical characteristic of ReAct: the model does not plan all operations at once; instead, it decides the next action based on the current observation.
7. Relationship Between ReAct and Planning
ReAct and Planning are both important execution mechanisms for Agents, but they focus on different aspects.
Planning is mainly responsible for creating execution plans, while ReAct is mainly responsible for alternating between reasoning and action during execution.
1. How Planning Works
Planning usually generates a task plan based on the goal first.
For example:
T1: Query weather
T2: Get air quality
T3: Assess outdoor exercise conditions
T4: Generate exercise recommendations
There can be explicit dependencies between tasks.
After the plan is generated, the scheduler arranges execution according to the dependencies.
2. How ReAct Works
ReAct does not necessarily require a complete task plan to be generated at the outset.
It can first take the most reasonable action at the moment and then decide the next step based on the Observation.
For example, after querying the weather, if the model finds that air quality information is insufficient, it then decides to query air quality further.
3. Comparison of the Two
| Comparison dimension | Planning | ReAct |
|---|---|---|
| Core objective | Create execution plans | Reasoning-action loop |
| Main focus | Task structure and dependencies | Current state and next action |
| Planning method | Usually generate a plan first | Can decide actions step by step |
| Execution method | Schedule according to plan | Continue reasoning based on feedback after actions |
| Use cases | Clear tasks with many steps | Uncertain environment requiring interaction |
| Typical structure | DAG, task tree, state machine | Thought, Action, Observation |
4. Combining Planning and ReAct
In production-grade Agents, the two can usually be used together.
Planning is responsible for generating the initial task structure, while ReAct is responsible for adjusting behavior based on observations when executing each task.
For example:
flowchart TD
A["Complex user task"] --> B["Planner generates task plan"]
B --> C["Task scheduler"]
C --> D["Select current task"]
D --> E["ReAct reasoning"]
E --> F{"Need a tool?"}
F -->|"Yes"| G["Execute Action"]
G --> H["Get Observation"]
H --> I["Update task status"]
I --> E
F -->|"No"| J["Validate current task"]
J --> K{"Is the task complete?"}
K -->|"No"| L["Adjust current task plan"]
L --> E
K -->|"Yes"| M["Schedule next task"]
M --> N{"Is the overall goal complete?"}
N -->|"No"| D
N -->|"Yes"| O["Output final result"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style C fill:#EAF3EC,stroke:#83A995,color:#315D49
style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style H fill:#EAF3EC,stroke:#83A995,color:#315D49
style I fill:#EAF3EC,stroke:#83A995,color:#315D49
style J fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style K fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style L fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style M fill:#EAF3EC,stroke:#83A995,color:#315D49
style N fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style O fill:#DCEFE5,stroke:#4F8B70,color:#24563F
This combination maintains controllability over the overall task while preserving flexibility to adjust during execution.
8. Differences Between ReAct and Other Agent Patterns
ReAct is an execution paradigm for Agents, not the only Agent architecture.
Real systems also include patterns such as Reflection, Plan-and-Execute, Tool-First, and multi-Agent collaboration.
1. ReAct vs. Reflection
Reflection emphasizes checking, evaluating, and improving existing results.
For example:
- Check generated code.
- Evaluate analysis results.
- Identify errors.
- Correct unreasonable conclusions.
ReAct primarily determines what action to take next; Reflection primarily determines whether existing results are correct and whether they need improvement.
The two can be used together:
Thought: decide to execute code
Action: run tests
Observation: tests failed
Reflection: analyze the cause of failure
Thought: decide to modify code
Action: rerun tests
Observation: tests passed
2. ReAct vs. Plan-and-Execute
Plan-and-Execute usually generates a complete plan first, then the executor executes it step by step.
ReAct places more emphasis on observation and re-reasoning after each action.
Plan-and-Execute is suitable for scenarios where the task structure is relatively clear; ReAct is better suited to scenarios that require continuous exploration and dynamic judgment.
3. ReAct vs. Multi-Agent
Multi-Agent systems usually involve multiple Agents collaborating with a division of labor.
For example:
- The Research Agent is responsible for information search.
- The Data Agent is responsible for data analysis.
- The Writing Agent is responsible for report generation.
- The Review Agent is responsible for result review.
Each Agent can internally use ReAct for reasoning and action.
Therefore, ReAct can serve as the execution mechanism of a single Agent and can also become the foundational pattern for each execution unit in a multi-Agent system.
4. Pattern Comparison
| Mode | Core Mechanism | Applicable Scenarios |
|---|---|---|
| ReAct | Reasoning, action, and observation loop | Dynamic tool interaction |
| Reflection | Evaluation and correction | Result optimization |
| Plan-and-Execute | Plan first, then execute | Multi-step tasks |
| Workflow | Predefined process orchestration | Fixed business processes |
| Multi-Agent | Collaboration among multiple Agents | Division of labor in complex domains |
9. Core Advantages of ReAct
1. Ability to Obtain External Information
The model can obtain up-to-date data through tools instead of relying entirely on knowledge formed during the training phase.
Suitable for real-time search, database queries, and external API access.
2. Ability to Adjust Dynamically Based on Feedback
Tool results may differ from expectations.
ReAct can correct subsequent actions based on the actual Observation.
3. Suited to Multi-Step Tasks
A complex task can be broken down into multiple reasoning steps and tool calls, without needing to determine all operational details at the outset.
4. Execution Process Is Easier to Trace
Thought, Action, and Observation can form a structured execution record.
This helps pinpoint tool failures, parameter errors, and issues in task judgment.