写点什么

大模型驱动软件 2.0

  • 2023-08-03
    北京
  • 本文字数:14936 字

    阅读完需:约 49 分钟

大模型驱动软件2.0

原文地址:https://lilianweng.github.io/posts/2023-06-23-agent/, 部分翻译来自清华 ChatGLM 模型


使用大模型技术作为核心控制器来构建 Agent 是一个很酷的概念,一些验证这个概念的技术方案,例如 AutoGPT、GPT-Engineer 和 BadyAGI,取得令人鼓舞的成绩。大模型的扩展潜能,超过生成书写流畅的副本、故事、论文和问题,其可以作为强有力的通用问题解决方案。

Agent 系统概览

在大模型技术驱动的 Agent 系统,大模型的函数是大脑,组织协调一系列关键组件


  • 规划

  • 子目标和解构。Agent 系统将大的任务分割为较小的且易于管理的子目标,使得更加有效处理复杂问题

  • 反射和自省。Agent 系统会自我反省和自我复盘过去的动作,从错误中学习经验,并在后续的步骤中重新定义,这样就提高最终结果的质量

  • 记忆体

  • 短周期记忆体。我将所有基于上下文的学习都认为是一种短周期记忆体的模型学习

  • 长周期记忆体。这将提供 Agent 系统跨越时间去存储和回溯信息,通常这些能力需要依赖外部的向量存储和快速的检索

  • 工具使用

  • Agent 系统学习调用外部的 API 来获取信息,特别是那些不在模型预训练中的,包括实时信息、代码执行能力和获取私有信息的来源等等


组件一:规划

复杂的任务通常包括很多步骤,Agent 系统需要知道哪些是任务并计划

任务拆解

思维链已经成为一种面对复杂任务的标准化的针对模型增强的提升工程。模型遵循逐步思考策略,通过尽量增加测试评估来将复杂任务拆解为更小和更轻量的步骤。思维链技术将大的任务拆解为多个可管理的任务,同时阐述模型思考过程的可解释性。决策树通过在每个步骤遍历多个可能性的选择。首先,将问题拆解为多个想法步骤,然后为每个步骤生成多个想法,进而创建一棵树。遍历过程可以是深度有限或者广度优先,每个状态由分类器(通过提示)或多数投票进行评估。任务的拆解可以(1)在大模型下使用简洁的提示语例如"Steps for XYZ.\n1.", "What are the subgoals for achieving XYZ?",(2)使用特定的任务指令例如"Write a story outline."来编写故事,(3)或者根据人工输入。另一个办法是通过 LLM+P,通过引入外部经典的规划器来做任务规划。这个方案最大化 PDDL 作为描述规划问题的接口。在这个过程中,大模型将问题转化为 PDDL,然后再请求经典规划器生成基于 PDDL 的计划,最后再把 PDDL 计划转化为自然语言。 本质来说,就是把规划步骤交给外部工具去做,并假设存在专门领域的 PDDL 以及合适的计划器,这在某些机器人设置中是很常见的,但在许多其他领域中并不普遍。

自我反省

自我反省是允许 Agent 系统不断迭代过去的决策并修正之前的错误。在真实世界任务中,尝试和错误是不可避免的,扮演批评者角色。ReAct 通过将行动空间扩展为任务特定离散动作和语言空间的组合,在大模型中集成了推理和行动。之前启动 LLM 与环境交互,随后使用自然语言在提示大模型下来产生推理记录。ReAct 提示模板合并显示步骤来帮助大模型思考,格式如下所示


Thought: ...Action: ...Observation: ...... (Repeated many times)
复制代码



在知识推理任务和做决策任务中,ReAct 均较没有想法只有动作的基线要好。Reflexion 是一个框架集成动态内存和自我反省能力来提升推理能力,其有一个标准化的 RL 初始化,在这个过程中奖励模型提供简洁二分的奖励,而行动空间遵循在 ReAct 中的初始化,特定任务动作空间是使用语言参数化驱动复杂推理步骤。每一个步骤后,Agent 系统会计算启发值,可能启动重置环境来开启一个新的尝试,这些都依赖自反馈系统结果。



