智能体经典范式构建:从ReAct到Reflection

在上一章中,我们深入探讨了作为现代智能体"大脑"的大语言模型------了解了它内部的Transformer架构、与之交互的方法,以及它的能力边界。现在,是时候将这些理论知识转化为对智能体工作范式的系统理解。

一个现代的智能体,其核心能力在于能将大语言模型的推理能力与外部世界联通。它能够自主地理解用户意图、拆解复杂任务,并通过调用代码解释器、搜索引擎、API等一系列"工具"来获取信息、执行操作,最终达成目标。

然而,智能体并非万能。它同样面临着来自大模型本身的"幻觉"问题、在复杂任务中可能陷入推理循环、以及对工具的错误使用等挑战。为了更好地组织智能体的"思考"与"行动"过程,业界涌现出了多种经典的架构范式。

在本章中,我们将系统学习其中最具代表性的三种:

  • ReAct(Reasoning and Acting) :一种将"思考"和"行动"紧密结合的范式,让智能体边想边做,动态调整。
  • Plan-and-Solve :一种"三思而后行"的范式,智能体首先生成一个完整的行动计划,然后严格执行
  • Reflection :一种赋予智能体"反思"能力的范式,通过自我批判和修正来优化结果。

📊 全文知识框架图

#mermaid-svg-FEzLrHQpLfc7GxOB{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-FEzLrHQpLfc7GxOB .error-icon{fill:#552222;}#mermaid-svg-FEzLrHQpLfc7GxOB .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-FEzLrHQpLfc7GxOB .marker{fill:#333333;stroke:#333333;}#mermaid-svg-FEzLrHQpLfc7GxOB .marker.cross{stroke:#333333;}#mermaid-svg-FEzLrHQpLfc7GxOB svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-FEzLrHQpLfc7GxOB p{margin:0;}#mermaid-svg-FEzLrHQpLfc7GxOB .edge{stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .section--1 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section--1 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section--1 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section--1 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section--1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section--1 text{fill:#ffffff;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon--1{font-size:40px;color:#ffffff;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge--1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth--1{stroke-width:17;}#mermaid-svg-FEzLrHQpLfc7GxOB .section--1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-0 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-0 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-0 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-0 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-0 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-0{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-0{stroke-width:14;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-1 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-1 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-1 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-1 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-1 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-1{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-1{stroke-width:11;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-2 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-2 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-2 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-2 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-2 text{fill:#ffffff;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-2{stroke-width:8;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-3 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-3 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-3 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-3 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-3 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-3{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-3{stroke-width:5;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-4 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-4 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-4 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-4 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-4 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-4{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-4{stroke-width:2;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-5 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-5 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-5 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-5 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-5 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-5{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-5{stroke-width:-1;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-6 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-6 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-6 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-6 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-6 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-6{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-6{stroke-width:-4;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-7 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-7 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-7 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-7 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-7 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-7{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-7{stroke-width:-7;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-8 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-8 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-8 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-8 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-8 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-8{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-8{stroke-width:-10;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-9 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-9 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-9 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-9 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-9 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-9{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-9{stroke-width:-13;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-10 rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-10 path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-10 circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-10 polygon,#mermaid-svg-FEzLrHQpLfc7GxOB .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-10 text{fill:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .node-icon-10{font-size:40px;color:black;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .edge-depth-10{stroke-width:-16;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled circle,#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:lightgray;}#mermaid-svg-FEzLrHQpLfc7GxOB .disabled text{fill:#efefef;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-root rect,#mermaid-svg-FEzLrHQpLfc7GxOB .section-root path,#mermaid-svg-FEzLrHQpLfc7GxOB .section-root circle,#mermaid-svg-FEzLrHQpLfc7GxOB .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-FEzLrHQpLfc7GxOB .section-root text{fill:#ffffff;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-root span{color:#ffffff;}#mermaid-svg-FEzLrHQpLfc7GxOB .section-2 span{color:#ffffff;}#mermaid-svg-FEzLrHQpLfc7GxOB .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-FEzLrHQpLfc7GxOB .edge{fill:none;}#mermaid-svg-FEzLrHQpLfc7GxOB .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-FEzLrHQpLfc7GxOB :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 智能体经典范式构建
ReAct范式
核心理念
思考Thought
行动Action
观察Observation
工作流程
思考→行动→观察循环
关键组件
工具定义与描述
提示词设计
输出解析
适用场景
需要外部知识的任务
动态交互任务
主要优势
灵活适应
可解释性强
主要局限
可能局部最优
效率问题
Plan-and-Solve范式
核心理念
先规划后执行
工作流程
规划阶段
执行阶段
关键组件
规划器Planner
执行器Executor
状态管理
适用场景
多步推理任务
结构化问题
主要优势
目标一致
不易跑偏
主要局限
缺乏动态调整
Reflection范式
核心理念
自我反思迭代优化
工作流程
执行→反思→优化循环
关键组件
记忆模块
评审员角色
优化器角色
适用场景
代码生成
内容创作
主要优势
自我纠错
持续优化
主要局限
迭代成本高

一、智能体为何需要"范式"?

在构建智能体之前,我们首先需要理解一个核心问题:为什么不能简单地把问题扔给大语言模型,让它直接输出答案?

原因在于,大语言模型虽然拥有海量的知识和强大的推理能力,但它本质上是一个"纯思考"的系统。它存在三个根本性的局限:

局限 说明 示例
信息封闭性 模型的知识截止于训练数据,无法获取实时信息 问"今天天气怎么样"时,模型无法回答
工具缺失 模型只能输出文本,无法执行实际操作 无法调用计算器、搜索网页、操作数据库
缺乏自我修正 模型的一次性输出可能包含错误,但没有机制去发现和纠正 编造不存在的参考文献

