AutoGen实现多代理—AI Agentic Design Patterns with AutoGen(二)

news2024/9/29 14:06:19

1. AutoGen顺序对话在客户入职案例上的应用

在这里插入图片描述
如图,客户入职前会经历三个阶段,一个代理收集客户的信息,一个代理收集客户的感兴趣话题,一个代理根据前两个代理的基础信息与客户代理对话,产生聊天信息。

本节实验的地址:传送门

2. 代码实践

2.1 准备环境

llm_config={"model": "gpt-3.5-turbo"}

from autogen import ConversableAgent

2.2 构建Agent

# 创建获取用户信息的Agent,包括名字和地址
onboarding_personal_information_agent = ConversableAgent(
    name="Onboarding Personal Information Agent",
    system_message='''You are a helpful customer onboarding agent,
    you are here to help new customers get started with our product.
    Your job is to gather customer's name and location.
    Do not ask for other information. Return 'TERMINATE' 
    when you have gathered all the information.''',
    llm_config=llm_config,
    code_execution_config=False,
    human_input_mode="NEVER",
)
# 创建获取用户话题的Agent
onboarding_topic_preference_agent = ConversableAgent(
    name="Onboarding Topic preference Agent",
    system_message='''You are a helpful customer onboarding agent,
    you are here to help new customers get started with our product.
    Your job is to gather customer's preferences on news topics.
    Do not ask for other information.
    Return 'TERMINATE' when you have gathered all the information.''',
    llm_config=llm_config,
    code_execution_config=False,
    human_input_mode="NEVER",
)
# 创建与客户交互的Agent,基于客户提供的基础信息
customer_engagement_agent = ConversableAgent(
    name="Customer Engagement Agent",
    system_message='''You are a helpful customer service agent
    here to provide fun for the customer based on the user's
    personal information and topic preferences.
    This could include fun facts, jokes, or interesting stories.
    Make sure to make it engaging and fun!
    Return 'TERMINATE' when you are done.''',
    llm_config=llm_config,
    code_execution_config=False,
    human_input_mode="NEVER",
    is_termination_msg=lambda msg: "terminate" in msg.get("content").lower(),
)
# 创建客户代理Agent
customer_proxy_agent = ConversableAgent(
    name="customer_proxy_agent",
    llm_config=False,
    code_execution_config=False,
    human_input_mode="ALWAYS",
    is_termination_msg=lambda msg: "terminate" in msg.get("content").lower(),
)

2.3 创建任务

现在,你可以制定一系列任务来促进新用户的入职流程。

chats = [
    {
        "sender": onboarding_personal_information_agent,
        "recipient": customer_proxy_agent,
        "message": 
            "Hello, I'm here to help you get started with our product."
            "Could you tell me your name and location?",
        "summary_method": "reflection_with_llm",
        "summary_args": {
            "summary_prompt" : "Return the customer information "
                             "into as JSON object only: "
                             "{'name': '', 'location': ''}",
        },
        "max_turns": 2,
        "clear_history" : True
    },
    {
        "sender": onboarding_topic_preference_agent,
        "recipient": customer_proxy_agent,
        "message": 
                "Great! Could you tell me what topics you are "
                "interested in reading about?",
        "summary_method": "reflection_with_llm",
        "max_turns": 1,
        "clear_history" : False
    },
    {
        "sender": customer_proxy_agent,
        "recipient": customer_engagement_agent,
        "message": "Let's find something fun to read.",
        "max_turns": 1,
        "summary_method": "reflection_with_llm",
    },
]

2.4 开始对话

from autogen import initiate_chats

chat_results = initiate_chats(chats)

执行阶段包含面板交互,提示输入用户的名字、地址和感兴趣的话题,输出如下:

********************************************************************************
Starting a new chat....

********************************************************************************
Onboarding Personal Information Agent (to customer_proxy_agent):

Hello, I'm here to help you get started with our product.Could you tell me your name and location?

--------------------------------------------------------------------------------
Provide feedback to Onboarding Personal Information Agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: Alice
customer_proxy_agent (to Onboarding Personal Information Agent):

Alice

--------------------------------------------------------------------------------
Onboarding Personal Information Agent (to customer_proxy_agent):

Thank you, Alice. Could you also let me know your location, please?

--------------------------------------------------------------------------------
Provide feedback to Onboarding Personal Information Agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: new york
customer_proxy_agent (to Onboarding Personal Information Agent):

new york

--------------------------------------------------------------------------------

********************************************************************************
Starting a new chat....

********************************************************************************
Onboarding Topic preference Agent (to customer_proxy_agent):

Great! Could you tell me what topics you are interested in reading about?
Context: 
{
  "name": "Alice",
  "location": "New York"
}

--------------------------------------------------------------------------------
Provide feedback to Onboarding Topic preference Agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: dog
customer_proxy_agent (to Onboarding Topic preference Agent):

dog

--------------------------------------------------------------------------------

********************************************************************************
Starting a new chat....

********************************************************************************
customer_proxy_agent (to Customer Engagement Agent):