当轨道变得低效或者包含幻觉时,启发函数决定是否被终止。低效的规划常见很长的轨道但没有任何成功。幻觉被定义为在环境中遇到一系列连续相同的动作,这些动作导致相同的观察结果。自我反省通过两个例子给大模型来创建,每个例子都是成对存在。反省被追加到 Agent 系统的内存中,并在后续的大模型查询中使用。



链式后见之明(CoH;Liu 等,2023)鼓励模型通过明确向其呈现带有反馈的一系列过去输出来改进自己的输出。人类反馈数据是一个集合,其中每个<prompt, model completion, human rating, hindsight feedback>元组表示一个模型完成,人类评级和相应的人类提供的后见之明反馈。假设反馈元组按照奖励排名,该过程是监督微调,其中数据是一个形式为<prefix, output, human rating, hindsight feedback>的序列,其中模型被微调以仅在给定序列前缀的条件下预测<output>,以便模型根据反馈序列进行自我反思并产生更好的输出。在测试时间,模型还可以选择接收多轮人类注释员的指令。为了避免过拟合,CoH 在训练过程中添加了一个正则化项,以最大化预训练数据的对数似然。为了避免捷径和复制(因为反馈序列中存在许多常见单词),他们在训练过程中随机屏蔽了 0% - 5% 的过去词符。训练集合包括WebGPT comparisonssummarization from human feedbackhuman preference dataset



CoH 的想法是在上下文中呈现一个序列改进的输出历史,并训练模型以产生更好的输出趋势。算法蒸馏(Algorithm Distillation,AD;Laskin 等人,2023)将相同的想法应用于强化学习任务中的跨集群轨迹,其中算法被封装在一个长历史条件下的策略中。考虑到智能体与环境多次互动,并且在每一集群中智能体都会变得更好,AD 连接这个学习历史并输入到模型中。因此,我们应该预期下一个预测动作将比以前的试验导致更好的性能。目标是学习 RL 的过程,而不是训练一个特定任务的政策本身。



这篇论文假设,通过在动作上进行行为克隆,可以将生成一组学习历史集合的任何算法提炼为一个神经网络。历史数据由一组源政策生成,每个政策都是为特定任务训练的。在训练阶段,每次 RL 运行过程中会随机抽取一个任务,并使用多集群历史的子序列进行训练,使得学到的政策具有任务无关性。实际上,模型的上下文窗口长度是有限的,因此剧集应该足够短,以构建多集群历史。学习近优的上下文 RL 算法需要 2-4 集的多集群上下文。情境 RL 的出现需要足够的上下文。与三个基线相比,包括 ED(专家蒸馏,用专家轨迹代替学习历史进行行为克隆)、源策略(用于通过 UCB 生成蒸馏轨迹)和 RL^2(Duan 等人,2017;用于作为上限,因为它需要在线 RL),AD 在使用离线 RL 的情况下,展示出情境 RL,其性能接近 RL^2,并且学习速度比其他基线快得多。在给定源策略的部分训练历史条件下,AD 也比 ED 基线改进得更快。


组件二:记忆体

记忆类型

记忆体可以被用来获取、存储、保持和过后恢复信息。在人脑中有几种不同类型的记忆体。


  1. 感官记忆:这是最早期阶段的记忆体,在原始的信息结束后,提供由感官刺激来保持信息的能力。感官记忆通常只能持续几秒钟,包括视觉、听觉和触觉。

  2. 顺时记忆:或者成为工作记忆,其储存我们正在感知的信息和复杂认知活动,例如学习和理智。根据 Miller 在 1956 年研究证明,顺时记忆可以保持 7 个左右,持续 20 到 30 秒。

  3. 长期记忆:长期记忆存储信息,可以跨域几天到几十年,并且通常没有存储空间的限制,其还有两个子类别。

  4. 显性记忆:这类记忆体包括事实和事件,可以有意识的回顾,包括情节记忆和语义记忆。

  5. 隐性记忆:这类记忆体是无意识的,可以自动出发技能和路径,例如骑自行车和在键盘上打字。



我们可以做如下的映射:


  • 感官记忆对应将内嵌的信息作为原始输入,例如文本、图片或者其他模型

  • 顺时记忆对应上下文学习,其是短暂和有界限的,因为受限于有限的 Transformer 上下文窗口

  • 长期记忆对应外部向量存储,那些 Agent 系统可以在查询时获取,通过快速搜索来获取

