解密Prompt系列31. LLM Agent之从经验中不断学习的智能体

前言

Agent智能体的工作流可以简单分成两种:一种是固定的静态工作流,一种是智能体自主决策的动态工作流

静态流程的Agent举几个例子,例如新闻热点追踪推送Agent,每日新论文摘要总结Agent,它们的优点是可控,稳定,可复现,缺点是一种流程基本只能固定适配一种场景,就像工厂的流水线。

而动态流程的Agent,也叫自主智能体,例如AutoGPT,BabyAgent,它们自主感知环境,基于观测进行决策,并做出行动,然后基于行动结果进行反思,并给出下一步行动。优点自然是’理论上’可以泛化到任意场景,不需要基于经验的预置工作流的抽象,但缺点就是不可控,不稳定,不能复现,且任务完成率有限,尤其是在非通用的垂直领域。

影响自主智能体在垂直领域任务完成率的有以下2个亟待解决的问题

  • 模型自主能力进化:失败是成功之母,模型该如何基于失败的任务流进行反思和探索,一步步提高自己的任务完成率呢?
  • 模型自主能力获得:最初模型如何掌握该领域的技能,之前的方案多数是依赖SFT,通过人工,或者人工+模型来构建领域样本来教会模型部分能力。说白了还是人手把手教模型。那这一步能否自主化让模型在trial and error里面自主进行学习呢?毕竟人类也是靠实验和探索一步步掌握新的技能的。

其实以上两个问题都可以通过Self-Reflection from past experience来解决,那问题就转变成了如何获得past-experience,past-experience如何转化成经验,如何在新的推理中使用这些经验。这一章会介绍三个模型自主探索学习和经验总结的方案分别是:AppAgent,Trial and Error和AutoGuide

使用多模态大模型和SOM页面元素分割来识别每一步模型和页面的哪些元素进行交互。而自主学习的部分,论文基于模型的前期自主探索,来构建工具说明书,帮助模型了解每款APP的使用,从而提高推理阶段的任务完成率。这里论文在9个android app上进行了测试,一些测试任务如下

image

那如何使用模型来自主生成APP操作说明书呢?类比人类在使用一个新工具时通过Trial and Error来不断更新自己对工具的认知和使用方式,这里的模型探索也是如此。论文先生成了一组基于APP的任务指令,然后基于每个指令模型会对APP的使用进行自主探索,每一步模型的输入包括

  • 手机交互的4种功能的功能介绍:包括点击、键入、长按、左右滑动
  • 任务描述
  • 历史的交互行为的总结
  • 当前手机应用页面的截图

每一步模型的输出包括,如下图

  • Thought:完成任务下一步做啥
  • Action:使用以上哪个功能的Function Calling或者FINISH
  • Summary:加入最新的Action,对所有历史行为进行总结,作为下一步的输入

image

APP操作的具体prompt(省略细节)如下:

self_explore_task_template = """You are an agent that is trained to complete certain tasks on a smartphone. You will be 
given a screenshot of a smartphone app. The interactive UI elements on the screenshot are labeled with numeric tags 
starting from 1. 

You can call the following functions to interact with those labeled elements to control the smartphone:

1. tap(element: int)
功能介绍。。。

2. text(text_input: str)
功能介绍。。。

3. long_press(element: int)
功能介绍。。。

4. swipe(element: int, direction: str, dist: str)
功能介绍。。。

The task you need to complete is to <task_description>. Your past actions to proceed with this task are summarized as 
follows: <last_act>
Now, given the following labeled screenshot, you need to think and call the function needed to proceed with the task. 
Your output should include three parts in the given format:
Observation: <Describe what you observe in the image>
Thought: <To complete the given task, what is the next step I should do>
Action: <The function call with the correct parameters to proceed with the task. If you believe the task is completed or 
there is nothing to be done, you should output FINISH. You cannot output anything else except a function call or FINISH 
in this field.>
Summary: <Summarize your past actions along with your latest action in one or two sentences. Do not include the numeric 
tag in your summary>
You can only take one action at a time, so please directly call the function."""

