ReAct 通过其人类可读的”草稿本”,为 AI 的”黑盒”提供了一个罕见的窗口。Agent 过程的每一步都被记录为想法、行动和观察的序列,提供了以前不可能的诊断水平。
如果 Agent 失败,开发者可以精确定位确切的失败模式——比如模型陷入重复循环的”推理错误”,或外部 API 返回无信息结果的”搜索错误”。这种透明性还促进了“人在回路(Human-in-the-loop)”的纠正。在 ALFWorld 环境(一个基于文本的任务模拟器)中,研究人员证明,人类可以通过简单编辑草稿本上的”想法”来引导失败的 Agent 回到正轨——删除幻觉或添加提示——使 AI 能够立即重新校准其计划[^1]。
示例:ReAct 轨迹
1 2 3 4 5
Thought: 用户询问 2024 年诺贝尔物理学奖得主,我需要确认最新获奖信息。 Action: search[2024 Nobel Prize in Physics winner] Observation: John J. Hopfield and Geoffrey Hinton were awarded... Thought: 好的,我已获得准确信息,现在可以回答用户了。 Action: finish[约翰·霍普菲尔德和杰弗里·辛顿]
for step inrange(MAX_ITERATIONS): action_signature = (action_name, action_input) if action_signature in seen_actions: # 检测到循环,触发终止或切换策略 break seen_actions.add(action_signature)
-- 语义相似度检索 SELECT*, 1- (embedding <=>CAST(:embedding AS vector)) AS similarity FROM agent_few_shot_examples ORDERBY embedding <=>CAST(:embedding AS vector) LIMIT :limit;
这只是最小示例。生产里还得建索引,不然样本库一大,延迟会很难看:
1 2 3 4
-- HNSW 构建慢一点、吃内存一点,但通常有更好的召回/延迟平衡 CREATE INDEX agent_few_shot_examples_embedding_hnsw ON agent_few_shot_examples USING hnsw (embedding vector_cosine_ops);
“The space of interesting harness combinations doesn’t shrink as models improve. Instead, it moves, and the interesting work for AI engineers is to keep finding the next novel combination.”
“It is always good practice to experiment with the model you’re building against, read its traces on realistic problems, and tune its performance to achieve your desired outcomes.”
graph LR
P[1. 规划 拆任务、定目标] --> E[2. 执行 搜资料、调工具]
E --> R[3. 自我反思 挑刺、补漏]
R --> H[4. 人类审核 关键节点拍板]
H -->|需要修正| P
H -->|通过| D[交付]
style P fill:#fff3e6
style E fill:#e6ffe6
style R fill:#ffe6e6
style H fill:#e6f3ff