最大内积检索

外部记忆体可以缓和有限注意力扩展的限制,标准的做法是将信息保存到支持最大内积检索的向量存储。为了尽可能缩短获取速度,最常见的选择是使用近似最近邻算法返回最近的 K 个进而在牺牲一点准确性的基础上获得足够大的速度优势对于快速最大内积检索的常见近似最近邻算法如下所示:


  • LSH(Locality-Sensitive Hashing):这个算法引入一个哈希函数,这样相似的输入元素很大概率被映射到相同的区块,这样区块的数量相较于输入的数量就会更少。

  • ANNOY(Approximate Nearest Neighbors Oh Yeah):其核心数据解构是随机映射树,一组二叉树,每个非叶子节点代表一个一分为二的高维度分割器,每个叶子节点存储数据。树是被随机构建的,一定程度来说充当了哈希函数。ANNOY 检索在最接近 query 的一半树上进行迭代检索,然后集合结果。这个想法和 KD 树较为相似但是可扩展性更好些。

  • HNSW(Hierarchical Navigable Small World):这个算法受到小世界网络的启发,其大多数节点都可以被其他节点通过较少的步数获取,例如社交网络上的六度人脉特性。HNSW 构建分级的小世界网络,在最底层保存数据,中间层创建连接来缩短检索时长。当执行检索任务时,HNSW 在最上层随机节点开始,然后朝着目标前进。当不能再接近时,来到下一层,一直到最后一层。在高层的每一次移动能覆盖很大一部分数据空间,而在较低层级则提升检索的质量。

  • FAISS(Facebook AI Similarity Search):这个算法构建在这样的假设下,在高维度空间,节点间的距离符合高斯分布,因此应该存在数据点的聚类的高斯混合模型所做出的假设。FAISS 通过将向量空间划分为簇,然后在簇内部进行量化,从而应用向量量化。具体来说,FAISS 首先将向量空间分为多个簇,然后在每个簇内部进行进一步的量化。这种方法能够提高量化的精度,同时降低计算复杂度。搜索过程首先寻找粗量化下的簇候选者,然后使用更细的量化方法进一步研究每个簇。这种方法能够提高搜索的效率,同时保证搜索结果的准确性。

  • ScaNN(Scalable Nearest Neighbors):ScaNN 的主要创新是各向异性向量量化。



ann-benchmarks.com可以获得更多 MIPS 算法和性能对比

组件三:工具使用

使用工具是人类区分其他物种的主要特征之一。我们制造、修改以及扩展外部对象来实现超出我们物理和认知的局限。使用外部工具来辅助大模型可以有效扩展模型的能力。



模块化推理、认知和语言简称 MRKL,是用来一种独立自主神经系统架构。这个系统的目标是存储一系列专家模块和通用目标的大模型沿着路径寻找最合适的专家模块,这些模块可以是神经网络(例如深度学习模型)或者符号化(数学计算、货币转换和天气 API)。有人做过一个实验,使用 fine-tuning 大模型去调用计算器,以算术作为测试用例。这个实验显示出,相较于明确表述数学问题,解决口头数学问题更困难,这是因为大模型(7B Jurassic1-large model)不能对基础算术问题设置正确的参数。这个实验强调外部符合化工具并且知道什么时候和如何使用是至关重要的,这些决定了大模型的能力。TALM 和 Toolformer 均可以通过 fine-tuning 来学习使用外部工具 API。数据集根据新添加的 API 调用注释是否可以提高模型输出质量进行扩展。可以到External APIs” section查找更多细节。chatGPT 的 Plugin 和 OpenAI 的 API 函数是很好的大模型参数化外部工具的样例。这些 API 可以被其他开发者和自身调用。HuggingGPT 是使用 ChatGPT 作为任务调度器根据模型的描述选择合适的模型,然后根据执行结果总结响应结果。



这个系统包括 4 个阶段:


  1. 任务规划:大模型充当大脑的角色,将用户的请求分解为若干任务。每个任务均有 4 个属性:任务类型、任务 ID、依赖项和参数集合。他们使用小样本指导大模型做任务分解和计划。


指令:


