agent利用知识来做规划:《KnowAgent: Knowledge-Augmented Planning for LLM-Based Agents》笔记

news2024/9/20 7:47:12

文章目录

    • 简介
    • KnowAgent思路
      • 准备知识
      • Action Knowledge的定义
      • Planning Path Generation with Action Knowledge
      • Planning Path Refinement via Knowledgeable Self-Learning
      • KnowAgent的实验结果
    • 总结
    • 参考资料

简介

《KnowAgent: Knowledge-Augmented Planning for LLM-Based Agents》是2024年03月出的一篇论文。

论文要解决的问题:LLM与环境交互生成执行动作时的规划幻觉(planning hallucination),即模型会生成不必要的或者冲突的动作序列。如"attempting to look up information without performing a search operation"或"trying to pick an apple from a table without verifying the presence of both the table and the apple"

下图是KnowAgent的概览图。

在这里插入图片描述

knowAgent的框架如下图,后面的动图(来自论文GitHub)演示了knowAgent框架的步骤示意。

在这里插入图片描述

在这里插入图片描述

KnowAgent思路

准备知识

KnowAgent是在ReAct提出的规划轨迹格式的基础上来训练和评估的。

如果用数学语言来定义ReAct,轨迹 τ \tau τ由Thought-Action-Observation三元组( T , A , O \mathcal{T},\mathcal{A},\mathcal{O} T,A,O)表示,其中 T \mathcal{T} T表示agent的想法, A \mathcal{A} A表示可执行动作, O \mathcal{O} O表示从环境获得的反馈信息。

在时刻t的历史轨迹为:
H t = ( T 0 , A 0 , O 0 , T 1 , ⋯   , T t − 1 , A t − 1 , O t − 1 ) \mathcal{H}_t = (\mathcal{T}_0, \mathcal{A}_0, \mathcal{O}_0, \mathcal{T}_1, \cdots,\mathcal{T}_{t-1}, \mathcal{A}_{t-1}, \mathcal{O}_{t-1}) Ht=(T0,A0,O0,T1,,Tt1,At1,Ot1)
基于历史轨迹,agent将生成新的想法和动作。给定参数为 θ \theta θ的模型agent π \pi π,根据历史轨迹生成 T t \mathcal{T}_t Tt可表示为下式,式中的 T t i \mathcal{T}_t^i Tti ∣ T t ∣ |\mathcal{T}_t| Tt分别是 T t \mathcal{T}_t Tt的第i个token及长度。
p ( T t ∣ H t ) = ∏ i = 1 ∣ T t ∣ π θ ( T t i ∣ H t , T t < i ) p\left(\mathcal{T}_t \mid \mathcal{H}_t\right)=\prod_{i=1}^{\left|\mathcal{T}_t\right|} \pi_\theta\left(\mathcal{T}_t^i \mid \mathcal{H}_t, \mathcal{T}_t^{<i}\right) p(TtHt)=i=1Ttπθ(TtiHt,Tt<i)
接着,动作 A t \mathcal{A}_t At将由 T t \mathcal{T}_t Tt H t \mathcal{H}_t Ht来决定,式中的 A t j \mathcal{A}_t^j Atj ∣ A t ∣ |\mathcal{A}_t| At分别是 A t \mathcal{A}_t At的第j个token及长度:
p ( A t ∣ H t , T t ) = ∏ j = 1 ∣ A t ∣ π θ ( A t j ∣ H t , T t , A t < j ) p\left(\mathcal{A}_t \mid \mathcal{H}_t, \mathcal{T}_t\right)=\prod_{j=1}^{\left|\mathcal{A}_t\right|} \pi_\theta\left(\mathcal{A}_t^j \mid \mathcal{H}_t, \mathcal{T}_t, \mathcal{A}_t^{<j}\right) p(AtHt,Tt)=j=1Atπθ(AtjHt,Tt,At<j)
最后,动作 A t \mathcal{A}_t At的得到的反馈结果被当做观察 O \mathcal{O} O并添加到轨迹中得到 H t + 1 \mathcal{H}_{t+1} Ht+1