然后基于以上模型自主探索生成的行为序列,我们可以记录每一步操作前后,收集页面的变化,并基于变化让大模型总结,该操作步骤究竟是干什么的,从而生成APP中每个按钮的交互说明书。以下是点击类操作的说明书prompt,如果一个按钮被使用多次,则模型会不断更新该按钮的说明文档。

tap_doc_template = """I will give you the screenshot of a mobile app before and after tapping the UI element labeled 
with the number <ui_element> on the screen. The numeric tag of each element is located at the center of the element. 
Tapping this UI element is a necessary part of proceeding with a larger task, which is to <task_desc>. Your task is to 
describe the functionality of the UI element concisely in one or two sentences. Notice that your description of the UI 
element should focus on the general function. For example, if the UI element is used to navigate to the chat window 
with John, your description should not include the name of the specific person. Just say: "Tapping this area will 
navigate the user to the chat window". Never include the numeric tag of the UI element in your description. You can use 
pronouns such as "the UI element" to refer to the element."""

这样基于前期的模型探索我们可以得到每个APP上各种按钮的一份操作说明书。然后在推理阶段,模型会同时使用当前手机界面的UI+前期生成的说明书+5种交互行为说明+历史操作,来生成下一步的交互操作。

论文验证了,前期自主探索形成的说明书,对模型的任务完成准确率有很大的提升,几乎可以逼近基于人工探索形成的说明书(Watching Demos),以及直接手工编写说明书(Manually Crafted)的水平。

image

上面APPAgent帮助模型自我学习如何进行前端交互,微软提出的STE是针对后端API交互,让模型通过前期的多轮API交互学习API调用,并通过In-Context-Learning或者SFT使用前期探索的结果帮助模型更好的使用API来完成任务。

image

这里STE使用了BmTools的API作为工具池,前期的工具探索阶段分成以下3个步骤

  1. Query生成:基于工具名称和工具描述,让模型生成一条能使用该API回答的问题。prompt指令如下
Your task is to answer the user's query as best you can. You have access to the following tools which you can use via API call to help with your response:

{api_descriptions}

Now you have the chance to explore the available APIs. You can do this by 1) synthesizing some natural user query that calling the API could help, and 2) trying to respond to the user query with the help of the APIs. Here, you can focus on queries that only require calling the API once.

Now, first input your synthesized user query. You should make the query natural - for example, try to avoid using the provided API descriptions or API names in the query, as the user does not know what APIs you have access to. Also try to make the query as specific as possible. Input just the user query alone; do NOT solve the query for now.

User Query:

2. 工具调用推理:基于以上生成的Query+工具描述,模型使用ReACT范式来生成工具调用语句。把推理语句解析成API调用后,调用API并获取返回值,然后让模型基于返回进行反思。这一步可以最多重复4次,直到模型判断API调用结果可以回答用户提问,并且每次都会使用之前N-1次的推理结果和观测作为上文,也就是上图中的Short-Memory部分,来帮助模型从错误中进行迭代和优化。这里论文使用ChatGPT,prompt如下

Now, try to respond to the query using the available APIs.

The format you use the API is by specifying 1) Action: the API function name you'd like to call 2) Action Input: the input parameters of the API call in a json string format. The result of the API call will be returned starting with "Observation:". Remember that you should only perform a SINGLE action at a time, do NOT return a list of multiple actions.

Reminder:
1) the only values that should follow "Action:" are: {api_names}
2) use the following json string format for the API arguments:

Action Input:
{{
    "key_1": "value_1",
    ...
    "key_n": "value_n",
}}

Remember to ALWAYS use the following format:

Thought: you should always think about what to do next
Action: the API function name
Action Input: the input parameters of the API call in json string format
Observation: the return result of the API call. This is what I will provide you with; you do not need to repeat it in your response.
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the response to the user query

Begin! Remember that your response should never start with "Observation:" since that is what I will provide you with. Once you have enough information, please immediately use \nThought: I now know the final answer\nFinal Answer:

User Query (the same you just synthesized): {query}