The AI assistant can parse user input to several tasks: [{"task": task, "id", task_id, "dep": dependency_task_ids, "args": {"text": text, "image": URL, "audio": URL, "video": URL}}]. The "dep" field denotes the id of the previous task which generates a new resource that the current task relies on. A special tag "-task_id" refers to the generated text image, audio and video in the dependency task with id as task_id. The task MUST be selected from the following options: {{ Available Task List }}. There is a logical relationship between tasks, please note their order. If the user input can't be parsed, you need to reply empty JSON. Here are several cases for your reference: {{ Demonstrations }}. The chat history is recorded as {{ Chat History }}. From this chat history, you can find the path of the user-mentioned resources for your task planning.


  1. 模型选择:大模型分解任务到专家模型,每一个请求都被当做一个多个选项的问题。大模型被表现为一系列可选的模型。受限于上下文长度,基于过滤的任务类型是必要的


指令:


Given the user request and the call command, the AI assistant helps the user to select a suitable model from a list of models to process the user request. The AI assistant merely outputs the model id of the most appropriate model. The output must be in a strict JSON format: "id": "id", "reason": "your detail reason for the choice". We have a list of models for you to choose from {{ Candidate Models }}. Please select one model from the list.


  1. 任务执行:专家模型执行特定的任务并记录结果


指令:


With the input and the inference results, the AI assistant needs to describe the process and results. The previous stages can be formed as - User Input: {{ User Input }}, Task Planning: {{ Tasks }}, Model Selection: {{ Model Assignment }}, Task Execution: {{ Predictions }}. You must first answer the user's request in a straightforward manner. Then describe the task process and show your analysis and model inference results to the user in the first person. If inference results contain a file path, must tell the user the complete file path.


  1. 生成响应:大模型收到执行结果并给用户提供总结性信息


为了把 HuggingGPT 引进现实,有一些挑战需要被解决:


  1. 提升性能,因为大模型接口和与其他模型的交互拖慢整个进城

  2. 依赖长的执行上下文来跨越复杂任务通信

  3. 大模型和外部模型输出的可信度提升


API-Bank 是度量使用工具的大模型的标准,其包括 53 个通用的 API 工具,一个完整的基于工具的大模型工作流程以及 264 组带注释的对话,可发起 568 次 API 调用。API 的选择是唯一的,包括搜索引擎、计算器、日历查询、智能硬件、调度管理、健康数据、账户认证工作流等等。由于存在很多 API,大模型首先通过搜索引擎选择合适的 API,然后使用适当的参数去调用。



在 API-Bank 的流程中,大模型需要做出一系列决策,每一个步骤我们都可以判断有效性,如下所示


  1. API 调用是否是必要的

  2. 识别正确的 API 被调用,如果不够好,大模型应该迭代后并修改 API 的输入,例如决定搜索引擎的搜索词

  3. 根据 API 的结果响应:当结果不够好时,模型可以选择,修正或者再次调用


这套标准将 Agent 系统的工具使用能力分为 3 个等级:


  • 第一级别具有调用 API 的能力。根据 API 的描述,模型决定是否需要调用、正确地调用以及适当的响应 API 的返回

  • 第二级别具有查找 API 的能力。模型根据用户的需求检索到可能的 API,并且通过阅读文档使用 API

  • 第三级别在查找和调用 API 的基础上,可以计划 API 的调用。根据模糊的用户需求,模型可以组合多个 API 调用去解决问题

案例学习

科学发现 Agent

ChemCrow(Bran 等人,2023)是一个特定领域的示例,其中 LLM 通过 13 个专家设计的工具来完成有机合成、药物发现和材料设计等任务。该工作流程在 LangChain 中实现,反映了之前在 ReAct 和 MRKLs 中描述的内容,并将 CoT 推理与相关任务的工具相结合:


  • LLM 提供了一份工具名称列表、它们用途的描述以及预期输入/输出的详细信息。

  • 然后指示它在必要时使用提供的工具来回答用户给出的提示。说明建议模型遵循 ReAct 格式 - 思考、行动、行动输入、观察。