注:在论文后面将动作集称为 E a E_a Ea,里面的动作 a i a_i ai A i \mathcal{A}_i Ai是一样的。

Action Knowledge的定义

动作Action E a = a 1 , ⋯   , a N − 1 E_a = {a_1, \cdots, a_{N-1}} Ea=a1,,aN1表示动作集合,LLM为了完成特定任务需要执行的离散动作。

动作规则Action Rules R = r 1 , ⋯   , r N − 1 \mathcal{R} = {r_1, \cdots, r_{N-1}} R=r1,,rN1定义了动作转换的逻辑和顺序。 r k : a i → a j r_k: a_i \rightarrow a_j rk:aiaj 定义了可行的动作转换。

动作知识Action Knowledge:表示为 ( E a , R ) (E_a, \mathcal{R}) (Ea,R),由动作集合 E a E_a Ea和规则集 R \mathcal{R} R组成,不同任务的动作知识构成了动作知识库(Action KB)

提取动作知识的策略:人工构建耗时且费力,所以使用GPT-4进行初始构建后进行人工校正。

在这里插入图片描述

Planning Path Generation with Action Knowledge

使用动作知识来规划路径生成的第一步是将动作知识转换成文本(Action knowledge to text),比如Search: (Search, Retrieve, Lookup, Finish), 表示Search后面的动作可以是Search, Retrieve, Lookup, Finish中的任一个。

第二步是根据动作知识来进行路径生成(Path Generation), 作者们设计了一个如上面图片右侧的prompt,prompt由四部分构成:

  1. 动作知识库的概述来定义基本概念和规则
  2. 定义每一个动作的含义、操作详情
  3. 定义规划路径生成的原则,用来约束输出过程
  4. 提供几个实际规划路径的例子

在HotpotQA上使用的prompt举例(Table 4):

"""
Your task is to answer a question using a specific graph-based method. You must navigate from the "Start" node to the "Finish" node by following the paths outlined in the graph. The correct path is a series of actions that will lead you to the answer.
The decision graph is constructed upon a set of principles known as "Action Knowledge", outlined as follows: 
	Start:(Search, Retrieve)
	Retrieve:(Retrieve, Search, Lookup, Finish) 
	Search:(Search, Retrieve, Lookup, Finish)
	Lookup:(Lookup, Search, Retrieve, Finish)
	Finish:() 
Here's how to interpret the graph's Action Knowledge: 
	From "Start", you can initiate with either a "Search" or a "Retrieve" action. 
	At the "Retrieve" node, you have the options to persist with "Retrieve", shift to "Search", experiment with "Lookup", or advance to "Finish". 
	At the "Search" node, you can repeat "Search", switch to "Retrieve" or "Lookup", or proceed to "Finish". 
	At the "Lookup" node, you have the choice to keep using "Lookup", switch to "Search" or "Retrieve", or complete the task by going to "Finish". 
	The "Finish" node is the final action where you provide the answer and the task is completed. Each node action is defined as follows: 
	(1) Retrieve[entity]: Retrieve the exact entity on Wikipedia and return the first paragraph if it exists. If not, return some similar entities for searching. 
	(2) Search[topic]: Use Bing Search to find relevant information on a specified topic, question, or term.
  (3) Lookup[keyword]: Return the next sentence that contains the keyword in the last passage successfully found by Search or Retrieve. 
  (4) Finish[answer]: Return the answer and conclude the task. 
As you solve the question using the above graph structure, interleave ActionPath, Thought, Action, and Observation steps. ActionPath documents the sequence of nodes you have traversed within the graph. Thought analyzes the current node to reveal potential next steps and reasons for the current situation. 
You may take as many steps as necessary.
Here are some examples:
{examples}
(END OF EXAMPLES)
Question: {question}{scratchpad}

"""

论文在ALFWorld 上执行Pick任务使用的prompt举例(Table 5):