"范式"的本质,就是一套结构化的方法,用来弥补这些局限。

它规定了智能体应该以什么样的节奏来"思考"、以什么样的方式来"行动"、以及如何根据外界的反馈来调整自己的策略。通过范式,大语言模型从一个"只会聊天的程序",变成了一个"能够自主完成任务的智能体"。

二、ReAct范式:边想边做的智能体

ReAct(Reason + Act)由Shunyu Yao 等于2022年提出,其核心思想是模仿人类解决问题的方式,将推理 (Reasoning)与行动 (Acting)显式地结合起来,形成一个"思考-行动-观察"的循环。

2.1 ReAct的工作流程

在ReAct诞生之前,主流的方法可以分为两类:一类是"纯思考"型,如思维链(Chain-of-Thought),它能引导模型进行复杂的逻辑推理,但无法与外部世界交互,容易产生事实幻觉;另一类是"纯行动"型,模型直接输出要执行的动作,但缺乏规划和纠错能力。

ReAct的巧妙之处在于,它认识到思考与行动是相辅相成的------思考指导行动,而行动的结果又反过来修正思考。
#mermaid-svg-Pw7HI7scWApTrIfo{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-Pw7HI7scWApTrIfo .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-Pw7HI7scWApTrIfo .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-Pw7HI7scWApTrIfo .error-icon{fill:#552222;}#mermaid-svg-Pw7HI7scWApTrIfo .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-Pw7HI7scWApTrIfo .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-Pw7HI7scWApTrIfo .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-Pw7HI7scWApTrIfo .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-Pw7HI7scWApTrIfo .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-Pw7HI7scWApTrIfo .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-Pw7HI7scWApTrIfo .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-Pw7HI7scWApTrIfo .marker{fill:#333333;stroke:#333333;}#mermaid-svg-Pw7HI7scWApTrIfo .marker.cross{stroke:#333333;}#mermaid-svg-Pw7HI7scWApTrIfo svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-Pw7HI7scWApTrIfo p{margin:0;}#mermaid-svg-Pw7HI7scWApTrIfo .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-Pw7HI7scWApTrIfo .cluster-label text{fill:#333;}#mermaid-svg-Pw7HI7scWApTrIfo .cluster-label span{color:#333;}#mermaid-svg-Pw7HI7scWApTrIfo .cluster-label span p{background-color:transparent;}#mermaid-svg-Pw7HI7scWApTrIfo .label text,#mermaid-svg-Pw7HI7scWApTrIfo span{fill:#333;color:#333;}#mermaid-svg-Pw7HI7scWApTrIfo .node rect,#mermaid-svg-Pw7HI7scWApTrIfo .node circle,#mermaid-svg-Pw7HI7scWApTrIfo .node ellipse,#mermaid-svg-Pw7HI7scWApTrIfo .node polygon,#mermaid-svg-Pw7HI7scWApTrIfo .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-Pw7HI7scWApTrIfo .rough-node .label text,#mermaid-svg-Pw7HI7scWApTrIfo .node .label text,#mermaid-svg-Pw7HI7scWApTrIfo .image-shape .label,#mermaid-svg-Pw7HI7scWApTrIfo .icon-shape .label{text-anchor:middle;}#mermaid-svg-Pw7HI7scWApTrIfo .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-Pw7HI7scWApTrIfo .rough-node .label,#mermaid-svg-Pw7HI7scWApTrIfo .node .label,#mermaid-svg-Pw7HI7scWApTrIfo .image-shape .label,#mermaid-svg-Pw7HI7scWApTrIfo .icon-shape .label{text-align:center;}#mermaid-svg-Pw7HI7scWApTrIfo .node.clickable{cursor:pointer;}#mermaid-svg-Pw7HI7scWApTrIfo .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-Pw7HI7scWApTrIfo .arrowheadPath{fill:#333333;}#mermaid-svg-Pw7HI7scWApTrIfo .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-Pw7HI7scWApTrIfo .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-Pw7HI7scWApTrIfo .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Pw7HI7scWApTrIfo .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-Pw7HI7scWApTrIfo .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Pw7HI7scWApTrIfo .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-Pw7HI7scWApTrIfo .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-Pw7HI7scWApTrIfo .cluster text{fill:#333;}#mermaid-svg-Pw7HI7scWApTrIfo .cluster span{color:#333;}#mermaid-svg-Pw7HI7scWApTrIfo div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-Pw7HI7scWApTrIfo .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-Pw7HI7scWApTrIfo rect.text{fill:none;stroke-width:0;}#mermaid-svg-Pw7HI7scWApTrIfo .icon-shape,#mermaid-svg-Pw7HI7scWApTrIfo .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Pw7HI7scWApTrIfo .icon-shape p,#mermaid-svg-Pw7HI7scWApTrIfo .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-Pw7HI7scWApTrIfo .icon-shape .label rect,#mermaid-svg-Pw7HI7scWApTrIfo .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Pw7HI7scWApTrIfo .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-Pw7HI7scWApTrIfo .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-Pw7HI7scWApTrIfo :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 核心循环
追加到历史
💭 思考 Thought

分析当前状态

制定下一步计划
⚡ 行动 Action

调用工具/执行操作
👀 观察 Observation

获取执行结果

在每一轮循环中,智能体的行为轨迹严格遵循一个固定的三步格式:

第一步:思考(Thought) ------这是智能体的"内心独白"。它会分析当前情况、分解任务、制定下一步计划,或者反思上一步的结果。思考过程完全透明,让开发者能够理解智能体的决策逻辑。

第二步:行动(Action) ------这是智能体决定采取的具体动作,通常是调用一个外部工具,例如Search['华为最新款手机']。行动指令需要明确指定工具名称和输入参数。

第三步:观察(Observation) ------这是执行行动后从外部工具返回的结果,例如搜索结果的摘要或API的返回值。

这个过程将持续循环,将新的观察结果追加到历史记录中,形成一个不断增长的上下文,直到智能体在思考中认为已经找到了最终答案。
#mermaid-svg-HVvvp6ZxdNrZyqGI{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-HVvvp6ZxdNrZyqGI .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-HVvvp6ZxdNrZyqGI .error-icon{fill:#552222;}#mermaid-svg-HVvvp6ZxdNrZyqGI .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-HVvvp6ZxdNrZyqGI .marker{fill:#333333;stroke:#333333;}#mermaid-svg-HVvvp6ZxdNrZyqGI .marker.cross{stroke:#333333;}#mermaid-svg-HVvvp6ZxdNrZyqGI svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-HVvvp6ZxdNrZyqGI p{margin:0;}#mermaid-svg-HVvvp6ZxdNrZyqGI .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-HVvvp6ZxdNrZyqGI .cluster-label text{fill:#333;}#mermaid-svg-HVvvp6ZxdNrZyqGI .cluster-label span{color:#333;}#mermaid-svg-HVvvp6ZxdNrZyqGI .cluster-label span p{background-color:transparent;}#mermaid-svg-HVvvp6ZxdNrZyqGI .label text,#mermaid-svg-HVvvp6ZxdNrZyqGI span{fill:#333;color:#333;}#mermaid-svg-HVvvp6ZxdNrZyqGI .node rect,#mermaid-svg-HVvvp6ZxdNrZyqGI .node circle,#mermaid-svg-HVvvp6ZxdNrZyqGI .node ellipse,#mermaid-svg-HVvvp6ZxdNrZyqGI .node polygon,#mermaid-svg-HVvvp6ZxdNrZyqGI .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-HVvvp6ZxdNrZyqGI .rough-node .label text,#mermaid-svg-HVvvp6ZxdNrZyqGI .node .label text,#mermaid-svg-HVvvp6ZxdNrZyqGI .image-shape .label,#mermaid-svg-HVvvp6ZxdNrZyqGI .icon-shape .label{text-anchor:middle;}#mermaid-svg-HVvvp6ZxdNrZyqGI .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-HVvvp6ZxdNrZyqGI .rough-node .label,#mermaid-svg-HVvvp6ZxdNrZyqGI .node .label,#mermaid-svg-HVvvp6ZxdNrZyqGI .image-shape .label,#mermaid-svg-HVvvp6ZxdNrZyqGI .icon-shape .label{text-align:center;}#mermaid-svg-HVvvp6ZxdNrZyqGI .node.clickable{cursor:pointer;}#mermaid-svg-HVvvp6ZxdNrZyqGI .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-HVvvp6ZxdNrZyqGI .arrowheadPath{fill:#333333;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-HVvvp6ZxdNrZyqGI .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-HVvvp6ZxdNrZyqGI .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-HVvvp6ZxdNrZyqGI .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-HVvvp6ZxdNrZyqGI .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-HVvvp6ZxdNrZyqGI .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-HVvvp6ZxdNrZyqGI .cluster text{fill:#333;}#mermaid-svg-HVvvp6ZxdNrZyqGI .cluster span{color:#333;}#mermaid-svg-HVvvp6ZxdNrZyqGI div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-HVvvp6ZxdNrZyqGI .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-HVvvp6ZxdNrZyqGI rect.text{fill:none;stroke-width:0;}#mermaid-svg-HVvvp6ZxdNrZyqGI .icon-shape,#mermaid-svg-HVvvp6ZxdNrZyqGI .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-HVvvp6ZxdNrZyqGI .icon-shape p,#mermaid-svg-HVvvp6ZxdNrZyqGI .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-HVvvp6ZxdNrZyqGI .icon-shape .label rect,#mermaid-svg-HVvvp6ZxdNrZyqGI .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-HVvvp6ZxdNrZyqGI .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-HVvvp6ZxdNrZyqGI .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-HVvvp6ZxdNrZyqGI :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 否

开始
💭 思考: 分析问题
⚡ 行动: 调用工具
👀 观察: 获取结果
任务完成?
✅ 输出最终答案

2.2 ReAct背后的设计思想

(1)工具是智能体的"手脚"

如果说大语言模型是智能体的大脑,那么工具(Tools)就是其与外部世界交互的"手和脚"。一个良好定义的工具应包含三个核心要素:

要素 说明 为什么重要
名称 简洁、唯一的标识符 供智能体在Action中精确调用
描述 清晰的自然语言说明 最关键的部分------模型据此判断何时使用该工具
执行逻辑 真正执行任务的函数 工具的实际功能实现

工具描述之所以最关键,是因为大语言模型完全依赖这段文本来理解工具的用途、适用场景和输入格式。如果描述模糊或不准确,模型就可能:

  • 在不该用的时候使用工具
  • 在应该使用工具的时候选择"硬想"
  • 使用工具时提供错误的输入格式

(2)提示词是行动的"操作手册"

在ReAct范式中,系统提示词的设计至关重要。它需要在一次调用中完成三项任务:

任务 提示词中的体现
角色设定 "你是一个有能力调用外部工具的智能助手"
工具清单 列出所有可用工具的名称和描述
格式规约 强制要求输出"Thought: ... Action: ..."的格式