有趣的是,尽管基于 LLM 的评估得出结论,GPT-4 和 ChemCrow 的表现几乎相当,但专家导向的解决方案的完成和化学正确性的人类评估显示,ChemCrow 的表现比 GPT-4 好得多。这表明,在需要深入专业知识的领域中,使用 LLM 来评估其自身性能可能存在潜在问题。缺乏专业知识可能导致 LLM 不知道其缺陷,因此无法很好地判断任务结果的正确性。Boiko 等人(2023)还研究了使用 LLM 赋能的智能体在科学发现领域的应用,以处理复杂科学实验的自主设计、计划和执行。这款智能体可以使用工具浏览互联网、阅读文档、执行代码、调用机器人实验 API 并利用其他 LLM。例如,当要求“开发一种新型抗癌药物”时,模型给出了以下推理步骤:


  1. 询问当前抗癌药物发现的趋势;

  2. 选择一个目标;

  3. 请求一个针对这些化合物的支架;

  4. 一旦确定了化合物,模型就会尝试对其进行合成。


他们还讨论了风险,特别是与非法药物和生物武器有关的风险。他们制定了一个测试集,包含已知的化学武器剂清单,并要求代理人合成它们。在 11 个请求中,有 4 个被接受以获得合成溶液,Agent 试图查阅文档以执行程序。其中 11 个请求中有 7 个被拒绝,在这 7 个被拒绝的案例中,有 5 个是在网络搜索之后发生的,有 2 个是基于提示被拒绝的。

生成 Agent 模拟器

Generative Agents(Park, et al. 2023)是一个非常有趣的实验,其中 25 个虚拟角色,每个角色都由一个由 LLM 驱动的智能体控制,在一个沙盒环境中生活和互动,灵感来源于《模拟城市》。生成式代理为交互式应用程序创建了人类行为的可信模拟生成式代理的设计将 LLM 与记忆、计划和反思机制相结合,使代理能够根据过去的经验表现出条件反射,同时还能与其他代理互动。


  • 记忆流:是一个长期记忆模块(外部数据库),它记录了代理在自然语言中的全面经验清单。

  • 每一个元素都是一个观察值,是由代理直接提供的事件。 - 跨代理通信可以触发新的自然语言陈述。

  • 检索模型:根据相关性、新颖性和重要性,将上下文呈现出来,以指导代理的行为。

  • 新颖性:最近发生的事件具有更高的分数

  • 重要性:区分平凡事件和核心记忆。直接询问 LM。

  • 相关性:根据它与当前情况/查询的关联程度而定。

  • 反射机制:随着时间的推移,将记忆合成为更高层次的推理,并指导代理的未来行为。它们是对过去事件的高层次总结(<- 注意这里的自我反思与上面的自我反思略有不同)

  • 给定 100 个最近的观察结果,提示 LM 生成 3 个最显著的高层次问题。然后请 LM 回答这些问题。

  • 规划与反应:将反思和环境信息转化为行动

  • 规划的本质是为了在当前时刻优化可信度。

  • 提示模板:{Intro of an agent X}. Here is X's plan today in broad strokes:

  • 规划和反应中都考虑了代理之间的关系以及一个代理对另一个代理的观察。

  • 环境信息以树状结构呈现



这种有趣的模拟产生了一些 emergent social behavior,例如信息扩散、关系记忆(例如两个代理继续谈话主题)和社交活动的协调(例如举办派对并邀请许多人)。

POC 样例

AutoGPT 已经引起了很多人关于使用 LLM 作为主要控制器来建立自主代理的可能性的兴趣。由于自然语言接口,它存在相当多的可靠性问题,但这仍然是一个很酷的概念证明。AutoGPT 中有很多代码是关于格式解析的。下面是一个使用 AutoGPT 的系统消息,其中{{...}}是用户的输入