Let's find something fun to read.
Context: 
{
  "name": "Alice",
  "location": "New York"
}
Alice is interested in reading about dogs.

--------------------------------------------------------------------------------
Customer Engagement Agent (to customer_proxy_agent):

Hey Alice from New York! I hope you're ready for a paw-some time because we are diving into the wonderful world of dogs! Did you know that the world's oldest known breed of domesticated dog is the Saluki, which is originally from Egypt? These elegant and swift hounds have been mankind's loyal companions for over 4,000 years!

Dogs truly are incredible creatures with so much to offer. Whether they are bounding through fields, snuggling on the couch, or just giving us those heart-melting puppy dog eyes, they never fail to bring joy and love into our lives. So, grab a cozy spot and get ready to explore the fascinating world of our four-legged friends!

TERMINATE

--------------------------------------------------------------------------------

2.5 打印摘要

for chat_result in chat_results:
    print(chat_result.summary)
    print("\n")

输出如下:

{
  "name": "Alice",
  "location": "New York"
}


Alice is interested in reading about dogs.


Alice from New York is interested in reading about dogs. She is about to dive into the wonderful world of dogs, learning about the world's oldest known breed, the Saluki, and the joy and love that dogs bring into our lives.

2.6 打印花费

for chat_result in chat_results:
    print(chat_result.cost)
    print("\n")

输出如下:

{'usage_including_cached_inference': {'total_cost': 0.0001405, 'gpt-3.5-turbo-0125': {'cost': 0.0001405, 'prompt_tokens': 182, 'completion_tokens': 33, 'total_tokens': 215}}, 'usage_excluding_cached_inference': {'total_cost': 0.0001405, 'gpt-3.5-turbo-0125': {'cost': 0.0001405, 'prompt_tokens': 182, 'completion_tokens': 33, 'total_tokens': 215}}}


{'usage_including_cached_inference': {'total_cost': 4.55e-05, 'gpt-3.5-turbo-0125': {'cost': 4.55e-05, 'prompt_tokens': 67, 'completion_tokens': 8, 'total_tokens': 75}}, 'usage_excluding_cached_inference': {'total_cost': 4.55e-05, 'gpt-3.5-turbo-0125': {'cost': 4.55e-05, 'prompt_tokens': 67, 'completion_tokens': 8, 'total_tokens': 75}}}


{'usage_including_cached_inference': {'total_cost': 0.000453, 'gpt-3.5-turbo-0125': {'cost': 0.000453, 'prompt_tokens': 324, 'completion_tokens': 194, 'total_tokens': 518}}, 'usage_excluding_cached_inference': {'total_cost': 0.000453, 'gpt-3.5-turbo-0125': {'cost': 0.000453, 'prompt_tokens': 324, 'completion_tokens': 194, 'total_tokens': 518}}}

3. 总结

本篇讲述了AutoGen实现多代理之间按照顺序对话的过程,并最终根据上下文产生输出结果。体现了多代理之间协作的设计模式。

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

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

相关文章

基于SSM+小程序的会议发布与预约管理系统(会议1)(源码+sql脚本+视频导入教程+文档)

👉文末查看项目功能视频演示获取源码sql脚本视频导入教程视频 1、项目介绍 本基于微信小程序的会议发布与预约系统管理员功能有个人中心,发布者管理,用户管理,发布会议管理,会议预约管理,留言板管理&…

C++远端开发环境手动编译安装(centos7)

背景 直接使用yum安装,无法安装指定的版本,因为很多版本并没有在镜像仓库中,所以此处进行手动安装指定版本 使用VMWare安装centos7 准备centos镜像 可以自行搜索下载地址,阿里云的也可以 下载VmWare,社区版即可 可…

【第十四周】PyTorch深度学习实践1

目录 摘要Abstract1.反向传播2.线性回归2.1.准备数据集2.2.设计模型2.3.定义损失函数和优化器2.4.模型训练 3.逻辑回归4.处理多维特征的输入5.加载数据集5.1.导入必要的库5.2.准备数据集5.3.定义模型5.4.构建损失函数和优化器5.5.训练模型 总结 摘要 本周主要通过B站刘二大人的…

酒店新科技,飞睿智能毫米波雷达人体存在感应器,智能照明创新节能新风尚

在这个日新月异的时代,科技正以未有的速度改变着我们的生活。从智能手机到智能家居,每一个细微之处都渗透着科技的魅力。而今,这股科技浪潮已经席卷到了酒店行业,为传统的住宿体验带来了翻天覆地的变化。其中,引人注目…

基于SpringBoot+Vue的茶园茶农文化交流平台

作者:计算机学姐 开发技术:SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等,“文末源码”。 专栏推荐:前后端分离项目源码、SpringBoot项目源码、Vue项目源码、SSM项目源码 精品专栏:Java精选实战项目…

对已经运行的flask服务测试代码覆盖率

上一篇文章《用pytest-cov获取flask项目的测试代码覆盖率》展示了用pytest的测试用例验证flask的函数,获取代码覆盖率信息。但是上述方法要求web服务没有提前启动,而是由pytest来启动,然后运行测试用例。 那么对于已经启动的web服务&#xff…