特别是格式规约,它是整个ReAct机制的"结构骨架"。它让智能体的输出具有高度的结构性,使得代码能够通过简单的正则表达式精确地解析出"思考"和"行动"。

(3)循环的安全机制

ReAct循环需要设置一个最大步数(max_steps)作为安全阀。为什么需要它?

  • 防止无限循环:智能体可能在两个工具之间反复横跳
  • 防止资源耗尽:每一步都调用LLM,成本随时间线性增长
  • 防止上下文溢出:Observation不断累积,可能超出模型的上下文窗口

2.3 ReAct的适用场景与优缺点

🎯 最适合的场景

场景类型 说明 示例
需要外部知识的任务 查询实时信息、搜索专业领域知识 天气查询、新闻检索
需要精确计算的任务 将数学问题交给计算器工具 复杂算术、统计分析
需要与API交互的任务 操作数据库、调用第三方服务 数据写入、邮件发送
优点 缺点
高可解释性:Thought链完全透明,便于调试 对LLM能力强依赖:模型能力不足时容易出错
动态规划与纠错:能根据外部反馈实时调整 执行效率问题:每步都调用LLM,Token消耗大
工具协同能力:LLM负责推理,工具负责执行 提示词脆弱性:对提示词设计敏感
可能陷入局部最优:缺乏全局规划

💡 通俗类比 :ReAct就像一个经验丰富的侦探------他不会在行动前制定完整的计划,而是根据现场发现的每一条线索,思考下一步该去哪里、该找谁问话,然后在行动中获得新线索,再继续推理。

三、Plan-and-Solve范式:三思而后行的智能体

如果说ReAct像一个经验丰富的侦探,根据现场的蛛丝马迹一步步推理,随时调整调查方向;那么Plan-and-Solve则更像一位建筑师,在动工之前必须先绘制出完整的蓝图,然后严格按照蓝图来施工。

Plan-and-Solve Prompting由Lei Wang等人在2023年提出,其核心动机是为了解决思维链在处理多步骤、复杂问题时容易"偏离轨道"的问题。

3.1 Plan-and-Solve的工作原理

与ReAct将思考和行动融合在每一步不同,Plan-and-Solve将整个流程解耦为两个核心阶段:
#mermaid-svg-WnswDpF9jF48LPju{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-WnswDpF9jF48LPju .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-WnswDpF9jF48LPju .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-WnswDpF9jF48LPju .error-icon{fill:#552222;}#mermaid-svg-WnswDpF9jF48LPju .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-WnswDpF9jF48LPju .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-WnswDpF9jF48LPju .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-WnswDpF9jF48LPju .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-WnswDpF9jF48LPju .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-WnswDpF9jF48LPju .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-WnswDpF9jF48LPju .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-WnswDpF9jF48LPju .marker{fill:#333333;stroke:#333333;}#mermaid-svg-WnswDpF9jF48LPju .marker.cross{stroke:#333333;}#mermaid-svg-WnswDpF9jF48LPju svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-WnswDpF9jF48LPju p{margin:0;}#mermaid-svg-WnswDpF9jF48LPju .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-WnswDpF9jF48LPju .cluster-label text{fill:#333;}#mermaid-svg-WnswDpF9jF48LPju .cluster-label span{color:#333;}#mermaid-svg-WnswDpF9jF48LPju .cluster-label span p{background-color:transparent;}#mermaid-svg-WnswDpF9jF48LPju .label text,#mermaid-svg-WnswDpF9jF48LPju span{fill:#333;color:#333;}#mermaid-svg-WnswDpF9jF48LPju .node rect,#mermaid-svg-WnswDpF9jF48LPju .node circle,#mermaid-svg-WnswDpF9jF48LPju .node ellipse,#mermaid-svg-WnswDpF9jF48LPju .node polygon,#mermaid-svg-WnswDpF9jF48LPju .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-WnswDpF9jF48LPju .rough-node .label text,#mermaid-svg-WnswDpF9jF48LPju .node .label text,#mermaid-svg-WnswDpF9jF48LPju .image-shape .label,#mermaid-svg-WnswDpF9jF48LPju .icon-shape .label{text-anchor:middle;}#mermaid-svg-WnswDpF9jF48LPju .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-WnswDpF9jF48LPju .rough-node .label,#mermaid-svg-WnswDpF9jF48LPju .node .label,#mermaid-svg-WnswDpF9jF48LPju .image-shape .label,#mermaid-svg-WnswDpF9jF48LPju .icon-shape .label{text-align:center;}#mermaid-svg-WnswDpF9jF48LPju .node.clickable{cursor:pointer;}#mermaid-svg-WnswDpF9jF48LPju .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-WnswDpF9jF48LPju .arrowheadPath{fill:#333333;}#mermaid-svg-WnswDpF9jF48LPju .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-WnswDpF9jF48LPju .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-WnswDpF9jF48LPju .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-WnswDpF9jF48LPju .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-WnswDpF9jF48LPju .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-WnswDpF9jF48LPju .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-WnswDpF9jF48LPju .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-WnswDpF9jF48LPju .cluster text{fill:#333;}#mermaid-svg-WnswDpF9jF48LPju .cluster span{color:#333;}#mermaid-svg-WnswDpF9jF48LPju div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-WnswDpF9jF48LPju .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-WnswDpF9jF48LPju rect.text{fill:none;stroke-width:0;}#mermaid-svg-WnswDpF9jF48LPju .icon-shape,#mermaid-svg-WnswDpF9jF48LPju .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-WnswDpF9jF48LPju .icon-shape p,#mermaid-svg-WnswDpF9jF48LPju .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-WnswDpF9jF48LPju .icon-shape .label rect,#mermaid-svg-WnswDpF9jF48LPju .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-WnswDpF9jF48LPju .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-WnswDpF9jF48LPju .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-WnswDpF9jF48LPju :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 执行阶段
规划阶段
❓ 用户问题
📋 规划器 Planner
📝 行动计划