You are {{ai-name}}, {{user-provided AI bot description}}.Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications.
GOALS:
1. {{user-provided goal 1}}2. {{user-provided goal 2}}3. ...4. ...5. ...
Constraints:1. ~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.3. No user assistance4. Exclusively use the commands listed in double quotes e.g. "command name"5. Use subprocesses for commands that will not terminate within a few minutes
Commands:1. Google Search: "google", args: "input": "<search>"2. Browse Website: "browse_website", args: "url": "<url>", "question": "<what_you_want_to_find_on_website>"3. Start GPT Agent: "start_agent", args: "name": "<name>", "task": "<short_task_desc>", "prompt": "<prompt>"4. Message GPT Agent: "message_agent", args: "key": "<key>", "message": "<message>"5. List GPT Agents: "list_agents", args:6. Delete GPT Agent: "delete_agent", args: "key": "<key>"7. Clone Repository: "clone_repository", args: "repository_url": "<url>", "clone_path": "<directory>"8. Write to file: "write_to_file", args: "file": "<file>", "text": "<text>"9. Read file: "read_file", args: "file": "<file>"10. Append to file: "append_to_file", args: "file": "<file>", "text": "<text>"11. Delete file: "delete_file", args: "file": "<file>"12. Search Files: "search_files", args: "directory": "<directory>"13. Analyze Code: "analyze_code", args: "code": "<full_code_string>"14. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<full_code_string>"15. Write Tests: "write_tests", args: "code": "<full_code_string>", "focus": "<list_of_focus_areas>"16. Execute Python File: "execute_python_file", args: "file": "<file>"17. Generate Image: "generate_image", args: "prompt": "<prompt>"18. Send Tweet: "send_tweet", args: "text": "<text>"19. Do Nothing: "do_nothing", args:20. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>"
Resources:1. Internet access for searches and information gathering.2. Long Term memory management.3. GPT-3.5 powered Agents for delegation of simple tasks.4. File output.
Performance Evaluation:1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.2. Constructively self-criticize your big-picture behavior constantly.3. Reflect on past decisions and strategies to refine your approach.4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.
You should only respond in JSON format as described belowResponse Format:{"thoughts": {"text": "thought","reasoning": "reasoning","plan": "- short bulleted\n- list that conveys\n- long-term plan","criticism": "constructive self-criticism","speak": "thoughts summary to say to user"},"command": {"name": "command name","args": {"arg name": "value"}}}Ensure the response can be parsed by Python json.loads
复制代码


GPT-Engineer 是另一个项目,旨在根据自然语言指定的任务创建一个完整的代码库。GPT-Engineer 会思考一个较小的组件列表,并根据需要向用户寻求输入以澄清问题。以下是一个用于任务澄清的示例对话,该对话发送给 OpenAI ChatCompletion 端点,该端点被 GPT-Engineer 使用。用户的输入包裹在 {{用户输入文本}} 中.


[  {    "role": "system",    "content": "You will read instructions and not carry them out, only seek to clarify them.\nSpecifically you will first summarise a list of super short bullets of areas that need clarification.\nThen you will pick one clarifying question, and wait for an answer from the user.\n"  },  {    "role": "user",    "content": "We are writing {{a Super Mario game in python. MVC components split in separate files. Keyboard control.}}\n"  },  {    "role": "assistant",    "content": "Summary of areas that need clarification:\n1. Specifics of the Super Mario game (e.g. level design, characters, gameplay mechanics)\n2. Details about the MVC components (e.g. which components are in each file)\n3. Keyboard control implementation (e.g. which keys to use, how to handle input)\n\nClarifying question:\nCan you provide more details about the Super Mario game, such as level design, characters, and gameplay mechanics?"  },  {    "role": "user",    "content": "{{There are 10 levels in total. The main character is a plumber named Mario, who can walk and jump. It is a classical platform game just like Super Mario. The main character moves from left to right, trying to get to the destination, where there are many obstacles and attacks from enemies in the process.}}\n\nIs anything else unclear? If yes, only answer in the form:\n{remaining unclear areas} remaining questions.\n{Next question}\nIf everything is sufficiently clear, only answer \"Nothing more to clarify.\"."  },  {    "role": "assistant",    "content": "Remaining unclear areas: 2 remaining questions.\nCan you provide more information about how the MVC components are split into separate files?"  },  {    "role": "user",    "content": "{{Make your own assumptions and state them explicitly before starting}}"  }]
复制代码


然后,在澄清任务后,代理进入了编写代码的模式,并使用了不同的系统消息。系统消息


