Background
The ReAct (Reasoning and Acting) framework was proposed in 2022 by researchers from Princeton University and Google to address the limitations of traditional large language models in complex tasks. The framework consists of two key modules:
- Reasoning Engine: Decomposes problems using Chain-of-Thought techniques
- Acting Module: Calls tool APIs or generates executable code
Typical Workflow
Taking “book a flight from Beijing to Shanghai next week” as an example:
- Reasoning Phase: Analyze task requirements, determine need to query flight information, compare prices, fill in orders
- Acting Phase: Sequentially call airline API and payment system interfaces to complete operations
- Verification Phase: Check booking results and provide feedback to user
Technical Advantages
- Dynamic planning capabilities
- Multi-tool collaboration
- Interpretability
Application Scenarios
Covers fields such as customer service, data analysis, and research assistance.
Core Components
The ReAct framework consists of three key concepts:
1. Thought
The core reasoning process of the LLM model, representing the model’s internal thinking logic when solving tasks. The thinking process provides the theoretical basis and decision-making basis for subsequent actions.
2. Action
Based on the reasoning results, the LLM decides on specific external operations to execute. Common action types include API calls, tool usage, information retrieval, etc.
3. Observation
The mechanism for the LLM to obtain external feedback, equivalent to the model’s “perception system.” Sources of observation include return results from API calls, outputs from tool execution, new user inputs, etc.
These three components form a closed-loop interaction cycle: Thought → Action → Observation → Rethinking… until the task is completed.
Install Dependencies, Prompt and Code Implementation
The article provides complete code examples for building a ReAct Agent using LangChain and OpenAI, including prompt template usage and TavilySearchResults tool usage, demonstrating the complete process of how LLM independently thinks, searches, and answers questions.