"""
Interact with a household to solve a task by following the structured "Action Knowledge". The guidelines are: 
Goto(receptacle) -> Open(receptacle)
[Goto(receptacle), Open(receptacle)] -> Take(object, from: receptacle) 
Take(object, from: receptacle) -> Goto(receptacle) 
[Goto(receptacle), Take(object, from: receptacle)] -> Put(object, in/on: receptacle) 

Here's how to interpret the Action Knowledge:
Before you open a receptacle, you must first go to it. This rule applies when the receptacle is closed. To take an object from a receptacle, you either need to be at the receptacle's location, or if it's closed, you need to open it first. 
Before you go to the new receptacle where the object is to be placed, you should take it. Putting an object in or on a receptacle can follow either going to the location of the receptacle or after taking an object with you.

The actions are as follows:
1) go to receptacle
2) take object from receptacle 
3) put object in/on receptacle 
4) open receptacle

As you tackle the question with Action Knowledge, utilize both the ActionPath and Think steps. ActionPath records the series of actions you've taken, and the Think step understands the current situation and guides your next moves. 
Here are two examples. 
{examples} 
Here is the task.
"""

路径(path)和轨迹(trajectory)的区别如下:

  • 路径是指agent采取的一系列动作

  • 轨迹包括模型在解决问题过程中的完整输出,所以路径是轨迹的一部分。

如果像在准备知识一样用数学语言来定义knowAgent,轨迹 τ \tau τ由四元组( P , T , A , O \mathcal{P},\mathcal{T},\mathcal{A},\mathcal{O} P,T,A,O)表示,其中 P \mathcal{P} P表示动作路径, T \mathcal{T} T表示agent的想法, A \mathcal{A} A表示可执行动作, O \mathcal{O} O表示从环境获得的反馈信息。在时刻t的历史轨迹为:
H t = ( P 0 , T 0 , A 0 , O 0 , ⋯   , P t − 1 , T t − 1 , A t − 1 , O t − 1 ) \mathcal{H}_t = (\mathcal{P}_0,\mathcal{T}_0, \mathcal{A}_0, \mathcal{O}_0, \cdots,\mathcal{P}_{t-1},\mathcal{T}_{t-1}, \mathcal{A}_{t-1}, \mathcal{O}_{t-1}) Ht=(P0,T0,A0,O0,,Pt1,Tt1,At1,Ot1)
基于历史轨迹,agent将生成新的动作路径、想法和动作。给定参数为 θ \theta θ的模型agent π \pi π,根据历史轨迹生成接下来的动作路径 P t \mathcal{P}_t Pt可表示为下式,式中的 P t k \mathcal{P}_t^k Ptk ∣ P t ∣ |\mathcal{P}_t| Pt分别是 P t \mathcal{P}_t Pt的第k个token及长度。
p ( P t ∣ H t ) = ∏ k = 1 ∣ P t ∣ π θ ( P t k ∣ H t , P t < k ) p\left(\mathcal{P}_t \mid \mathcal{H}_t\right)=\prod_{k=1}^{\left|\mathcal{P}_t\right|} \pi_\theta\left(\mathcal{P}_t^k \mid \mathcal{H}_t, \mathcal{P}_t^{<k}\right) p(PtHt)=k=1Ptπθ(PtkHt,Pt<k)
与前面准备知识中提到的React思路一样,后续想法和动作的生成可以表示为下面的式子:
p ( T t ∣ H t , P t ) = ∏ i = 1 ∣ T t ∣ π θ ( T t i ∣ H t , P t , T t < i ) p ( A t ∣ H t , P t , T t ) = ∏ j = 1 ∣ A t ∣ π θ ( A t j ∣ H t , P t , T t , A t < j ) p\left(\mathcal{T}_t \mid \mathcal{H}_t, \mathcal{P}_t\right)=\prod_{i=1}^{\left|\mathcal{T}_t\right|} \pi_\theta\left(\mathcal{T}_t^i \mid \mathcal{H}_t, \mathcal{P}_t, \mathcal{T}_t^{<i}\right) \\ p\left(\mathcal{A}_t \mid \mathcal{H}_t, \mathcal{P}_t, \mathcal{T}_t\right)=\prod_{j=1}^{\left|\mathcal{A}_t\right|} \pi_\theta\left(\mathcal{A}_t^j \mid \mathcal{H}_t,\mathcal{P}_t, \mathcal{T}_t, \mathcal{A}_t^{<j}\right) p(TtHt,Pt)=i=1Ttπθ(TtiHt,Pt,Tt<i)p(AtHt,Pt,Tt)=j=1Atπθ(AtjHt,Pt,Tt,At<j)