You will get instructions for code to write. You will write a very long answer. Make sure that every detail of the architecture is, in the end, implemented as code. Make sure that every detail of the architecture is, in the end, implemented as code.Think step by step and reason yourself to the right decisions to make sure we get it right. You will first lay out the names of the core classes, functions, methods that will be necessary, as well as a quick comment on their purpose.
Then you will output the content of each file including ALL code. Each file must strictly follow a markdown code block format, where the following tokens must be replaced such that FILENAME is the lowercase file name including the file extension, LANG is the markup code block language for the code’s language, and CODE is the code:
FILENAME
CODEYou will start with the “entrypoint” file, then go to the ones that are imported by that file, and so on. Please note that the code should be fully functional. No placeholders.
Follow a language and framework appropriate best practice file naming convention. Make sure that files contain all imports, types etc. Make sure that code in different files are compatible with each other. Ensure to implement all code, if you are unsure, write a plausible implementation. Include module dependency or package manager dependency definition file. Before you finish, double check that all parts of the architecture is present in the files.
Useful to know: You almost always put different classes in different files. For Python, you always create an appropriate requirements.txt file. For NodeJS, you always create an appropriate package.json file. You always add a comment briefly describing the purpose of the function definition. You try to add comments explaining very complex bits of logic. You always follow the best practices for the requested languages in terms of describing the code written as a defined package/project.
Python toolbelt preferences:
pytestdataclasses
复制代码


对话例子


