Agent开发中ReAct是什么概念

A
Admin

在 Agent(智能体)开发领域,ReAct 是目前最经典、最广泛使用的 Agent 设计模式之一。它的名字来自:

Reasoning(推理) + Acting(行动) = ReAct (IBM)

核心思想是:

Agent 不只是思考(Reasoning),也不只是调用工具(Acting),而是在“思考 → 行动 → 观察”的循环中不断完成任务。 (Agentica)


ReAct 的基本循环

Thought(思考)
    ↓
Action(执行动作/调用工具)
    ↓
Observation(观察结果)
    ↓
Thought(重新思考)
    ↓
...
    ↓
Final Answer

例如用户问:

“东京明天会下雨吗?如果下雨帮我推荐室内景点。”

Agent 的执行过程可能是:

Thought:
我需要先查询东京明天的天气。

Action:
调用天气API(Tokyo)

Observation:
明天降雨概率80%

Thought:
既然会下雨,需要推荐室内景点。

Action:
搜索东京室内景点

Observation:
东京国立博物馆、teamLab、东京站地下街

Thought:
已经获得所需信息。

Final Answer:
东京明天有较高降雨概率,建议前往……

这种模式比一次性回答更灵活。 (Agentica)


为什么 ReAct 很重要

在 ReAct 出现之前主要有两种方法:

1. Chain of Thought(CoT)

只会思考:

Question
  ↓
Think
  ↓
Answer

问题:

  • 只能依赖模型内部知识
  • 无法获取实时信息
  • 容易幻觉(Hallucination)

2. Tool Calling

只会调用工具:

Question
  ↓
Call Tool
  ↓
Answer

问题:

  • 缺少规划能力
  • 多步骤任务容易迷失方向

ReAct 把两者结合起来:

Think → Tool → Observe → Think → Tool ...

因此能完成更复杂的任务。 (agentscookbook.com)


在 Agent 框架中的体现

几乎所有主流 Agent 框架都能看到 ReAct 的影子:

很多框架本质上都是在实现:

while not done:
    thought = llm(reason)
    action = choose_tool(thought)
    observation = run_tool(action)
    context += observation

(Agentica)


一个简化版 ReAct Prompt

开发中经常会看到类似提示词:

You have access to these tools:

Search
Calculator

Use the following format:

Thought: think about what to do
Action: tool name
Action Input: input
Observation: tool result

... repeat ...

Final Answer: answer to user

模型运行时会生成:

Thought: 我需要先查找苹果公司市值
Action: Search
Action Input: Apple market cap

Observation: 3.2 trillion USD

Thought: 已获得结果
Final Answer: 苹果公司市值约3.2万亿美元

这就是典型的 ReAct Agent。 (IBM)


现在的发展趋势

2023~2026 年很多 Agent 架构已经不再是纯 ReAct,而是在其基础上扩展:

  • ReAct → Reflexion(增加自我反思)
  • ReAct → Plan-and-Execute(先规划后执行)
  • ReAct → ReWOO(规划与工具调用分离)
  • ReAct → Multi-Agent(多个 Agent 协作) (Agentica)

但即使是今天,大多数 Agent 的核心执行循环仍然可以抽象为:

Reason
  ↓
Act
  ↓
Observe
  ↓
Reason

所以你可以把 ReAct 理解为现代 AI Agent 的“Hello World 架构”——几乎所有 Agent 框架都是从它演化出来的。 (villion.io)