Planning Path Refinement via Knowledgeable Self-Learning

Knowledgeable Self-Learning的目标是通过迭代微调使得模型更好的理解动作知识,其算法如下图所示:

在这里插入图片描述

具体来说,算法过程如下:

  1. Knowledgeable Self-Learning的输入为初始训练集 D 0 D_0 D0、动作知识 A K m AK_m AKm、未训练模型 M 0 M_0 M0,由模型生成初始轨迹集合 T 0 = { τ 1 , τ 2 , ⋯   , τ n } T_0=\{\tau_1, \tau_2, \cdots, \tau_n\} T0={τ1,τ2,,τn},将 T 0 T_0 T0过滤后微调模型 M 0 M_0 M0后得到模型 M 1 M_1 M1​。

  2. 模型 M 1 M_1 M1 D 0 D_0 D0上评估得到新的轨迹集合 T 1 = { τ 1 ′ , τ 2 ′ , ⋯   , τ n ′ } T_1=\{\tau_1^{\prime}, \tau_2^{\prime}, \cdots, \tau_n^{\prime}\} T1={τ1,τ2,,τn}, 将 T 1 T_1 T1 T 0 T_0 T0经过滤和合并(merging)操作后用来微调模型 M 1 M_1 M1后得到模型 M 2 M_2 M2

  3. 一直重复第二步直到模型在测试集 D t e s t D_{test} Dtest上的提升变得非常小。

其中,

  • 过滤Filtering:先根据生成结果选择正确的轨迹 T c o r r e c t T_{correct} Tcorrect,然后根据动作知识库 A K m AK_m AKm​来去掉未与其对齐的轨迹,主要是invalid动作和misordered的动作序列。
    • invalid动作是指不符合动作规则的动作
    • misordered序列是指动作的逻辑顺序与动作知识库不一样
  • 合并merging:合并不同迭代轮次里的轨迹,对于解决同一任务的多条轨迹,保留更高效(更短)的轨迹。

KnowAgent的实验结果

在HotpotQA和ALFWorld上来评估KnowAgent,使用Llama2-{7,13,70}b-chat模型作为基础模型,同时测试了Vicuna和Mistral模型的效果。

与KnowAgent比较的基准有:CoT、ReAct、Reflexion、FiReAct。结果如下图

在这里插入图片描述

错误分析:knowagent难以有效蒸馏关键信息,经常无法给出准确回复。主要原因在于处理长上下文窗口时推理能力和记忆能力的不足。

总结

knowAgent在ReAct的基础上新增了路径(path)概念,通过构建一个动作知识库来指导agent更好的规划任务,减少规划幻觉(planning hallucination)。个人觉得动作知识库的引入与RAG减少幻觉的思路是类似的,knowAgent复杂的prompt也是方法不可忽视的一点。

knowAgent另一个很重要的思路是自学习,使用迭代的思路不断微调模型使模型更好的理解动作知识。

论文中的几个数学公式主要是用来表示生成过程的,即使不理解公式也没有关系,个人觉得即使论文中不添加那些公式表示也不影响思路的完整性。

参考资料

  1. Zhu, Yuqi, Shuofei Qiao, Yixin Ou, Shumin Deng, Ningyu Zhang, Shiwei Lyu, Yue Shen, et al. n.d. “KnowAgent: Knowledge-Augmented Planning for LLM-Based Agents.”
  2. KnowAgent github

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1546683.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

摆扫式(whisk broom)和推扫式(push broom)卫星传感器介绍