步骤1: 计算周一销量

步骤2: 计算周二销量

步骤3: 计算周三销量

步骤4: 计算总销量
⚡ 执行步骤1
📊 结果1: 15
⚡ 执行步骤2
📊 结果2: 30
⚡ 执行步骤3
📊 结果3: 25
⚡ 执行步骤4
✅ 最终答案: 70

规划阶段(Planning Phase) :首先,智能体会接收用户的完整问题。它的第一个任务不是直接去解决问题或调用工具,而是将问题分解,并制定出一个清晰、分步骤的行动计划。

执行阶段(Solving Phase) :在获得完整的计划后,智能体进入执行阶段。它会严格按照计划中的步骤,逐一执行。每一步的执行都可能是一次独立的LLM调用,或者是对上一步结果的加工处理。

这种"先谋后动"的策略,使得智能体在处理需要长远规划的复杂任务时,能够保持更高的目标一致性,避免在中间步骤中迷失方向。

3.2 为什么"先规划"更可靠?

在分析Plan-and-Solve的优势之前,我们首先需要理解它与ReAct的本质区别。

ReAct反应式的:走一步看一步,根据反馈动态调整。这种方式的优点是灵活,但缺点是容易"走偏"------在复杂任务中,每一步的微小偏差可能在多步之后累积成巨大的方向性错误。

Plan-and-Solve前摄式的:先看清全局再行动。这种方式的优点是方向明确,但缺点是如果初始规划有误,整个执行过程都会偏离目标。

核心优势体现在:

优势 说明
目标一致性 始终围绕原始问题,不会偏离轨道
可追溯性 每一步执行都与计划中的某一步对应,便于调试
并行潜力 如果步骤之间相互独立,可以并行执行

关键设计要点

  1. 规划器的输出格式必须严格受控(如输出Python列表),便于程序解析
  2. 执行器需要维护状态,记录已完成步骤及其结果
  3. 历史结果的格式直接影响后续步骤的效果------过于简略可能丢失信息,过于详细可能引入噪声

3.3 Plan-and-Solve的适用场景与优缺点

🎯 最适合的场景

场景类型 说明 示例
多步数学应用题 需要先列出计算步骤,再逐一求解 复杂的算术、代数问题
需要整合多个信息源的报告 先规划好报告结构,再逐一填充内容 市场分析报告、项目方案
代码生成任务 先构思好函数、类和模块的结构,再逐一实现 软件架构设计
优点 缺点
目标一致性强:全程围绕原始问题,不易偏离 缺乏动态调整:无法在途中修正计划
可追溯性高:每步执行与计划一一对应 规划质量依赖模型:初始规划出错则全错
便于并行:独立步骤可同时执行 不适应不确定性任务:结果未知时难以预先规划

💡 通俗类比 :Plan-and-Solve就像一位建筑师------他不会边盖楼边改图纸,而是先画出完整的施工蓝图,再让施工队严格按照图纸执行。

四、Reflection范式:会自我反思的智能体

在ReAct和Plan-and-Solve范式中,智能体一旦完成任务,工作流程便告结束。然而,它们生成的初始答案------无论是行动轨迹还是最终结果------都可能存在谬误或有待改进之处。

Reflection机制的核心思想,正是为智能体引入一种事后的自我校正循环,使其能够像人类一样,审视自己的工作,发现不足,并进行迭代优化

4.1 Reflection的核心思想

Reflection(在相关论文中常被称为Reflexion)机制的灵感来源于人类的学习过程:我们完成初稿后会进行校对,解出数学题后会进行验算。