3. 扩展Query: 这里论文针对每个API会进行15次query生成和尝试,并且为了提高query的多样性,在生成新query时会加入历史已经生成的query和每个query模型是否成功调用工具完成。也就是上图Long-Term Memory的部分,判断query是否成功执行也是使用大模型prompt,这里使用了能力更强的GPT4。

Now you know a bit more about the API. You can synthesize another user query to explore the API a bit further and consolidate your understanding of the API, based on things that you discovered about this API. Again, just input the user query alone; do NOT solve the query for now.

User Query:

每个API会重复15次以上的步骤2和步骤3,并记录每一次尝试的路径,用于训练或者后续的In-Context-Learning。

这里我们只关注ICL的方案,因为泛化性更好,能更快拓展新工具和新场景。和上面APPAgent不同的,这里的ICL不是使用前期探索生成的工具说明书,而是直接使用模型调用工具的历史操作,类似于案例。 当用户有新的提问时,会基于query的Embedding(SentenceBert),召回前期探索阶段中最相似的15个query和最终模型的API调用结果作为推理上文,进行工具推理。

效果上论文对比了多个模型直接进行工具调用推理,使用前期探索的案例作为上文,和构建样本进行SFT的效果。小模型还是需要微调才能获得最高的任务完成率,但GPT4这类能力强的模型,只需要ICL就可以达到很好的任务完成率,以及不论是SFT还是ICL相比BaseLine都有很明显的效果提升。

image

AutoGuide

  • AutoGuide: Automated Generation and Selection of State-Aware Guidelines for Large Language Model Agents

image

对比AppAgent是把经验在APP按钮的操作级别进行总结形成工具说明书,推理时召回当前工具的说明书。STE是直接使用原始经验,推理时召回相关历史经验作为上文,而AutoGuide则是通过对比成功和失败的经验在每一步的状态级别进行总结,在推理时召回相关的状态和状态经验作为上文。通俗点说AppAgent是使用说明书,STE是操作案例集,AutoGuide是使用指南。

想要构建并使用指南,AutoGuide包含三个核心模块:状态总结模块(State Summarization),指南抽取模块(Guideline Extraction),和指南召回模块。论文针对不同的Agent场景设计了不同的状态总结和抽取prompt,这里还是用我们上一章刚提过的webagent中的WebArena数据集为例,分别说下两个模块

  1. State Summarization

状态总结模块是基于模型的规划链路(Thought+Action)来总结模型处于的状态。具体来说是基于同一个任务的成功和失败的两条行为链路,定位到两个链路首次出现不同行为的时间节点T,使用"<T"的链路行为作为输入,使用以下prompt进行状态总结。

image

举个例子,以下的任务中,两条行为链路是在Action1的时候出现了差异,则会使用Action1之前的观察和行为作为输入(current trajectory) 进行状态总结。这里得到的状态应该是"You are on the List of forum Page"

image

  1. Guideline Extraction

得到状态后则需要生成该状态下的行为指南,这里同样分别用到成功和失败的行为链路,以及前面的状态总结,作为输入来生成指南,具体prompt如下

image

同样是上面的例子,针对状态"You are on the List of forum Page",以上prompt得到的指南是 “if you want to navigate to a specific forum, you can click on the link that exactly matches the forum name you are looking for.”

在不断基于state生成guideline的过程中,论文还会使用大模型prompt对相似的状态进行合并,最终得到的是一个字典{state:guidelines}。以下是webArena场景中,最终生成的状态指南示例

image

  1. Apply Guideline at Test

基于以上获取的状态和状态指南,在推理阶段,每一步执行会先使用State Summarization模块对当前状态进行总结,然后基于当前的状态去构建好的状态指南中先定位相似的状态,这里使用了和上面状态消重合并相同的大模型prompt,然后基于定位到的状态,获取所有的相关指南。如果指南数量太多,则使用下面的prompt对指南进行筛选,只保留Top-K。然后基于这Top-K指南进行下一步思考和行为的推理。

image

如何系统的去学习大模型LLM ?

作为一名热心肠的互联网老兵,我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在人工智能学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。

但苦于知识传播途径有限,很多互联网行业朋友无法获得正确的资料得到学习提升,故此将并将重要的 AI大模型资料 包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来

