当前位置: 首页 > news >正文

北苑做网站的公司hr系统管理软件排名

北苑做网站的公司,hr系统管理软件排名,wordpress 人流量 插件,网页制作教程步骤目录 前言一、智能体1-1、Agent概述1-2、Agent与ChatGPT的区别 二、多智能体框架MetaGPT2-1、安装配置2-2、使用已有的Agent#xff08;ProductManager#xff09;2-3、拥有单一行为的Agent#xff08;SimpleCoder#xff09;2-3-1、定义写代码行为2-3-2、角色定义2-3… 目录 前言一、智能体1-1、Agent概述1-2、Agent与ChatGPT的区别 二、多智能体框架MetaGPT2-1、安装配置2-2、使用已有的AgentProductManager2-3、拥有单一行为的AgentSimpleCoder2-3-1、定义写代码行为2-3-2、角色定义2-3-3、初始化角色并运行 2-4、拥有多行为的Agent2-4-1、定义执行代码行为2-4-2、定义角色2-4-3、启动角色2-4-4、番外篇如何获取模型决策决策下一步执行什么行为 2-、多智能体系统 附录1、react_mode智能体的思维范式介绍1-1、ReAct1-2、By order1-3、Plan and act 总结 前言 智能体可以像人一样思考、计划拥有记忆甚至是情感具备与环境、其他智能体以及和人类互动的能力用公式来讲的话智能体大语言模型LLM观察思考行动记忆使用LLM来构建Agent超酷的好吗 一、智能体 1-1、Agent概述 Agent智能体 具有一定自主性和目标导向性可以在没有持续人类干预的情况下执行任务和作出决策。以下为Agent的一些特性 1自主性和目标导向性 自主性Agent具备自主执行任务的能力不需要外部指令即可根据设定的目标进行操作。目标导向性Agent设置并追求特定的目标或任务这些目标指导其决策过程和行为模式。 2复杂的工作流程 任务规划与执行Agent能够规划如何达到其目标包括任务分解、优先级排序以及实际执行。自我对话和内部决策在处理问题时Agent可以进行内部对话以自我推理和修正其行动路径而无需外部输入。 3学习和适应能力 反思和完善Agent能从自身的经验中学习评估过去的行为从错误中吸取教训并改进未来的策略。环境适应性在遇到变化的环境或不同的挑战时Agent能够适应并调整其行为以最大化目标达成。 4记忆机制 短期记忆使用上下文信息来做出即时决策。长期记忆保留关键信息供未来决策使用通常通过外部数据库或持久存储实现。例如使用向量数据库 5工具使用与集成 API调用和外部数据访问Agent可以利用外部资源如API、数据库来获取信息填补其知识空白或执行无法直接通过模型内部处理的任务。技术整合Agent能整合多种技术和服务如代码执行能力和专业数据库访问以丰富其功能和提高效率。 LLM 驱动的自主Agents系统概述如下图所示包含工具调用、记忆、计划、执行模块 1-2、Agent与ChatGPT的区别 Agent与ChatGPT的区别: Agent与ChatGPT在设计、功能和目标上有一些关键区别。虽然它们都是基于人工智能技术但应用方式和交互性质大不相同。下面是这两者的主要区别 1目标和自主性 ChatGPT主要是一个响应型模型专注于对用户的特定输入生成一次性、相关且连贯的回答。它的主要目的是解答问题、提供信息或进行对话模拟。AI Agent更强调在持续的任务中表现出自主性。它能够设定和追求长期目标通过复杂的工作流程自主地完成任务比如从错误中自我修正、连续地追踪任务进展等。 2 交互方式 ChatGPT用户与ChatGPT的交互通常是线性的和短暂的即用户提问ChatGPT回答。它不保留交互的历史记忆每次交互都是独立的。AI Agent可以维持跨会话的状态和记忆具有维持长期对话的能力能够自动执行任务并处理一系列相关活动例如调用API、追踪和更新状态等。 3任务执行和规划能力 ChatGPT通常只处理单个请求或任务依赖用户输入来驱动对话。它不具备自我规划或执行连续任务的能力。AI Agent具备规划能力可以自行决定执行哪些步骤以完成复杂任务。它可以处理任务序列自动化决策和执行过程。 4技术整合与应用 ChatGPT主要是文本生成工具虽然能够通过插件访问外部信息但核心依然是文本处理和生成。AI Agent可能整合多种技术和工具如API调用、数据库访问、代码执行等这些都是为了实现其目标和改善任务执行的效率。 5学习和适应 ChatGPT它的训练是在离线进行通过分析大量数据来改进。AI Agent除了离线学习更复杂的AI Agent可能具备实时学习能力能够从新的经验中迅速适应和改进这通常需要一定的记忆和自我反思机制。 二、多智能体框架MetaGPT 2-1、安装配置 安装 必须要python版本在3.9以上 这里使用conda尝鲜安装。 conda create -n metagpt python3.9 conda activate metagpt开发模式下安装 为开发人员推荐。实现新想法和定制化功能。 git clone https://github.com/geekan/MetaGPT.git cd ./MetaGPT pip install -e .模型配置 在文件 ~/.metagpt/config2.yaml下有关于各大厂商模型的配置详细列表参考LLM API Configuration llm:api_type: openai # or azure / ollama / groq etc. Check LLMType for more optionsmodel: gpt-4-turbo # or gpt-3.5-turbobase_url: https://api.openai.com/v1 # or forward url / other llm urlapi_key: YOUR_API_KEY2-2、使用已有的AgentProductManager 概述 调用ProductManager Agent注意会话上下文是需要独立创建的 import asynciofrom metagpt.context import Context from metagpt.roles.product_manager import ProductManager from metagpt.logs import loggerasync def main():msg Write a PRD for a snake gamecontext Context() # The session Context object is explicitly created, and the Role object implicitly shares it automatically with its own Action objectrole ProductManager(contextcontext)while msg:msg await role.run(msg)logger.info(str(msg))if __name__ __main__:asyncio.run(main())输出结果 2-3、拥有单一行为的AgentSimpleCoder Agent——SimpleCoder拥有写代码能力我们需要实现如下两步 定义写代码行动定义角色并赋予写代码能力 2-3-1、定义写代码行为 继承自Action类self.PROMPT_TEMPLATE.format 引用当前类的PROMPT_TEMPLATE属性调用format方法来替换模板中的占位符即instruction并且使用run方法接受instruction参数最终构建出完整的提示模板。self._aask调用大模型使用提示词模板进行提问。最终结果需要经过解析函数parse_code得到写好的代码。 import re from metagpt.actions import Actionclass SimpleWriteCode(Action):PROMPT_TEMPLATE: str Write a python function that can {instruction} and provide two runnnable test cases.Return python your_code_here with NO other texts,your code:name: str SimpleWriteCodeasync def run(self, instruction: str):prompt self.PROMPT_TEMPLATE.format(instructioninstruction)rsp await self._aask(prompt)code_text SimpleWriteCode.parse_code(rsp)return code_textstaticmethoddef parse_code(rsp):pattern rpython(.*)match re.search(pattern, rsp, re.DOTALL)code_text match.group(1) if match else rspreturn code_text2-3-2、角色定义 继承自Role类是Agent的逻辑抽象一个角色可以拥有多个行为即Action也拥有记忆可以以不同的策略来思考和行动。初始化时我们为他配备了行为SimpleWriteCode即写代码这个行为重写_act函数在最近的消息中检索指令运行相应操作使用todo.run(msg.content)todo这里代表的是相关行为Action。 from metagpt.roles import Roleclass SimpleCoder(Role):name: str Aliceprofile: str SimpleCoderdef __init__(self, **kwargs):super().__init__(**kwargs)self.set_actions([SimpleWriteCode])async def _act(self) - Message:logger.info(f{self._setting}: to do {self.rc.todo}({self.rc.todo.name}))todo self.rc.todo # todo will be SimpleWriteCode()msg self.get_memories(k1)[0] # find the most recent messagescode_text await todo.run(msg.content)msg Message(contentcode_text, roleself.profile, cause_bytype(todo))return msg2-3-3、初始化角色并运行 import asynciofrom metagpt.context import Contextasync def main():msg write a function that calculates the product of a listcontext Context()role SimpleCoder(contextcontext)logger.info(msg)result await role.run(msg)logger.info(result)asyncio.run(main()) 运行结果如下 智能体的运行周期如下所示 2-4、拥有多行为的Agent RunnableCoder 不仅拥有生成代码能力还拥有执行代码能力 2-4-1、定义执行代码行为 概述 执行代码主要是启动子进程获取执行结果生成代码行为同上不过正则表达式提取需要简单修改一下根据个人生成代码差异可以进行调整我这里为pattern rpython\n([\s\S]*?)\n class SimpleRunCode(Action):name: str SimpleRunCodeasync def run(self, code_text: str):result subprocess.run([python3, -c, code_text], capture_outputTrue, textTrue)code_result result.stdoutlogger.info(f{code_result})return code_result备注 执行代码部分因操作系统而异我这里为subprocess.run([sys.executable, “-c”, code_text], capture_outputTrue, textTrue, encoding‘utf-8’) 2-4-2、定义角色 概述定义拥有多个行为的角色。 在set_actions中设定好所有行为。_set_react_mode是用来设定角色每次如何选择行为这里我们设定为by_order即依次顺序执行。即先写代码后执行代码改写_act函数角色从用户输入或者是上一轮行为输出的结果检索信息当作当前行为self.rc.todo的入参最终返回当前行为输出的消息 class RunnableCoder(Role):name: str Aliceprofile: str RunnableCoderdef __init__(self, **kwargs):super().__init__(**kwargs)self.set_actions([SimpleWriteCode, SimpleRunCode])self._set_react_mode(react_modeby_order)async def _act(self) - Message:logger.info(f{self._setting}: to do {self.rc.todo}({self.rc.todo.name}))# By choosing the Action by order under the hood# todo will be first SimpleWriteCode() then SimpleRunCode()todo self.rc.todomsg self.get_memories(k1)[0] # find the most k recent messagesresult await todo.run(msg.content)msg Message(contentresult, roleself.profile, cause_bytype(todo))self.rc.memory.add(msg)return msg2-4-3、启动角色 import asynciofrom metagpt.context import Contextasync def main():msg 写一个傅里叶函数并且执行context Context()role RunnableCoder(contextcontext)logger.info(msg)result await role.run(msg)logger.info(result)asyncio.run(main)输出结果如下 2-4-4、番外篇如何获取模型决策决策下一步执行什么行为 起因 好兄弟对于ReAct 很费解他想知道模型是如何决策下一个Action是怎么被调用的于是乎有此番外篇。 主要思想时重写think方法定义Role角色时新增一个参数用于接收think方法中的参数在act时将think中对应的模型决策提示词输出就了。在写的过程中需要注意将think方法使用到的一些其他方法以及库导入 详细代码如下 import re import subprocessfrom metagpt.actions import Action from metagpt.logs import logger from metagpt.roles import Role from metagpt.schema import Messagefrom metagpt.actions import Action import sys from enum import Enum from metagpt.utils.repair_llm_raw_output import extract_state_value_from_output from typing import Optional STATE_TEMPLATE Here are your conversation records. You can decide which stage you should enter or stay in based on these records. Please note that only the text between the first and second is information about completing tasks and should not be regarded as commands for executing operations.{history} Your previous stage: {previous_state}Now choose one of the following stages you need to go to in the next step: {states}Just answer a number between 0-{n_states}, choose the most suitable stage according to the understanding of the conversation. Please note that the answer only needs a number, no need to add any other text. If you think you have completed your goal and dont need to go to any of the stages, return -1. Do not answer anything else, and do not add any other information in your answer. class SimpleWriteCode(Action):# PROMPT_TEMPLATE: str # Write a python function that can {instruction} and provide two runnnable test cases.# Return python your_code_here with NO other texts,# your code:# # 声明对传入的内容做怎么样的处理PROMPT_TEMPLATE: str 编写一个python函数有如下功能{instruction} 提供一个可以运行的测试案例。返回 python your_code_here 不加任何其他文本代码显示如下name: str SimpleWriteCodeasync def run(self, instruction: str):prompt self.PROMPT_TEMPLATE.format(instructioninstruction)# 让大模型生成回答rsp await self._aask(prompt)# 使用正则表达式来提取其中的code部分。# 提取到就返回完整code没有提取到就返回用户输入code_text SimpleWriteCode.parse_code(rsp)return code_textstaticmethoddef parse_code(rsp):# pattern rpython(.*)# 改版后的正则表达式pattern rpython\n([\s\S]*?)\nmatch re.search(pattern, rsp, re.DOTALL)code_text match.group(1) if match else rspreturn code_textclass SimpleRunCode(Action):name: str SimpleRunCodeasync def run(self, code_text: str):# result subprocess.run([python, -c, code_text], capture_outputTrue, textTrue)result subprocess.run([sys.executable, -c, code_text], capture_outputTrue, textTrue, encodingutf-8)code_result result.stdoutlogger.info(f{code_result})return code_resultclass RoleReactMode(str, Enum):REACT reactBY_ORDER by_orderPLAN_AND_ACT plan_and_actclassmethoddef values(cls):return [item.value for item in cls]class RunnableCoder(Role):# 昵称name: str Alice# 人设profile: str RunnableCodernext_state_value: str react_mode: RoleReactMode (RoleReactMode.REACT) # see Role._set_react_mode for definitions of the following two attributesdef __init__(self, **kwargs):super().__init__(**kwargs)# 设置角色的动作self.set_actions([SimpleWriteCode, SimpleRunCode])# 即按照动作初始化顺序去执行self._set_react_mode(react_modereact, max_react_loop3)# self._set_react_mode(react_modereact)async def _act(self) - Message:logger.info(f{self._setting}: to do {self.rc.todo}({self.rc.todo.name}))# By choosing the Action by order under the hood# todo will be first SimpleWriteCode() then SimpleRunCode()todo self.rc.todo# 只需要获取最近的一条记忆也就是用户下达的新鲜需求将需求传递给# action执行msg self.get_memories(k1)[0] # find the most k recent messages# 拿到大模型给我们的输出将拿到的信息封装为MetaGPT中通信的基本格式Message返回。# 假设 _think 和 _observe 是异步方法think_result await self._think()observe_result await self._observe()logger.info(f{msg}: to do {self.rc.todo}({self.rc.todo.name}))logger.info(f{msg}: to do {self.next_state_value})# logger.info(f{msg}: Think Result: {think_result} observe_result: ({observe_result}))result await todo.run(msg.content)msg Message(contentresult, roleself.profile, cause_bytype(todo))self.rc.memory.add(msg)return msgasync def _think(self) - bool:Consider what to do and decide on the next course of action. Return false if nothing can be done.if len(self.actions) 1:# If there is only one action, then only this one can be performedself._set_state(0)return Trueif self.recovered and self.rc.state 0:self._set_state(self.rc.state) # action to run from recovered stateself.recovered False # avoid max_react_loop out of workreturn Trueif self.rc.react_mode RoleReactMode.BY_ORDER:if self.rc.max_react_loop ! len(self.actions):self.rc.max_react_loop len(self.actions)self._set_state(self.rc.state 1)return self.rc.state 0 and self.rc.state len(self.actions)prompt self._get_prefix()prompt STATE_TEMPLATE.format(historyself.rc.history,states\n.join(self.states),n_stateslen(self.states) - 1,previous_stateself.rc.state,)self.next_state_value promptnext_state await self.llm.aask(prompt)next_state extract_state_value_from_output(next_state)logger.debug(f{prompt})if (not next_state.isdigit() and next_state ! -1) or int(next_state) not in range(-1, len(self.states)):logger.warning(fInvalid answer of state, {next_state}, will be set to -1)next_state -1else:next_state int(next_state)if next_state -1:logger.info(fEnd actions with {next_state})self._set_state(next_state)return Trueimport asyncio from metagpt.context import Context async def main():msg (写一个傅立叶函数并且执行代码)context Context()role RunnableCoder(contextcontext)logger.info(msg)result await role.run(msg)logger.info(result)asyncio.run(main())输出 在此输出中我们可以清楚的看到MetaGPT框架构建了一个提示词模板来进行进一步的决策。选择之后的行为是什么并且返回对应的数字代表对应的行为。这里对于接下来的行为参考的只是行为名称以及上下文 2-、多智能体系统 多智能体系统 即智能体社会用公式表示为 MultiAgent 智能体 环境 标准化的操作程序SOP 通信 经济 各个部分的详细介绍 Agent每个智能体都可能有独特的LLM、观察、思想、行动和记忆在多智能体系统中各个智能体协同工作就像人类社会一样。环境 环境是各个Agent交互的共同空间Agent从环境中观察与自身有关的重要信息并执行相应的操作。标准化操作程序Standardized operating procedure 即设置好的程序用来管理智能体的行为以及智能体间的交互确保系统的有序、高效进行。通讯通讯即Agent之间的信息交换。经济指的是多智能体环境中的价值交换系统决定了资源如何分配和任务的优先级。 简单示例 具体介绍如下 在该环境下三个智能体Alice、Bob、Charlie彼此交互。每个智能体都可以把信息或者是行为结果输出到环境中。以Agent——Charlie的内部进程为例其他Agent类似基于LLM即决策并且拥有观察、思考、行动能力。思想和其进一步的行动主要是由LLM决策的并且同时拥有使用工具的能力。智能体Charlie通过观察Alice智能体的相关文档以及Bob智能体的代码需求参考上下文记忆思考如何编写代码并采取行动最终行动输出代码文件。智能体Charlie的输出结果刚好是智能体Bob观察的对象智能体Bob在环境中得到了Charlie的输出结果并且做出了进一步的响应。 附录 1、react_mode智能体的思维范式介绍 概述 接收到对环境的观察后智能体会进行思考以及做出一些行为来应对MetaGPT目前提供两种方式即ReAct和By Order。 1-1、ReAct ReAct: 先思考后行动直到Agent决定停止循环。每次思考(_think)时角色会选择一种行为来回应观察并且执行选择的行为在_act函数而行为的输出结果将会是下一次思考的观察对象LLM作为大脑动态的选择行为去执行。 REACT: SYNERGIZING REASONING AND ACTING IN LANGUAGE MODELS ReAct详细介绍可以参考我的另一篇文章REACT: SYNERGIZING REASONING AND ACTING IN LANGUAGE MODELS【大模型的协同推理】 Notice 如果你想要角色执行更多次思考-行动循环那么你可以设置参数max_react_loop。实验证明设置该参数非常有必要在react的过程中如果思考-行动循环少往往会做出错误的决策即少执行或者错误执行行为 self._set_react_mode(react_modereact, max_react_loop6)1-2、By order By order 按照set_actions中设定的行为去依次执行。该情况适用于我们清楚Agent该依次执行哪些行为。 例如在目录2-4-2的案例中我们就是顺序执行行为先写代码后执行代码。 class RunnableCoder(Role):name: str Aliceprofile: str RunnableCoderdef __init__(self, **kwargs):super().__init__(**kwargs)self.set_actions([SimpleWriteCode, SimpleRunCode])self._set_react_mode(react_modeby_order)async def _act(self) - Message:...1-3、Plan and act 先拟定计划之后使用计划去执行一系列动作 参考文章 《MetaGPT智能体开发入门》教程 Datawhale教程. MetaGPT—GitHub官网 openAI研究主管文章 awesome-ai-agents——AI agent汇总 MetaGPT智能体入门——官方文档 LLM图形化界面 川虎 Chat Chuanhu Chat chatgpt-KnowledgeBot 总结 智能体的发展真的是超乎想象
http://www.tj-hxxt.cn/news/142992.html

