ReAct 论文注解
§0Abstract 逐句注解
下面是论文 Abstract 的原文,每句配有中文翻译和学习笔记。 高亮词汇hover 可看释义 表示值得记住的学术表达。
§1它是什么 — 两条路线的交汇
2022 年之前,LLM 的能力沿两条独立路线发展。ReAct 的贡献是找到了交叉点。
历史交汇点
路线 A:推理 (Reasoning) 路线 B:行动 (Acting)
───────────────────── ─────────────────────
CoT (Wei et al. 2022.01) WebGPT (OpenAI 2021.12)
Self-Consistency (2022.03) SayCan (Google 2022.04)
MRKL (AI21 2022.05)
but these two directions have remained separate.
↘ ↙
ReAct (2022.10)
ReAct asks, what if these two
fundamental capabilities are combined?
↙ ↘
今天的 Agent 生态 今天的 Tool Use 标准
外界评价
| 维度 | 评价 |
|---|---|
| 学术 | ICLR 2023 Oral,2000+ 引用。后续几乎所有 agent 论文的 baseline |
| 工程 | LangChain 第一个 Agent 类型就叫 zero-shot-react;Claude Code / Cursor 的 agent loop 都是 ReAct 变体 |
| 概念 | "Thought / Action / Observation" 成为 AI Agent 领域的通用术语 |
§2做了什么 — 四类任务、四种对比
四种方法对比
| 方法 | Thought? | Action? | 特点 |
|---|---|---|---|
| Standard | ✘ | ✘ | 直接问直接答 |
| CoT | ✔ | ✘ | 只推理不行动 → 会编造事实 (hallucination) |
| Act-only | ✘ | ✔ | 只行动不推理 → 盲目搜索,缺乏策略 |
| ReAct | ✔ | ✔ | 推理和行动交替 → 既有策略又有真实信息 |
五条核心发现
ReAct > Act-only:有 Thought 让模型知道"该搜什么",而不是乱搜。reasoning traces help the model induce, track, and update action plans.
ReAct > CoT:有 Action 让模型拿到真实信息。ReAct overcomes issues of hallucination and error propagation by interacting with a simple Wikipedia API.
Hallucination 大幅降低:CoT 在 FEVER 上的主要失败原因是编造事实,ReAct 因为能查 Wikipedia,几乎消除了这类错误。
CoT + Self-Consistency 在纯推理上可能更强。论文没有回避自己的短板 — ReAct 解决的是"需要外部信息"的问题,不是所有问题。
ReAct + CoT-SC 融合最强:先用 ReAct,不确定时再用 CoT (SC) 投票,取置信度更高的答案。
§3如何做的 — The Loop
Prompt 五层结构
┌──────────────────────────────────────────────────────┐ │ 1. INSTRUCTION(系统指令) │ │ "Solve a question answering task with │ │ interleaving Thought, Action, Observation..." │ │ 定义三种 Action: Search / Lookup / Finish │ ├──────────────────────────────────────────────────────┤ │ 2. Few-shot 示例(6 道完整示例) │ │ 每道包含完整 Thought→Action→Observation 循环 │ ├──────────────────────────────────────────────────────┤ │ 3. 当前题目 │ │ "Question: Were Scott Derrickson and Ed Wood..." │ ├──────────────────────────────────────────────────────┤ │ 4. 已有的推理历史(逐轮累加) │ │ Thought 1→Action 1→Observation 1→Thought 2→... │ ├──────────────────────────────────────────────────────┤ │ 5. 当前轮提示前缀 │ │ "Thought {i}:" ← 模型从此续写 │ │ stop_sequences = ["\nObservation {i}:"] │ └──────────────────────────────────────────────────────┘
循环机制 — 可视化
点击每一步查看详情:
Search / Lookup / Finish
llm(prompt + f"Thought {i}:", stop=[f"\\nObservation {i}:"])模型看到完整的 prompt(指令 + few-shot + 历史),从 "Thought {i}:" 开始续写。
stop_sequences 在模型输出到 Observation 之前截断 — 不让它编造搜索结果。
stop_sequences:控制权的分界线
run_react.py (你的电脑) LLM API (远程服务器) ═══════════════════════ ══════════════════════ 拼接 prompt + "Thought 1:" ── HTTP 请求 ──► stop = ["\nObservation 1:"] 模型逐 token 生成... "...Action 1: Search[X]" "\nObservation 1:" ← 命中 stop! ⛔ 强制停止 ◄── HTTP 响应 ── 返回 Thought + Action 解析 Action → 调 Wikipedia → 拿到真实结果 → 作为 Observation 拼回 prompt → "Thought 2:" 再发给模型 ── HTTP 请求 ──► ...循环继续...
模型看过 few-shot 里完整的 Thought → Action → Observation 循环,所以它有能力自己编造 Observation。
stop_sequences 就是"拦截点" — 用 few-shot 教模型格式,用 stop_sequences 夺回内容的控制权。
这个思想在今天演化成了 tool_use API(Anthropic / OpenAI 的结构化工具调用接口)。
完整示例:HotpotQA idx=0
"Were Scott Derrickson and Ed Wood of the same nationality?"
Thought 1: I need to search Scott Derrickson and Ed Wood, find their nationalities, then determine if they are the same.
Action 1: Search[Scott Derrickson]
Observation 1: Scott Derrickson (born July 16, 1966) is an American filmmaker. He is known for his work in the horror genre...
→ 模型规划了完整策略(搜两个人→比较国籍),先搜第一个人。
Thought 2: Scott Derrickson is an American filmmaker. I need to search Ed Wood next and find his nationality.
Action 2: Search[Ed Wood]
Observation 2: Edward Davis Wood Jr. (October 10, 1924 – December 10, 1978) was an American filmmaker, actor and novelist...
→ 基于 Round 1 的结果,模型知道还需要搜第二个人。
Thought 3: Ed Wood is also an American filmmaker. So Scott Derrickson and Ed Wood are of the same nationality.
Action 3: Finish[yes]
Result: EM = 1 ✔ F1 = 1.00 ✔ 3 轮完成,0 次 parse 失败
→ 两个 Observation 提供了真实国籍信息,模型做出正确判断。
§4实验结果概览
| 任务 | 指标 | CoT | Act-only | ReAct | ReAct + CoT-SC |
|---|---|---|---|---|---|
| HotpotQA | EM | 29.4 | 25.7 | 27.4 | 35.1 |
| FEVER | Accuracy | 56.3 | 58.9 | 60.9 | 64.6 |
| ALFWorld | Success | — | 45% | 71% | — |
| WebShop | Success | — | 30.1 | 40.0 | — |
数据来自论文 Table 1-4(PaLM-540B 结果)。注意 HotpotQA 上 ReAct 单独并不比 CoT 高很多,但 ReAct + CoT-SC 融合后大幅领先。这体现了两种能力的互补性。
论文用的 PaLM-540B 和 text-davinci-002 已是旧一代模型。
用 Claude Haiku 4.5 跑本项目的复现代码(run_react.py --n 50),HotpotQA EM 通常能到 40%+,远超论文数字。
模型变强了,但 ReAct 的循环架构没有过时。
§V词汇追踪
阅读论文过程中积累的学术英语表达。持续更新。
| English | 中文 | 论文中的语境 |
|---|---|---|
| synergizing | 协同 / 使产生协同效应 | 标题 "Synergizing Reasoning and Acting" — 让推理和行动产生 1+1>2 的效果 |
| reasoning traces | 推理轨迹 | 模型用自然语言写出的思考过程,即 Thought 部分 |
| interleaved manner | 交替方式 | "generate both reasoning traces and actions in an interleaved manner" |
| greater synergy | 更大的协同效应 | "allowing for greater synergy between the two" |
| impressive capabilities | 令人印象深刻的能力 | "LLMs have demonstrated impressive capabilities" |
| have primarily been studied as separate topics | 主要被作为独立课题研究 | 论文开篇定义的"割裂"问题 |
| induce, track, and update | 归纳、追踪、更新 | "reasoning traces help the model induce, track, and update action plans" |
| handle exceptions | 处理异常 | "as well as handle exceptions" — 推理让模型能应对意外情况 |
| interface with external sources | 与外部信息源交互 | "actions allow it to interface with external sources such as knowledge bases" |
| diverse set of | 多样的…集合 | "a diverse set of language and decision making tasks" |
| state-of-the-art baselines | 当前最优基线 | "demonstrate its effectiveness over state-of-the-art baselines" |
| interpretability / interpretable | 可解释性 / 可解释的 | "improved human interpretability and trustworthiness" |
| trustworthiness | 可信度 | 人能看懂模型推理过程,因此更信任其结果 |
| hallucination | 幻觉(编造事实) | "overcomes issues of hallucination and error propagation" |
| error propagation | 错误传播 | 前面的错误推理导致后续步骤全部出错 |
| outperforms | 超越 / 优于 | "ReAct outperforms imitation and reinforcement learning methods" |
| imitation (learning) | 模仿学习 | 从人类示范中学习策略的方法,需要大量标注数据 |
| reinforcement (learning) | 强化学习 | 通过试错和奖励信号学习策略的方法 |
| in-context examples | 上下文示例(few-shot) | "prompted with only one or two in-context examples" |
| we apply our approach | 我们将此方法应用于 | 学术论文中描述方法应用的标准表达 |
| demonstrate its effectiveness | 证明其有效性 | 学术论文中描述实验验证的标准表达 |
§T初学者要点
论文层面:记住三件事
不是"先想完再做",而是每一步都交替。 每一轮 Thought 基于上一轮 Observation 推理,每一轮 Action 基于当前 Thought 决策。 这种交织让模型能根据新信息修正策略。
不是靠 prompt 求模型"不要编造",而是用 API 参数 stop_sequences 硬性截断。
程序决定什么时候该模型输出,什么时候该程序执行。
今天的 tool_use API 是同一思想的结构化演进。
论文诚实报告了 CoT (SC) 在纯推理上更强的场景。 ReAct 解决的是"需要外部信息 + 多步决策"的问题。 甚至提出了 ReAct + CoT-SC 融合策略 — 好论文不回避自己的边界。
代码层面:做三个实验
cd code/react-hands-on && python run_react.py --idx 0观察完整的 Thought → Action → Observation 交替输出。重点看模型在 Thought 里规划了什么。
心智模型
心智模型 1 — Agent = Loop + Tools + LLM ReAct 论文 run_react.py 今天的 Claude Code ────────── ────────────── ────────────────── Loop for i in range(1,9) while True: ... Tools Wikipedia Search/Lookup Read/Write/Bash/Grep LLM text-davinci-002 Claude Opus 4.6 骨架没变。变的是规模。 心智模型 2 — Prompt 是程序,stop_sequences 是中断 INSTRUCTION = 函数签名(定义 I/O 格式) Few-shot 示例 = 单元测试(示范期望行为) 当前题目 + 历史 = 运行时状态 stop_sequences = 中断(在特定位置夺回控制权)