😝有需要的小伙伴,可以V扫描下方二维码免费领取🆓

一、全套AGI大模型学习路线

AI大模型时代的学习之旅:从基础到前沿,掌握人工智能的核心技能!

img

二、640套AI大模型报告合集

这套包含640份报告的合集,涵盖了AI大模型的理论研究、技术实现、行业应用等多个方面。无论您是科研人员、工程师,还是对AI大模型感兴趣的爱好者,这套报告合集都将为您提供宝贵的信息和启示。

img

三、AI大模型经典PDF籍

随着人工智能技术的飞速发展,AI大模型已经成为了当今科技领域的一大热点。这些大型预训练模型,如GPT-3、BERT、XLNet等,以其强大的语言理解和生成能力,正在改变我们对人工智能的认识。 那以下这些PDF籍就是非常不错的学习资源。

img

在这里插入图片描述

四、AI大模型商业化落地方案

img

阶段1:AI大模型时代的基础理解

  • 目标:了解AI大模型的基本概念、发展历程和核心原理。
  • 内容
    • L1.1 人工智能简述与大模型起源
    • L1.2 大模型与通用人工智能
    • L1.3 GPT模型的发展历程
    • L1.4 模型工程
    • L1.4.1 知识大模型
    • L1.4.2 生产大模型
    • L1.4.3 模型工程方法论
    • L1.4.4 模型工程实践
    • L1.5 GPT应用案例

阶段2:AI大模型API应用开发工程

  • 目标:掌握AI大模型API的使用和开发,以及相关的编程技能。
  • 内容
    • L2.1 API接口
    • L2.1.1 OpenAI API接口
    • L2.1.2 Python接口接入
    • L2.1.3 BOT工具类框架
    • L2.1.4 代码示例
    • L2.2 Prompt框架
    • L2.2.1 什么是Prompt
    • L2.2.2 Prompt框架应用现状
    • L2.2.3 基于GPTAS的Prompt框架
    • L2.2.4 Prompt框架与Thought
    • L2.2.5 Prompt框架与提示词
    • L2.3 流水线工程
    • L2.3.1 流水线工程的概念
    • L2.3.2 流水线工程的优点
    • L2.3.3 流水线工程的应用
    • L2.4 总结与展望

阶段3:AI大模型应用架构实践

  • 目标:深入理解AI大模型的应用架构,并能够进行私有化部署。
  • 内容
    • L3.1 Agent模型框架
    • L3.1.1 Agent模型框架的设计理念
    • L3.1.2 Agent模型框架的核心组件
    • L3.1.3 Agent模型框架的实现细节
    • L3.2 MetaGPT
    • L3.2.1 MetaGPT的基本概念
    • L3.2.2 MetaGPT的工作原理
    • L3.2.3 MetaGPT的应用场景
    • L3.3 ChatGLM
    • L3.3.1 ChatGLM的特点
    • L3.3.2 ChatGLM的开发环境
    • L3.3.3 ChatGLM的使用示例
    • L3.4 LLAMA
    • L3.4.1 LLAMA的特点
    • L3.4.2 LLAMA的开发环境
    • L3.4.3 LLAMA的使用示例
    • L3.5 其他大模型介绍

阶段4:AI大模型私有化部署

  • 目标:掌握多种AI大模型的私有化部署,包括多模态和特定领域模型。
  • 内容
    • L4.1 模型私有化部署概述
    • L4.2 模型私有化部署的关键技术
    • L4.3 模型私有化部署的实施步骤
    • L4.4 模型私有化部署的应用场景

学习计划:

  • 阶段1:1-2个月,建立AI大模型的基础知识体系。
  • 阶段2:2-3个月,专注于API应用开发能力的提升。
  • 阶段3:3-4个月,深入实践AI大模型的应用架构和私有化部署。
  • 阶段4:4-5个月,专注于高级模型的应用和部署。
这份完整版的大模型 LLM 学习资料已经上传CSDN,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费

😝有需要的小伙伴,可以Vx扫描下方二维码免费领取🆓

  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值