[  {    "role": "system",    "content": "You will get instructions for code to write.\nYou will write a very long answer. Make sure that every detail of the architecture is, in the end, implemented as code.\nMake sure that every detail of the architecture is, in the end, implemented as code.\n\nThink step by step and reason yourself to the right decisions to make sure we get it right.\nYou will first lay out the names of the core classes, functions, methods that will be necessary, as well as a quick comment on their purpose.\n\nThen you will output the content of each file including ALL code.\nEach file must strictly follow a markdown code block format, where the following tokens must be replaced such that\nFILENAME is the lowercase file name including the file extension,\nLANG is the markup code block language for the code's language, and CODE is the code:\n\nFILENAME\n```LANG\nCODE\n```\n\nYou will start with the \"entrypoint\" file, then go to the ones that are imported by that file, and so on.\nPlease note that the code should be fully functional. No placeholders.\n\nFollow a language and framework appropriate best practice file naming convention.\nMake sure that files contain all imports, types etc. Make sure that code in different files are compatible with each other.\nEnsure to implement all code, if you are unsure, write a plausible implementation.\nInclude module dependency or package manager dependency definition file.\nBefore you finish, double check that all parts of the architecture is present in the files.\n\nUseful to know:\nYou almost always put different classes in different files.\nFor Python, you always create an appropriate requirements.txt file.\nFor NodeJS, you always create an appropriate package.json file.\nYou always add a comment briefly describing the purpose of the function definition.\nYou try to add comments explaining very complex bits of logic.\nYou always follow the best practices for the requested languages in terms of describing the code written as a defined\npackage/project.\n\n\nPython toolbelt preferences:\n- pytest\n- dataclasses\n"  },  #  … same conversation as earlier, ended with "Make your own assumptions and state them explicitly before starting".  {  "role": "assistant",  "content": "Assumptions:\n1. Model: The model will contain the game's data, such as level information, character states, and enemy positions.\n2. View: The view will handle the game's visuals, including rendering the game objects, backgrounds, and updating the display.\n3. Controller: The controller will manage user input, such as keyboard controls, and update the model accordingly.\n\nWith these assumptions in mind, is there any specific aspect of the keyboard control implementation you would like me to clarify?"  },  {    "role": "user",    "content": "Please now remember the steps:\n\nThink step by step and reason yourself to the right decisions to make sure we get it right.\nFirst lay out the names of the core classes, functions, methods that will be necessary, As well as a quick comment on their purpose.\n\nThen you will output the content of each file including ALL code.\nEach file must strictly follow a markdown code block format, where the following tokens must be replaced such that\nFILENAME is the lowercase file name including the file extension,\nLANG is the markup code block language for the code's language, and CODE is the code:\n\nFILENAME\n```LANG\nCODE\n```\n\nPlease note that the code should be fully functional. No placeholders.\n\nYou will start with the \"entrypoint\" file, then go to the ones that are imported by that file, and so on.\nFollow a language and framework appropriate best practice file naming convention.\nMake sure that files contain all imports, types etc. The code should be fully functional. Make sure that code in different files are compatible with each other.\nBefore you finish, double check that all parts of the architecture is present in the files.\n"  }    ]
复制代码

挑战

在回顾关键信息和构建以大模型技术为核心的 Agent 系统的 DEMO 后,我发现一些通用的限制:


  • 有限的上下文长度:受限制的长下文能力限制历史信息的概括、详细的信息、API 执行上下文以及响应。系统必将与这些限制通信带宽一起工作,而一些例如自我反省这样从过去学习到错误的特性将会从更大的长下文窗口中获益。尽管向量存储和检索可以提供规模更大的知识检索,但是表现不如完整的注意力。

  • 应对长期规划和任务拆解的挑战:通过长期历史规划和更有效地寻找解决方案空间仍是挑战。大模型一旦遇到非预期的错误就会调整计划,这导致相较于哪些从尝试和错误中学习的人类,缺少鲁棒性。

  • 自然语言的接口的可信度:当前 Agent 系统依赖自然语言作为大模型和外部组件例如记忆体和工具使用的接口,然而模型输出的可信度是值得商榷的,例如大模型可以出现格式错误和有时展现出不服从的行为。所以,很多 Agent 的 demo 代码专注在格式化模型输出。

引文

Weng, Lilian. (Jun 2023). LLM-powered Autonomous Agents". Lil’Log. https://lilianweng.github.io/posts/2023-06-23-agent/


@article{weng2023prompt,  title   = "LLM-powered Autonomous Agents"",  author  = "Weng, Lilian",  journal = "lilianweng.github.io",  year    = "2023",  month   = "Jun",  url     = "https://lilianweng.github.io/posts/2023-06-23-agent/"}
复制代码

引用资料

[1] Wei et al. “Chain of thought prompting elicits reasoning in large language models." NeurIPS 2022

[2] Yao et al. “Tree of Thoughts: Dliberate Problem Solving with Large Language Models." arXiv preprint arXiv:2305.10601 (2023).

[3] Liu et al. “Chain of Hindsight Aligns Language Models with Feedback “ arXiv preprint arXiv:2302.02676 (2023).

[4] Liu et al. “LLM+P: Empowering Large Language Models with Optimal Planning Proficiency” arXiv preprint arXiv:2304.11477 (2023).

[5] Yao et al. “ReAct: Synergizing reasoning and acting in language models." ICLR 2023.

[6] Google Blog. “Announcing ScaNN: Efficient Vector Similarity Search” July 28, 2020.

[7] https://chat.openai.com/share/46ff149e-a4c7-4dd7-a800-fc4a642ea389

[8] Shinn & Labash. “Reflexion: an autonomous agent with dynamic memory and self-reflection” arXiv preprint arXiv:2303.11366 (2023).

[9] Laskin et al. “In-context Reinforcement Learning with Algorithm Distillation” ICLR 2023.

[10] Karpas et al. “MRKL Systems A modular, neuro-symbolic architecture that combines large language models, external knowledge sources and discrete reasoning." arXiv preprint arXiv:2205.00445 (2022).

[11] Weaviate Blog. Why is Vector Search so fast? Sep 13, 2022.

[12] Li et al. “API-Bank: A Benchmark for Tool-Augmented LLMs” arXiv preprint arXiv:2304.08244 (2023).

[13] Shen et al. “HuggingGPT: Solving AI Tasks with ChatGPT and its Friends in HuggingFace” arXiv preprint arXiv:2303.17580 (2023).

[14] Bran et al. “ChemCrow: Augmenting large-language models with chemistry tools." arXiv preprint arXiv:2304.05376 (2023).

[15] Boiko et al. “Emergent autonomous scientific research capabilities of large language models." arXiv preprint arXiv:2304.05332 (2023).

[16] Joon Sung Park, et al. “Generative Agents: Interactive Simulacra of Human Behavior." arXiv preprint arXiv:2304.03442 (2023).

[17] AutoGPT. https://github.com/Significant-Gravitas/Auto-GPT

[18] GPT-Engineer. https://github.com/AntonOsika/gpt-engineer

用户头像

前端技术创新 体验优化 分享经验 共同进步 2018-11-25 加入

通过技术的创新和优化,为用户创造更好的使用体验,并与更多的前端开发者分享我们的经验和成果。我们欢迎对前端开发感兴趣的朋友加入我们的团队,一同探讨技术,共同进步。

评论

发布
暂无评论
大模型驱动软件2.0_大模型_汽车之家客户端前端团队_InfoQ写作社区