当产品经理谈到用LLM Agent构建新一代智能体的时候,他们在说什么?
什么是Agent
大型语言模型(LLM)的推理能力确实厉害,能读输入、做分析、输出文本、代码甚至媒体内容——这点大家都不陌生。但要说它像人类一样能规划、会思考、能调用工具跟物理世界互动,还自带记忆系统?抱歉,目前还真做不到。

举个例子:公司里同事A想知道自己还剩多少年假。单靠LLM,它没法给出答案——因为它根本连企业内部系统都碰不到。可要是能让LLM识别出“查询剩余年假”这个意图,从中抽取出同事A的信息,再调用业务系统的接口把数据拉回来,那就非常实用了。这,就是“Agent”的核心思路。
说得直白点,Agent是一种把LLM的推理能力和外部工具调用能力搭在一起的应用形态,专门用来搞定那些相对复杂的任务。
打个比方:Agent接到一个任务,它拿LLM当“大脑”或“思考引擎”,靠这个大脑决定每一步该怎么走。你可以把Agent想象成一位有战略眼光的指挥官——它不仅清楚战场上每个单元的能力,还能高效地协调它们去完成更复杂的作战目标。
哪些业务场景可以使用Agent
如果你的业务场景满足下面两个条件,采用Agent架构会非常合适:
- 业务流程需要多步骤执行,涉及复杂的流程编排。
- 问题可以被拆成多个子模块,每个模块都有清晰的输入、输出和功能,而且能明确判断是否完成了目标。
Agent架构流程
Agent的根基是LLM的推理能力。它先由LLM做出规划(Planning),然后动用工具去执行(Action),再观察执行结果(Observation)——这个闭环反复运行,直到任务落地。
ReAct
目前主流的Agent对话实现框架叫ReAct,是普林斯顿大学和Google在2022年提出的提示词方法。它最巧妙的地方在于把“思考”和“行动”融合到了一起。框架的演变历史可以参考下图:
- :典型的“思维链”方法。为了鼓励模型一步步推理,它在问题前加一句“Let’s think step by step”,而不是直接给答案。但问题也很明显——只专注内部推导,不跟外部世界交互,很容易基于错误或过时的信息瞎琢磨。
Reason Only
- :反过来,它直接通过单步行动来获取观察结果。短板是行动太快,缺乏充分思考,最后输出很可能不是用户真正想要的。
Act-Only
- :把思考和行动结合起来。系统先思考,然后执行动作,把反馈拿回来再接着思考——这个循环一直重复,直到得出最终答案。
ReAct
2023年又推出了一个新框架——自我反思(Reflexion),在ReAct的基础上增加了反思环节。具体细节看下图:
下面放一个ReAct论文里用到的例子:
案例讲解
ReAct的提示词长这样:
Answer the following questions as best you can. If it is in order, you can use some tools appropriately. You ha ve access to the following tools:
{tools}
Use the following format:
Question: the input question you must answer1
Thought: you should always think about what to do and what tools to use.
Action: the action to take, should be one of {toool_names}
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can be repeated zero or more times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
history: {history}
Question: {input}
Thought: {agent_scratchpad}
其中agent_scratchpad是Agent的思维记录,代表中间action和observation的过程,会被格式化成 """Observation: {observation}Thought:{action}""" 这样。
假设我们手头有:
- :“目前的黄金价格是多少?如果我想在这个价格上加价20%,我应该怎么定价?”
用户提问
- :
工具库
google-search(用谷歌搜索网络信息)和llm-calc(用大模型+Python做数学运算)。
那么第一轮对话的输入是:
Answer the following questions as best you can. If it is in order, you can use some tools appropriately. You ha ve access to the following tools:
google-search: 用谷歌Search搜索网络开源信息的工具
llm-calc: 用大模型和Python做数学运算的工具
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do and what tools to use.
Action: the action to take, should be one of [google-search, llm-calc]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can be repeated zero or more times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
history:
Question: 目前的黄金价格是多少?如果我想在这个价格上加价20%,我应该怎么定价?
Thought:
模型输出后解析,拿到Thought、Action和Action Input:
Thought: 我应该使用搜索工具来查找黄金的当前市场价格。
Action: google-search
Action Input: 黄金当前价格
调用google-search工具,输入“黄金当前价格”,拿到返回结果Observation:“根据网络资料显示,每克黄金的价格为60美元。” 然后把上面这些内容整理好,塞回ReAct提示词模板,开启第二轮对话的输入:
Answer the following questions as best you can. If it is in order, you can use some tools appropriately. You ha ve access to the following tools:
google-search: 用谷歌Search搜索网络开源信息的工具
llm-calc: 用大模型和Python做数学运算的工具
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do and what tools to use.
Action: the action to take, should be one of [google-search, llm-calc]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can be repeated zero or more times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
history:
Question: 目前的黄金价格是多少?如果我想在这个价格上加价20%,我应该怎么定价?
Thought: 我应该使用搜索工具来查找答案,这样我可以快速地找到所需的信息。
Action: google-search
Action Input: 黄金当前价格
Observation: 根据网络资料显示,每克黄金的价格为60美元。
Thought:
再次解析输出:
Thought: 我需要计算在这个价格基础上加价20%的新价格是多少。
Action: llm-calc
Action Input: 60*1.20
调用llm-calc工具,输入60*1.20,拿到Observation:“72”。然后继续整理,启动第三轮对话:
Answer the following questions as best you can. If it is in order, you can use some tools appropriately. You ha ve access to the following tools:
google-search: 用谷歌Search搜索网络开源信息的工具
llm-calc: 用大模型和Python做数学运算的工具
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do and what tools to use.
Action: the action to take, should be one of [google-search, llm-calc]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can be repeated zero or more times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
history:
Question: 目前的黄金价格是多少?如果我想在这个价格上加价20%,我应该怎么定价?
Thought: 我应该使用搜索工具来查找答案,这样我可以快速地找到所需的信息。
Action: google-search
Action Input: 黄金当前价格
Observation: 根据网络资料显示,每克黄金的价格为60美元。
Thought: 我需要计算在这个价格基础上加价20%的新价格是多少。
Action: llm-calc
Action Input: 60*1.20
Observation: 72
Thought:
第三次解析输出:
Thought: 我知道最终答案了。
Final Answer: 如果想在当前价格上加价20%卖出黄金,应该定价为每克72美元。 -
- 关于宇宙的好的网名有哪些
- 角色扮演 | 1
- 网名