Reflection的核心工作流程可以概括为一个简洁的三步循环
#mermaid-svg-49bGZYgYPc2ThkW3{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-49bGZYgYPc2ThkW3 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-49bGZYgYPc2ThkW3 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-49bGZYgYPc2ThkW3 .error-icon{fill:#552222;}#mermaid-svg-49bGZYgYPc2ThkW3 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-49bGZYgYPc2ThkW3 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-49bGZYgYPc2ThkW3 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-49bGZYgYPc2ThkW3 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-49bGZYgYPc2ThkW3 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-49bGZYgYPc2ThkW3 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-49bGZYgYPc2ThkW3 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-49bGZYgYPc2ThkW3 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-49bGZYgYPc2ThkW3 .marker.cross{stroke:#333333;}#mermaid-svg-49bGZYgYPc2ThkW3 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-49bGZYgYPc2ThkW3 p{margin:0;}#mermaid-svg-49bGZYgYPc2ThkW3 .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-49bGZYgYPc2ThkW3 .cluster-label text{fill:#333;}#mermaid-svg-49bGZYgYPc2ThkW3 .cluster-label span{color:#333;}#mermaid-svg-49bGZYgYPc2ThkW3 .cluster-label span p{background-color:transparent;}#mermaid-svg-49bGZYgYPc2ThkW3 .label text,#mermaid-svg-49bGZYgYPc2ThkW3 span{fill:#333;color:#333;}#mermaid-svg-49bGZYgYPc2ThkW3 .node rect,#mermaid-svg-49bGZYgYPc2ThkW3 .node circle,#mermaid-svg-49bGZYgYPc2ThkW3 .node ellipse,#mermaid-svg-49bGZYgYPc2ThkW3 .node polygon,#mermaid-svg-49bGZYgYPc2ThkW3 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-49bGZYgYPc2ThkW3 .rough-node .label text,#mermaid-svg-49bGZYgYPc2ThkW3 .node .label text,#mermaid-svg-49bGZYgYPc2ThkW3 .image-shape .label,#mermaid-svg-49bGZYgYPc2ThkW3 .icon-shape .label{text-anchor:middle;}#mermaid-svg-49bGZYgYPc2ThkW3 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-49bGZYgYPc2ThkW3 .rough-node .label,#mermaid-svg-49bGZYgYPc2ThkW3 .node .label,#mermaid-svg-49bGZYgYPc2ThkW3 .image-shape .label,#mermaid-svg-49bGZYgYPc2ThkW3 .icon-shape .label{text-align:center;}#mermaid-svg-49bGZYgYPc2ThkW3 .node.clickable{cursor:pointer;}#mermaid-svg-49bGZYgYPc2ThkW3 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-49bGZYgYPc2ThkW3 .arrowheadPath{fill:#333333;}#mermaid-svg-49bGZYgYPc2ThkW3 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-49bGZYgYPc2ThkW3 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-49bGZYgYPc2ThkW3 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-49bGZYgYPc2ThkW3 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-49bGZYgYPc2ThkW3 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-49bGZYgYPc2ThkW3 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-49bGZYgYPc2ThkW3 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-49bGZYgYPc2ThkW3 .cluster text{fill:#333;}#mermaid-svg-49bGZYgYPc2ThkW3 .cluster span{color:#333;}#mermaid-svg-49bGZYgYPc2ThkW3 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-49bGZYgYPc2ThkW3 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-49bGZYgYPc2ThkW3 rect.text{fill:none;stroke-width:0;}#mermaid-svg-49bGZYgYPc2ThkW3 .icon-shape,#mermaid-svg-49bGZYgYPc2ThkW3 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-49bGZYgYPc2ThkW3 .icon-shape p,#mermaid-svg-49bGZYgYPc2ThkW3 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-49bGZYgYPc2ThkW3 .icon-shape .label rect,#mermaid-svg-49bGZYgYPc2ThkW3 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-49bGZYgYPc2ThkW3 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-49bGZYgYPc2ThkW3 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-49bGZYgYPc2ThkW3 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 迭代优化循环
提供反馈
新版本
⚡ 执行 Execution

生成初稿
🔍 反思 Reflection

评审员评估
🛠️ 优化 Refinement

根据反馈修正

执行(Execution) :首先,智能体使用我们熟悉的方法(如ReAct或Plan-and-Solve)尝试完成任务,生成一个初步的解决方案或行动轨迹。

反思(Reflection) :接着,智能体进入反思阶段。它会调用一个独立的、或者带有特殊提示词的大语言模型实例,来扮演一个"评审员"的角色。这个"评审员"会审视第一步生成的"初稿",并从多个维度进行评估:

评估维度 关注的问题
事实性 是否存在与常识或已知事实相悖的内容?
逻辑性 推理过程是否存在不连贯或矛盾之处?
效率性 是否有更直接、更简洁的路径来完成任务?
完整性 是否忽略了问题的某些关键约束或方面?

根据评估,它会生成一段结构化的反馈,指出具体的问题所在和改进建议。

优化(Refinement) :最后,智能体将"初稿"和"反馈"作为新的上下文,再次调用大语言模型,要求它根据反馈内容对初稿进行修正,生成一个更完善的"修订稿"。

这个循环可以重复进行多次,直到反思阶段不再发现新的问题,或达到预设的迭代次数上限。

4.2 为什么"自我反思"有效?

Reflection的有效性建立在两个关键机制之上:

机制一:多角色协作

Reflection最巧妙的设计是让同一个LLM扮演不同角色。智能体既是"执行者"(撰写初稿),又是"评审员"(提出反馈),还是"优化者"(修改完善)。这种多角色协作的意义在于:

  • 视角切换:同一模型从"创作者"切换到"评审员"时,会采用不同的评判标准,发现"创作者"视角下看不到的问题
  • 无监督纠错:不依赖外部工具或标注数据,模型通过自我检查来提升输出质量

机制二:记忆轨迹的积累

整个迭代过程的关键在于记忆模块------它记录了每一次的执行结果和反馈意见。当智能体在优化时,它可以看到:

"我上一轮是这样写的,评审员指出了这些问题,所以我这一轮需要在这些方面改进......"

这种完整的"执行-反馈-修正"轨迹,让智能体不仅知道最终答案,还知道自己是如何从错误走向正确的,为后续任务积累宝贵经验。

4.3 Reflection的适用场景与优缺点

🎯 最适合的场景

场景类型 说明 示例
代码生成与优化 生成代码→审查性能→优化算法 算法实现、代码重构
内容创作与润色 生成初稿→检查逻辑→修改完善 文章写作、邮件起草
需要高质量输出的任务 容错率低、要求严谨的场景 技术文档、法律文书
优点 缺点
内部纠错回路:能发现并修正自身错误 迭代成本高:每次迭代都调用多次LLM
持续优化:能将"不错"的输出变成"优秀" 可能过度优化:陷入无休止的修改
学习效应:积累的"错误-修正"经验 依赖评审质量:评审员本身也可能犯错

💡 通俗类比 :Reflection就像一位作家------他不会一稿定稿,而是先写初稿,然后像编辑一样审阅自己的作品,提出修改意见,再根据意见修改,直到满意为止。

五、三种范式对比