目前&#xff0c;我们卫星传感器主要有两大类型&#xff1a;摆扫式&#xff08;whisk broom&#xff09;和推扫式&#xff08;push broom&#xff09;。为了更好的理解和使用卫星影像数据&#xff0c;我们需要简单了解下这两种传感器工作原理。 摆扫式&#xff1a;Whisk Broom…

zabbix进阶

知识点补充 zabbix server在主机上运行服务&#xff0c;端口号为10050&#xff0c;zabbix agent 在被监控机器上运行&#xff08;源码下载&#xff09;主要完成对cpu&#xff0c;磁盘的信息采集&#xff0c;端口号为10051 zabbix 软件结构组成&#xff1a; 1.Zabbix Web GUI …

城市内涝水文水动力模型:慧天【HTWATER】

查看详情>>> 城市内涝水文水动力模型&#xff1a;慧天【HTWATER】 【城市内涝水文水动力模型介绍】 慧天排水数字化分析平台针对城市排水系统基础设施数据管理的需求&#xff0c;以及水文、水力及水质模拟对数据的需求&#xff0c;实现了以数据库方式对相应数据的存…

兼职副业大揭秘:六个潜力满满的赚钱途径

亲爱的朋友&#xff0c;你对兼职副业充满好奇与期待&#xff0c;这非常好&#xff01;在此&#xff0c;我将为你分享一些能够助你赚取额外收入的兼职副业建议。以下是六个颇具潜力的兼职副业方向&#xff0c;希望能为你的探索之路提供些许启发。 1&#xff0c;网络调查与市场洞…

C++ 动态规划

文章目录 一、简介二、举个栗子2.1斐波那契数列2.2最短路径&#xff08;DFS&#xff09; 参考资料 一、简介 感觉动态规划非常的实用&#xff0c;因此这里整理一下相关资料。动态规划&#xff08;Dynamic Programming&#xff09;&#xff1a;简称 DP&#xff0c;是一种优化算法…

后端常问面经之Java基础

基本数据类型 Java中有8种基本数据类型&#xff1a; 6种数字类型&#xff1a; 4种整数型&#xff1a;byte、short、int、long 2种浮点型&#xff1a;float、double 1种字符类型&#xff1a;char 1种布尔类型&#xff1a;boolean 数据类型的默认值以及所占空间如下&#x…

C++ STL - 优先级队列及其模拟实现

目录 0. 引言 1. priority_queue 介绍 1.1 构造函数 1.2 priority_queue 接口函数使用 1.3 仿函数 1.4 题目练习 2. priority_queue 模拟实现 2.1基本框架&#xff1a; 2.2 默认构造函数 2.3 基本函数 2.4 堆的向上以及向下调整 0. 引言 优先队列 (priority_queu…

Flask python :logging日志功能使用

logging日志的使用 一、了解flask日志1.1、Loggers记录器1.2、Handlers 处理器1.3、Formatters 格式化器 二、使用日志2.1、官网上的一个简单的示例2.2、基本配置2.3、具体使用示例2.4、运行 三、写在最后 一、了解flask日志 日志是一种非常重要的工具&#xff0c;可以帮助开发…

[技术杂谈]解决windows上出现文件名太长错误

最近执行python setup.py install总是失败&#xff0c;提示文件名太长发现网上有取消限制文件名长度&#xff0c;测试发现改完注册表无需重启cmd就生效了。但是有时候会失败&#xff0c;现在方法放这。 转到Windows“开始”&#xff0c;然后键入REGEDIT。选择注册表编辑器 选…

Linux内核中的进程调度-进程调度基础

前言 一、进程的概念 1.概述 2.ps和top命令 3.总结 二、进程的生命周期 1.进程状态文字描述 2.进程状态程序中的体现 3.进程状态的切换 三、task_struct数据结构简述 1.数据结构成员简述 2.需要注意的成员&#xff1a; 3.进程优先级 ①、优先级的代码表示 ②、Linux内核下的进…

蓝桥杯2023真题-幸运数字