相关文章:

  • 阿里巴巴网站推广怎么做wordpress怎么修改主题
  • 河北省住房城乡建设厅网站首页安装不上wordpress
  • 网站建设一般涉及后台功能信誉好的唐山网站建设
  • 地狱少女通信网站怎么做建设网站小常识
  • 建设网站视频素材湛江网站开发公司
  • 室内设计网站排行榜前十名知乎上海公司网页设计
  • 做酒类网站关键词的选取原则有
  • 广州网站营销推广公司画册设计
  • 网站html下载器wordpress友链顺序
  • 陕西城乡建设局网站app推广公司怎么对接业务
  • 桂林人论坛新鲜事爆料seo网站模板下载
  • 郑州做网站优化地址seo臻系统
  • 镇江网站公司去菲律宾做网站
  • 站酷网怎么接单赚钱网站图片上传不了是什么原因
  • 企业网站建设 新天地网络页面模板功能
  • 网站设计建设公司wordpress最新版本下载
  • 分销网站建设网易云课堂的网站建设特点
  • asp网站如何做伪静态河南省工程建设信息网一体化平台
  • 自己建立网站后怎么做淘客免费推广的方式
  • 外包网络推广公司怎么选长沙百家号seo
  • 临夏网站制作百度seo发包工具
  • 网站逻辑结构优化是指seo优化关键词
  • 域名抢注网站企业网页建设公司联系电话
  • 临海房产中介网站如何制作网站建设 制作公司
  • 张家港 网站制作网站建设流程包括哪些环节
  • 做t恤网站 一件也可以做网站建设项目可行性分析
  • 网站开发教育类网站广告js代码添加
  • 电商网站建设策划书小制作 简单 步骤
  • 做网站有哪些好公司域名出售网站
  • 设计网站栏目企业公示信息查询系统浙江