828华为云征文 | 云服务器Flexus X实例:多智能体对话框架 AutoGen 部署和实例运行

目录

一、什么是多智能体?

[二、什么是 AutoGen?](#二、什么是 AutoGen?)

[三、部署 AutoGen](#三、部署 AutoGen)

[3.1 更新 apt 软件源](#3.1 更新 apt 软件源)

[3.2 安装 python 3.10](#3.2 安装 python 3.10)

[3.3 安装 AutoGen](#3.3 安装 AutoGen)

[3.4 安装 AutoGen Studio](#3.4 安装 AutoGen Studio)

[四、运行 AutoGen Studio](#四、运行 AutoGen Studio)

五、实例展示

[5.1 构建实例](#5.1 构建实例)

[5.2 运行](#5.2 运行)

六、总结


在体验了华为云的 Flexus云服务器X实例后,感受到其卓越的性能和灵活性,通过弹性伸缩服务和负载均衡,能够轻松应对市场的瞬息万变,确保业务的连续性和稳定性。数据的可靠性和安全性也得到了极大的保障,华为云数据库服务和网络安全服务的结合,让数据存储和业务运行更加安全无忧。

对于个人开发者和测试人员来说,Flexus云服务器X实例 的按需计费模式极大地降低了成本,同时提供了高可用性和可靠性,体验上可以媲美自建环境。全栈的开发测试工具链更是提升了开发效率,让创新和迭代变得更加迅速,点击这里体验~

下面就来一起体验下吧!

一、什么是多智能体?

多智能体系统是由多个智能体精妙组合而成的集合体,其核心宗旨在于将庞大且复杂的系统解构为一系列小型、高度互联、且能自主通信与协同工作的子系统,从而显著提升系统的可管理性与灵活性。这一领域的研究深入探索了智能体的认知知识、追求目标、掌握技能、规划路径,以及如何通过高效的协调机制促使它们共同行动以解决复杂问题。

二、什么是 AutoGen?

AutoGen 是一个开源编程框架,用于构建 AI 代理并促进多个代理之间的协作以解决任务。AutoGen 旨在简化代理 AI 的开发和研究,就像 PyTorch 对深度学习所做的那样。它提供的功能包括能够相互交互的代理、促进使用各种大型语言模型 (LLM) 和工具使用支持、自主和人机交互工作流程以及多代理对话模式。

三、部署 AutoGen

3.1 更新 apt 软件源

首先,更新下云服务器的 apt 软件源,执行如下命令更新。

bash 复制代码
root@flexusx-7305:~# sudo apt update
Hit:1 http://repo.huaweicloud.com/ubuntu focal InRelease
Get:2 http://repo.huaweicloud.com/ubuntu focal-updates InRelease [128 kB]
Hit:3 http://repo.huaweicloud.com/ubuntu focal-backports InRelease               
Hit:4 http://repo.huaweicloud.com/ubuntu focal-security InRelease          
Ign:5 https://download.docker.com/linux/ubuntu focal InRelease             
Get:6 http://repo.huaweicloud.com/ubuntu focal-updates/main amd64 Packages [3,563 kB]
Err:7 https://download.docker.com/linux/ubuntu focal Release                                     
  Could not handshake: Error in the pull function. [IP: 18.155.68.38 443]
Get:8 http://repo.huaweicloud.com/ubuntu focal-updates/universe i386 Packages [807 kB]           
Get:9 http://repo.huaweicloud.com/ubuntu focal-updates/universe amd64 Packages [1,231 kB]
Hit:10 https://packages.redis.io/deb focal InRelease                                        
Reading package lists... Done

执行如下命令安装 software-properties-common。

bash 复制代码
root@flexusx-7305:~# sudo apt install software-properties-common

3.2 安装 python 3.10

添加 ppa:deadsnakes/ppa,如下所示。

bash 复制代码
root@flexusx-7305:~# sudo add-apt-repository ppa:deadsnakes/ppa

AutoGen 需要 python 3.9 以上的版本,本文安装 python 3.10,如下所示。

bash 复制代码
root@flexusx-7305:~# sudo apt install python3.10
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  redis-server redis-tools
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libpython3.10-minimal libpython3.10-stdlib python3.10-minimal
Suggested packages:
  python3.10-venv binfmt-support
The following NEW packages will be installed:
  libpython3.10-minimal libpython3.10-stdlib python3.10 python3.10-minimal
0 upgraded, 4 newly installed, 0 to remove and 33 not upgraded.
Need to get 5,221 kB of archives.
After this operation, 20.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 libpython3.10-minimal amd64 3.10.15-1+focal1 [825 kB]
Get:2 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.10-minimal amd64 3.10.15-1+focal1 [2,077 kB]
Get:3 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 libpython3.10-stdlib amd64 3.10.15-1+focal1 [1,763 kB]
Get:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.10 amd64 3.10.15-1+focal1 [556 kB]
Fetched 5,221 kB in 3s (1,707 kB/s) 
Selecting previously unselected package libpython3.10-minimal:amd64.
(Reading database ... 117364 files and directories currently installed.)
Preparing to unpack .../libpython3.10-minimal_3.10.15-1+focal1_amd64.deb ...
Unpacking libpython3.10-minimal:amd64 (3.10.15-1+focal1) ...
Selecting previously unselected package python3.10-minimal.
Preparing to unpack .../python3.10-minimal_3.10.15-1+focal1_amd64.deb ...
Unpacking python3.10-minimal (3.10.15-1+focal1) ...
Selecting previously unselected package libpython3.10-stdlib:amd64.
Preparing to unpack .../libpython3.10-stdlib_3.10.15-1+focal1_amd64.deb ...
Unpacking libpython3.10-stdlib:amd64 (3.10.15-1+focal1) ...
Selecting previously unselected package python3.10.
Preparing to unpack .../python3.10_3.10.15-1+focal1_amd64.deb ...
Unpacking python3.10 (3.10.15-1+focal1) ...
Setting up libpython3.10-minimal:amd64 (3.10.15-1+focal1) ...
Setting up python3.10-minimal (3.10.15-1+focal1) ...
Setting up libpython3.10-stdlib:amd64 (3.10.15-1+focal1) ...
Setting up python3.10 (3.10.15-1+focal1) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...
root@flexusx-7305:~#

创建 python 软连接,让 /usr/bin/python 指向 /usr/bin/python3.10,如果 python3 命令不是 3.10 版本,同样也需要创建软连接,然后查看 python 版本,如下所示。

bash 复制代码
root@flexusx-7305:~# ln -s /usr/bin/python3.10 /usr/bin/python 
root@flexusx-7305:~# python --version
Python 3.10.15
root@flexusx-7305:~#

安装 python3.10-venv 用于创建 python 虚拟环境,如下所示。

bash 复制代码
root@flexusx-7305:~# apt install python3.10-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  redis-server redis-tools
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  python3.10-distutils python3.10-lib2to3
The following NEW packages will be installed:
  python3.10-distutils python3.10-lib2to3 python3.10-venv
0 upgraded, 3 newly installed, 0 to remove and 33 not upgraded.
Need to get 3,243 kB of archives.
After this operation, 4,528 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.10-lib2to3 all 3.10.15-1+focal1 [126 kB]
Get:2 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.10-distutils all 3.10.15-1+focal1 [187 kB]
Get:3 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.10-venv amd64 3.10.15-1+focal1 [2,931 kB]
Fetched 3,243 kB in 4s (880 kB/s)            
Selecting previously unselected package python3.10-lib2to3.
(Reading database ... 118026 files and directories currently installed.)
Preparing to unpack .../python3.10-lib2to3_3.10.15-1+focal1_all.deb ...
Unpacking python3.10-lib2to3 (3.10.15-1+focal1) ...
Selecting previously unselected package python3.10-distutils.
Preparing to unpack .../python3.10-distutils_3.10.15-1+focal1_all.deb ...
Unpacking python3.10-distutils (3.10.15-1+focal1) ...
Selecting previously unselected package python3.10-venv.
Preparing to unpack .../python3.10-venv_3.10.15-1+focal1_amd64.deb ...
Unpacking python3.10-venv (3.10.15-1+focal1) ...
Setting up python3.10-lib2to3 (3.10.15-1+focal1) ...
Setting up python3.10-distutils (3.10.15-1+focal1) ...
Setting up python3.10-venv (3.10.15-1+focal1) ...

创建用于部署 AutoGen 的虚拟环境,执行如下命令。

bash 复制代码
root@flexusx-7305:~# python3 -m venv autogentest
root@flexusx-7305:~# source autogentest/bin/activate
(autogentest) root@flexusx-7305:~#

3.3 安装 AutoGen

进入环境 AutoGen,执行命令安装 AutoGen,如下所示。

bash 复制代码
(autogentest) root@flexusx-7305:~# pip install autogen
Collecting autogen
  Downloading autogen-0.3.0-py3-none-any.whl (345 kB)
     |████████████████████████████████| 345 kB 968 kB/s 
Collecting openai>=1.3
  Using cached openai-1.45.0-py3-none-any.whl (374 kB)
Collecting docker
  Downloading docker-7.1.0-py3-none-any.whl (147 kB)
     |████████████████████████████████| 147 kB 17.6 MB/s 
Collecting diskcache
  Using cached diskcache-5.6.3-py3-none-any.whl (45 kB)
Collecting flaml
  Using cached FLAML-2.2.0-py3-none-any.whl (297 kB)
Collecting termcolor
  Using cached termcolor-2.4.0-py3-none-any.whl (7.7 kB)
Collecting numpy<2,>=1.17.0
  Using cached numpy-1.24.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
Collecting pydantic!=2.6.0,<3,>=1.10
  Using cached pydantic-2.9.1-py3-none-any.whl (434 kB)
Collecting tiktoken
  Using cached tiktoken-0.7.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB)
Collecting python-dotenv
  Using cached python_dotenv-1.0.1-py3-none-any.whl (19 kB)
Collecting packaging
  Using cached packaging-24.1-py3-none-any.whl (53 kB)
Collecting httpx<1,>=0.23.0
  Using cached httpx-0.27.2-py3-none-any.whl (76 kB)
Collecting jiter<1,>=0.4.0
  Using cached jiter-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (319 kB)

查看 AutoGen 版本,执行如下命令查看。

bash 复制代码
(autogentest) root@flexusx-7305:~# pip list | grep autogen
autogen            0.3.0    
(autogentest) root@flexusx-7305:~#

3.4 安装 AutoGen Studio

执行 wget 命令下载 autogenstudio 包,或者执行 pip install autogenstudio,如下所示。

bash 复制代码
(autogentest) root@flexusx-7305:~# wget https://files.pythonhosted.org/packages/4c/ec/adb715c79656b18b31bfdfbc0253f7f4486b22fd7f7f3a21234bf5d0597c/autogenstudio-0.1.5-py3-none-any.whl
--2024-09-15 11:55:58--  https://files.pythonhosted.org/packages/4c/ec/adb715c79656b18b31bfdfbc0253f7f4486b22fd7f7f3a21234bf5d0597c/autogenstudio-0.1.5-py3-none-any.whl
Resolving files.pythonhosted.org (files.pythonhosted.org)... 151.101.88.223, 2a04:4e42:15::223
Connecting to files.pythonhosted.org (files.pythonhosted.org)|151.101.88.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4434948 (4.2M) [application/octet-stream]
Saving to: 'autogenstudio-0.1.5-py3-none-any.whl'

autogenstudio-0.1.5-py3-none-any.whl                            100%[====================================================================================================================================================>]   4.23M  6.43MB/s    in 0.7s    

2024-09-15 11:55:59 (6.43 MB/s) - 'autogenstudio-0.1.5-py3-none-any.whl' saved [4434948/4434948]

pip 安装 autogenstudio,如下所示。

bash 复制代码
(autogentest) root@flexusx-7305:~# pip install autogenstudio-0.1.5-py3-none-any.whl 
Processing ./autogenstudio-0.1.5-py3-none-any.whl
Collecting arxiv
  Downloading arxiv-2.1.3-py3-none-any.whl (11 kB)
Collecting pydantic
  Using cached pydantic-2.9.1-py3-none-any.whl (434 kB)
Collecting numpy<2.0.0
  Downloading numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 49.9 MB/s eta 0:00:00
Collecting sqlmodel
  Downloading sqlmodel-0.0.22-py3-none-any.whl (28 kB)
Collecting fastapi
  Downloading fastapi-0.114.2-py3-none-any.whl (94 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 94.0/94.0 kB 864.9 kB/s eta 0:00:00
Collecting typer
  Downloading typer-0.12.5-py3-none-any.whl (47 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 47.3/47.3 kB 3.9 MB/s eta 0:00:00
Collecting alembic
  Downloading alembic-1.13.2-py3-none-any.whl (232 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 233.0/233.0 kB 3.1 MB/s eta 0:00:00
Collecting loguru
  Downloading loguru-0.7.2-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.5/62.5 kB 13.6 MB/s eta 0:00:00

至此,所有部署工作完成。

四、运行 AutoGen Studio

启动 AutoGen Studio,指定端口,如下所示。

bash 复制代码
(autogentest) root@flexusx-7305:~# autogenstudio ui --host 0.0.0.0 --port 3001
2024-09-15 14:22:26.963 | INFO     | autogenstudio.utils.utils:get_db_uri:253 - Using database URI: sqlite:root/.autogenstudio/database.sqlite
2024-09-15 14:22:26.963 | INFO     | autogenstudio.utils.utils:init_app_folders:288 - Initialized application data folder: /root/.autogenstudio
INFO:     Started server process [153974]
INFO:     Waiting for application startup.
***** App started *****
2024-09-15 14:22:27.006 | INFO     | autogenstudio.database.utils:init_db_samples:148 - Database already initialized with Default and Travel Planning Workflows
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:3001 (Press CTRL+C to quit)

访问 http://服务器IP:3001,界面如下所示。

点击 Build 按钮,进入构建页面,如下所示。

下面通过展示实例测试多智能体交互。

五、实例展示

5.1 构建实例

创建 test.py 文件,复制如下代码。

bash 复制代码
import os
from autogen import AssistantAgent, UserProxyAgent

llm_config =     {
        "model": "<model name>",
        "api_key": "<API_KEY>",
        "base_url": "<BASE_URL>"
    }
assistant = AssistantAgent("assistant", 
                           llm_config=llm_config
                           )
user_proxy = UserProxyAgent("user_proxy", 
                            llm_config=False,
                            human_input_mode="NEVER",
                            code_execution_config=False)

# 开始对话
chat_result = user_proxy.initiate_chat(
    assistant,
    message="北京有哪些景点?",
    max_turns=2
)

其中,<model name> 需要替换为模型名称,<API_KEY> 为密钥,<BASE_URL> 为基础 URL,API 需要兼容 OpenAI API。

5.2 运行

执行 python test.py 运行代码,如下所示。

bash 复制代码
(autogentest) root@flexusx-7305:~# python test.py
user_proxy (to assistant):

北京有哪些景点?

--------------------------------------------------------------------------------
assistant (to user_proxy):

北京是中国的首都,拥有丰富的历史遗产和文化景点。其中一些最著名的景点包括:

*   故宫:清朝的皇宫,也是世界上最大的宫殿建筑群。
*   天安门广场: мире 最大的城市广场之一,是许多重要事件的发生地。
*   长城:世界上最长的墙,也是中国最著名的景点之一。
*  juven]).
*   颐和园:清朝皇帝的夏宫,被誉为"中国园林之母"。
*   圆明园:清朝皇帝的私家园林,也是中国最大的园林之一。
*   天坛:明清两代皇帝在这里祭祀天地和祖先的场所。
*   东城区:位于北京中心的商业区,拥有众多高档购物商场和餐厅。
*   西单:北京最繁华的购物街之一。
*   北京奥林匹克公园:2008年北京奥运会的举办地,内有鸟巢等标志性建筑。

--------------------------------------------------------------------------------
(autogentest) root@flexusx-7305:~#

六、总结

通过深入探索并充分体验 "Flexus云服务器X实例 " 后,顺利部署了AutoGen 及其配套的开发环境 AutoGen Studio ,并展示了其高效运行的成果。此次实践不仅突显了 Flexus云服务器X实例 在部署与应用上的便捷与高效特性,更以其丝滑无阻的操作体验,让即便是技术新手也能迅速掌握,日常运维工作因此变得前所未有的轻松与高效。对于渴望在代码管理领域实现高效与流畅体验的用户而言,Flexus云服务器X实例 无疑是一个不容错过的理想之选。立即行动,亲身体验其卓越性能与便捷管理带来的无限可能!

相关推荐
IT民工金鱼哥2 天前
【华为云-云驻共创】UCS跨云多活容灾:让业务高可用不再是难题
华为云
知孤云出岫4 天前
华为云计算知识总结——及案例分享
华为·华为云·云计算
大数据AI人工智能培训专家培训讲师叶梓4 天前
自适应对话式团队构建,提升语言模型代理的复杂任务解决能力
人工智能·语言模型·自然语言处理·chatgpt·大模型·agent·智能体
嘟嘟Listing4 天前
华为云安装docker
docker·容器·华为云
博客园团队4 天前
又给会员送福利,100台一年华为云2核2G3M云服务器
华为云
三掌柜6665 天前
鸿蒙原生应用开发及部署:首选华为云,开启HarmonyOS NEXT App新纪元
华为·华为云·harmonyos·鸿蒙·1024程序员节
shiming88795 天前
GaussDB Ustore存储引擎解读
华为云·gaussdb ustore
wangye114226 天前
共创一带一路经济体,土耳其海外媒体软文发稿 - 媒体宣发报道
大数据·人工智能·华为云·游戏引擎·产品运营
荔枝学Python7 天前
一文总结AI智能体与传统RPA机器人的16个关键区别
人工智能·自然语言处理·机器人·大模型·agent·rpa·ai智能体