#mermaid-svg-dYAHGu9EDWp1xyzW{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-dYAHGu9EDWp1xyzW .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-dYAHGu9EDWp1xyzW .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-dYAHGu9EDWp1xyzW .error-icon{fill:#552222;}#mermaid-svg-dYAHGu9EDWp1xyzW .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-dYAHGu9EDWp1xyzW .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-dYAHGu9EDWp1xyzW .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-dYAHGu9EDWp1xyzW .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-dYAHGu9EDWp1xyzW .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-dYAHGu9EDWp1xyzW .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-dYAHGu9EDWp1xyzW .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-dYAHGu9EDWp1xyzW .marker{fill:#333333;stroke:#333333;}#mermaid-svg-dYAHGu9EDWp1xyzW .marker.cross{stroke:#333333;}#mermaid-svg-dYAHGu9EDWp1xyzW svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-dYAHGu9EDWp1xyzW p{margin:0;}#mermaid-svg-dYAHGu9EDWp1xyzW .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-dYAHGu9EDWp1xyzW .cluster-label text{fill:#333;}#mermaid-svg-dYAHGu9EDWp1xyzW .cluster-label span{color:#333;}#mermaid-svg-dYAHGu9EDWp1xyzW .cluster-label span p{background-color:transparent;}#mermaid-svg-dYAHGu9EDWp1xyzW .label text,#mermaid-svg-dYAHGu9EDWp1xyzW span{fill:#333;color:#333;}#mermaid-svg-dYAHGu9EDWp1xyzW .node rect,#mermaid-svg-dYAHGu9EDWp1xyzW .node circle,#mermaid-svg-dYAHGu9EDWp1xyzW .node ellipse,#mermaid-svg-dYAHGu9EDWp1xyzW .node polygon,#mermaid-svg-dYAHGu9EDWp1xyzW .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-dYAHGu9EDWp1xyzW .rough-node .label text,#mermaid-svg-dYAHGu9EDWp1xyzW .node .label text,#mermaid-svg-dYAHGu9EDWp1xyzW .image-shape .label,#mermaid-svg-dYAHGu9EDWp1xyzW .icon-shape .label{text-anchor:middle;}#mermaid-svg-dYAHGu9EDWp1xyzW .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-dYAHGu9EDWp1xyzW .rough-node .label,#mermaid-svg-dYAHGu9EDWp1xyzW .node .label,#mermaid-svg-dYAHGu9EDWp1xyzW .image-shape .label,#mermaid-svg-dYAHGu9EDWp1xyzW .icon-shape .label{text-align:center;}#mermaid-svg-dYAHGu9EDWp1xyzW .node.clickable{cursor:pointer;}#mermaid-svg-dYAHGu9EDWp1xyzW .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-dYAHGu9EDWp1xyzW .arrowheadPath{fill:#333333;}#mermaid-svg-dYAHGu9EDWp1xyzW .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-dYAHGu9EDWp1xyzW .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-dYAHGu9EDWp1xyzW .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-dYAHGu9EDWp1xyzW .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-dYAHGu9EDWp1xyzW .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-dYAHGu9EDWp1xyzW .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-dYAHGu9EDWp1xyzW .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-dYAHGu9EDWp1xyzW .cluster text{fill:#333;}#mermaid-svg-dYAHGu9EDWp1xyzW .cluster span{color:#333;}#mermaid-svg-dYAHGu9EDWp1xyzW div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-dYAHGu9EDWp1xyzW .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-dYAHGu9EDWp1xyzW rect.text{fill:none;stroke-width:0;}#mermaid-svg-dYAHGu9EDWp1xyzW .icon-shape,#mermaid-svg-dYAHGu9EDWp1xyzW .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-dYAHGu9EDWp1xyzW .icon-shape p,#mermaid-svg-dYAHGu9EDWp1xyzW .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-dYAHGu9EDWp1xyzW .icon-shape .label rect,#mermaid-svg-dYAHGu9EDWp1xyzW .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-dYAHGu9EDWp1xyzW .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-dYAHGu9EDWp1xyzW .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-dYAHGu9EDWp1xyzW :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Reflection
执行初稿
反思反馈
优化修正
Plan-and-Solve
规划
执行步骤1
执行步骤2
完成
ReAct
思考
行动
观察

对比维度 ReAct Plan-and-Solve Reflection
核心思想 边想边做,动态调整 先规划后执行,严守纪律 自我反思,迭代优化
工作流程 思考→行动→观察→循环 规划阶段→执行阶段 执行→反思→优化→循环
适合场景 需要外部信息、动态交互的任务 结构清晰、可分解的复杂任务 有明确优化路径的创作/编程任务
主要优势 灵活、可解释、能调用外部工具 目标一致、不易跑偏 自我纠错、持续优化
主要劣势 Token消耗大、可能局部最优 缺乏动态调整能力 迭代次数多、成本高
决策时机 运行时动态决策 执行前一次性规划 完成后回顾反思
容错能力 中(靠外部反馈修正) 低(规划出错则全错) 高(通过反思自我修正)
类比 🕵️ 侦探(边查边想) 🏗️ 建筑师(先设计后施工) ✍️ 作家(初稿→修改→定稿)

在实践中如何选择?

场景特征 推荐范式 原因
需要频繁查询外部信息 ReAct 动态适应性最强
任务步骤清晰、可预分解 Plan-and-Solve 目标一致,效率更高
对最终质量要求极高 Reflection 自我纠错,不断优化
任务既有动态交互又需高质量 ReAct + Reflection 先执行后反思,双重保障

六、核心概念速查表(新手友好)