目录 进制转换&#xff1a; 思路 代码 题目链接&#xff1a; 0幸运数字 - 蓝桥云课 (lanqiao.cn) 本题就考的进制转换问题&#xff0c;要将十进制5转换成二进制&#xff0c;通过%2,和/2的交替使用即可完成&#xff0c;所得余数就是转换成的二进制各位的值&#xff0c;转换…

浅谈如何自我实现一个消息队列服务器(3)—— 细节分析

文章目录 2.2 消息存储在文件时涉及到的流对象2.3 序列化、反序列化的方法2.3.1 JSON的ObjectMapper2.3.2 ObjectOutputStream 、 ObjectInputStream2.3.3 第三方库的Hessian2.3.4 protobuffer2.3.5 thrift 2.4 使用类MessageFileManager封装文件存储操作2.4.1 sendMessage()实…

ubuntu20.04云服务器安装LXDE轻量级桌面和XRDP远程连接工具

云服务器一般都是安装命令行系统&#xff0c;用SSH连接&#xff0c;但是有时我们需要桌面来做更好的管理。 首先我们明确一下需要的东西。 一个桌面系统&#xff1a;LXDE&#xff08;最轻量级桌面&#xff09;&#xff0c;为了节省资源&#xff0c;我们只要功能够用就行。一个…

[套路] 浏览器引入Vue.js场景-WangEditor富文本编辑器的使用 (永久免费)

系列文章目录 [套路] el-table 多选属性实现单选效果[套路] 基于服务内存实现的中文拼音混合查询[套路] Bypass滑块验证码 目录 系列文章目录前言一、实现1.1 场景1.2 Window对象简介1.3 引入WangEditor1.4 页面配置 前言 公司使用freemarker的老旧SpringBootWeb后台项目, 前…

【蓝桥杯】填空题技巧|巧用编译器|用Python处理大数和字符|心算手数|思维题

目录 一、填空题 1.巧用编译器 2.巧用Excel 3. 用Python处理大数 4.用Python处理字符 5.心算手数 二、思维题 推荐 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。【点击跳转到网站】 一、填空题 …

Python编程入门:环境搭建与基础语法

目录 1. 引言 2. Python环境搭建 3. Python基础语法 3.1. 变量与数据类型 3.2. 运算符与表达式 3.3. 控制结构&#xff1a;条件语句与循环 3.4. 函数定义与使用 3.5. 输入与输出 3.6. 列表操作 4. 总结 1. 引言 Python作为一种简洁易学、功能强大的编程语言&#xff…

hadoop伪分布式环境启动时web端访问不到

在搭建hadoop伪分布式环境时&#xff0c;开启hdfs-site.sh后&#xff0c;web端访问不到&#xff0c;但是节点已经正常开启&#xff1a; 在尝试关闭防火墙后也没有效果&#xff0c;后来在/etc/hosts文件中加入本机的ip和主机名映射后&#xff0c;重新初始化namenode&#xff0c;…

电脑桌面记事本便签软件,记事本软件哪个好用

正在电脑前忙碌工作&#xff0c;突然想起今晚有个重要的会议&#xff0c;或者是明天有一个重要的任务需要完成&#xff0c;但是手头的工作又无法让你离开电脑&#xff0c;这时候&#xff0c;你多么希望有一个便捷的电脑桌面记事本便签软件&#xff0c;可以让你快速记录下这些重…

2016年认证杯SPSSPRO杯数学建模D题(第二阶段)NBA是否有必要设立四分线全过程文档及程序

2016年认证杯SPSSPRO杯数学建模 D题 NBA是否有必要设立四分线 原题再现&#xff1a; NBA 联盟从 1946 年成立到今天&#xff0c;一路上经历过无数次规则上的变迁。有顺应民意、皆大欢喜的&#xff0c;比如 1973 年在技术统计中增加了抢断和盖帽数据&#xff1b;有应运而生、力…

软件测试/测试开发丨Docker环境安装配置(Mac、Windows、Ubuntu)

macOS 安装 Docker brew cask install docker运行 Docker Ubuntu 安装 Docker # 更新 apt update # 安装依赖 apt install apt-transport-https ca-certificates curl software-properties-common -y # 添加 key curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/…