【STM32-HAL库】MQ2烟雾传感器使用(STM32F407ZET6)

MQ2可燃气体传感器介绍 MQ2是一种广谱气体传感器,能够检测多种可燃气体和烟雾。它是一种低成本、高灵敏度的传感器,广泛应用于家庭和工业环境中的气体监测。 原理 MQ2传感器的工作原理基于金属氧化物半导体(MOX)技术。当传感器暴露…

俄罗斯市场合格评定准入认证要求

前言 国内厂家想要把自己的产品顺利出口到俄罗斯市场,就需要基本了解俄罗斯的市场合格评定准入要求。俄罗斯主要实行的认证有EAC(TR-CU/CU-TR)认证、GOST R认证、计量认证和医疗产品国家注册。下面就分别简单介绍一下这几个产品认证。 一、EAC(TR-CU/CU-TR)认证介绍…

LVGL 笔记

在显示GUI的过程中需要对某些对象进行临时隐藏或临时显示,因此需要对该对象的FLAG进行配置就可以实现对象的显示和隐藏了. lv_obj_add_flag(user_obj, LV_OBJ_FLAG_HIDDEN);//隐藏对象 lv_obj_clear_flag(user_obj, LV_OBJ_FLAG_HIDDEN);//取消隐藏 GUI-Guider 中的选项卡 注意…

Linux驱动开发(速记版)--驱动基础

第一章 初识内核源码 Linux系统源码提供了操作系统的核心功能,如进程管理、内存管理、文件系统等。 BusyBox这类的文件系统构建工具,则提供了在这些核心功能之上运行的一系列实用工具和命令,使得用户能够执行常见的文件操作、文本处理、网络配…

MaxKB知识库问答系统入选Gitee最有价值开源项目

2024年9月19日,飞致云旗下开源项目MaxKB成功加入Gitee平台主导的GVP计划,入选2024年GVP——Gitee最有价值开源项目。MaxKB也是继MeterSphere、DataEase和1Panel之后,飞致云旗下第四个入选GVP的开源项目。 ▲图1 MaxKB入选2024年Gitee最有价值…

软机器人咋模仿生物?响应式水凝胶Aquabots有啥用?快来了解一下!

大家好,今天我们要来了解一项关于响应式水凝胶Aquabots的研究——《Responsive‐Hydrogel Aquabots》发表于《Advanced Science》。在当今科技发展中,制造能像生物体一样具有响应适应性的软机器人是个挑战。而Aquabots为解决这个问题带来了新的突破。它通…

vue3项目执行pnpm update后还原package.json文件后运行报错

项目场景: vue官方版本已更新到vue3.5,项目中还在使用vue3.4,因此想要更新项目vue版本。 问题描述 执行了 pnpm update 命令,一键更新了所有包,更新完成后项目不能正常运行。为了还原项目代码,先删除 nod…

“AI+Security”系列第3期(七):智能体车企落地实践

近日,由安全极客、Wisemodel 社区、InForSec 网络安全研究国际学术论坛和海升集团联合主办的 “AI Security” 系列第 3 期技术沙龙 ——“AI 安全智能体,重塑安全团队工作范式” 活动顺利举行。此次活动备受关注,吸引了线上线下超过千名观众…

DriveVLM 论文学习

论文链接:https://arxiv.org/abs/2402.12289 解决了什么问题? 自动驾驶对交通行业有着革命性的作用,实现 FSD 的一个主要障碍就是场景理解。场景理解涉及在复杂且不可预测的环境中进行导航,这些环境可能包括恶劣的天气条件、复杂…

【Git】克隆主项目,并同时克隆所有子模块

子模块 带有箭头的文件夹(relaxed_ik_core)通常表示这是一个 Git 子模块(submodule)。Git 子模块是一种嵌入式的 Git 仓库,它允许你在一个仓库中引用其他的 Git 仓库。换句话说,relaxed_ik_core 不是这个项…

uniapp实战教程:如何封装一个可复用的表单组件

在uniapp开发过程中,表单组件的使用场景非常广泛。为了提高开发效率,我们可以将常用的表单组件进行封装。本文将带你了解如何在uniapp中封装一个表单组件,让你只需要通过属性配置轻松实现各种表单,效果图如下: 一、准备…

《北方牧业》是什么级别的期刊?是正规期刊吗?能评职称吗?

问题解答 问:《中国动物检疫》是不是核心期刊? 答:不是,是知网收录的正规学术期刊。 问:《中国动物检疫》级别? 答:省级。主管单位:河北省畜牧局 主办单…

【win11】关闭windows11系统的讲述人

如何关闭windows11系统的讲述人,经常误触启动 讲述人(Narrator) 设置里找到讲述人(Narrator) 开关讲述人及快捷键

物联网行业中天线定制的激光直接成型 (LDS)技术

01 什么是lds技术? 普通的手机天线都被安装在手机的主板上: 在当今的智能手机中,我们常见的手机天线通常都被巧妙地安装在手机的主板上。这些天线承担着接收和发送信号的重要任务,是实现通信功能的关键组件之一。 而 LDS 天线…