术语 通俗解释
ReAct 一种让AI"边想边做"的范式------思考→行动→观察→再思考......循环往复
Plan-and-Solve 一种"先规划后执行"的范式------先列出完整计划,再一步步执行
Reflection 一种让AI"自我反思"的范式------生成初稿→评审反馈→优化修正→再评审......
Thought(思考) ReAct中AI的"内心独白",分析问题、制定计划
Action(行动) ReAct中AI采取的具体动作,通常是调用一个工具
Observation(观察) 执行Action后从工具返回的结果
工具(Tool) 智能体与外部世界交互的"手脚",如搜索引擎、计算器
工具描述(Tool Description) 用自然语言说明工具的用途,模型据此判断何时使用
规划器(Planner) Plan-and-Solve中负责分解问题、生成计划的组件
执行器(Executor) Plan-and-Solve中负责按计划逐步执行的组件
评审员(Reflector) Reflection中负责审查和反馈的LLM角色
记忆模块(Memory) Reflection中存储"执行-反思"轨迹的短期记忆
最大步数(max_steps) 防止智能体陷入无限循环的安全阀

七、思考题(帮助加深理解)

以下思考题没有标准答案,旨在帮助你建立对不同智能体范式设计哲学的深刻理解。

  1. ReAct范式中的"思考-行动-观察"循环,与人类解决问题的方式有何相似之处? 这种设计为什么能帮助减少大模型的"幻觉"问题?

  2. Plan-and-Solve将"规划"和"执行"解耦,在什么场景下能发挥最大优势? 在什么场景下这种解耦反而可能成为劣势?

  3. Reflection机制中,为什么需要让同一个模型扮演"执行者"和"评审员"两个不同角色? 如果让两个不同的模型分别扮演这两个角色,会发生什么?

  4. 三种范式可以组合使用吗? 如果可以,你会如何设计一个同时结合ReAct、Plan-and-Solve和Reflection优点的混合范式?

  5. "工具描述是智能体机制中最关键的部分"------为什么一段文本描述如此重要? 如果工具描述写得不好,智能体的行为会出现什么问题?

  6. Reflection的迭代循环和ReAct的思考-行动循环,两者在本质上有什么区别? 它们各自解决了什么问题?

参考资料

  1. Datawhale Hello-Agents 第四章《智能体经典范式构建》
    https://datawhalechina.github.io/hello-agents/#/./chapter4/第四章 智能体经典范式构建

关于本文知识来源的说明

本文的核心知识框架完全基于Datawhale《Hello-Agents》教程第四章的内容进行整理和阐述。文中涉及的所有技术概念(ReAct、Plan-and-Solve、Reflection、工具定义、提示词设计等)均为该教程中明确讲解的内容。

ReAct论文(Yao et al., 2022)、Plan-and-Solve论文(Wang et al., 2023)、Reflexion框架(Shinn et al., 2023)等均作为背景知识参考。读者如有兴趣,可通过Google Scholar、arXiv或各学术搜索引擎自行检索相关论文标题进行深入学习。

结语

在这一章中,我们系统学习了三种经典的智能体范式:

  • ReAct 让智能体能够边想边做,通过"思考-行动-观察"的循环动态地与外部世界交互,灵活适应各种变化。
  • Plan-and-Solve 让智能体能够三思而后行,先制定完整的行动计划,再严格执行,确保目标的一致性。
  • Reflection 让智能体能够自我反思,通过"执行-反思-优化"的迭代循环不断提升输出质量。

这三种范式各有侧重,适用于不同的场景。ReAct适合需要动态获取外部信息的任务,Plan-and-Solve适合结构清晰的复杂推理,Reflection适合有明确优化路径的创作类任务。

更重要的是,通过理解这些范式的设计原理,我们明白了:

  • 提示词如何引导模型行为
  • 工具如何扩展模型的能力边界
  • 记忆如何支撑多轮交互
  • 多角色协作如何实现自我纠错

掌握了这些原理,你就拥有了从一个框架的"使用者"转变为智能体应用"创造者"的能力。

本文参考:Datawhale《Hello-Agents》教程第四章《智能体经典范式构建》的内容框架与核心知识点。本文在忠实呈现该教程内容的基础上,为便于新手理解进行了通俗化改写和图表化呈现。

相关推荐
新知图书2 小时前
4.2 北京欢迎您:基于Anthropic的京韵导览Agent实战(智能体工程)
人工智能·agent·ai agent·智能体·智能体工程
特立独行的猫a2 小时前
DeepSeek Harness插件和工具的区别介绍及开发入门指南
前端·ai·agent·插件·deepseek·harness
安逸sgr2 小时前
优化器是什么?SGD、Momentum、Adam 有什么区别?
人工智能·ai·大模型·agent·智能体
mCell5 小时前
AI 时代 SVG 画图的潜力
前端·agent·svg
抱抱宝12 小时前
Agent-study项目教程(03):手写 Mini-ReAct Agent(不依赖框架)
javascript·人工智能·gpt·react.js·prompt·agent
抱抱宝12 小时前
大模型应用开发教程08 | 构建完整 RAG 应用(Chroma/FAISS 实战)
人工智能·gpt·prompt·agent
纯爱掌门人15 小时前
DeepSeek Harness 上手实录:从启动 Web UI 到组装自己的 Agent
agent·deepseek
纯爱掌门人15 小时前
给 DeepSeek Harness 开发功能:别急着写 Tool,先找对扩展层
agent·deepseek
JaydenAI15 小时前
[基于OpenEvals的自动化评估-10]针对Agent对话的评估[上篇]
ai·langchain·agent·evaluation·openevals