XAgent的部署及运行

源代码clone

git clone

config 文件的修改

在XAgent源码目录,运行 vi .env, 修改以下配置条目

CONFIG_FILE=assets/gpt-3.5-turbo_config.yml

python环境

python >=3.10

安装conda,通过conda激活python3.10的环境

wget https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh

# 修改执行权限
chmod 777 Anaconda3-2023.03-1-Linux-x86_64.sh

# 执行
./Anaconda3-2023.03-1-Linux-x86_64.sh

# 创建python3.10+ 的环境
conda create --name py310 python=3.10

#查看新创建的环境 
conda info --envs
# conda environments:
#
# base                  *  /root/anaconda3
# py310                    /root/anaconda3/envs/py310

# 激活py310环境
activate py310

# 重新进入shell后,查看python的版本
python --version

PIP

安装pip包

# 下载安装脚本
wget https://bootstrap.pypa.io/get-pip.py

# 运行安装脚本
python3 get-pip.py

docker的部署及运行

确保已安装docker,在XAgent源码目录,运行以下命令,从代码builddocker

docker compose build
# 如果不是第一次build,可以加上--no-cache参数,强制不使用缓存,否则build内容可能不会被更新
docker compose build --no-cache

看到以下提示时,运行完毕

=> [ 4/12] RUN apt update && apt install -y build-essential make openjdk-17-jdk-headless curl docker.io docker-compose psmisc sudo                                                                         41.5s
 => [ 5/12] RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple                                                                                                                     1.9s
 => [ 6/12] RUN pip install playwright && playwright install chromium &&  playwright install-deps                                                                                                           83.0s
 => [ 7/12] COPY ToolServer/ToolServerNode/requirements.txt .                                                                                                                                                0.1s
 => [ 8/12] RUN pip install --no-cache-dir -r requirements.txt                                                                                                                                             144.4s
 => [ 9/12] RUN rm -rf /tmp/* /var/tmp/*                                                                                                                                                                     0.4s
 => [10/12] COPY ToolServer/ToolServerNode .                                                                                                                                                                 0.1s 
 => [11/12] RUN mkdir -p assets                                                                                                                                                                              0.2s 
 => [12/12] RUN mkdir -p workspace                                                                                                                                                                           0.2s 
 => exporting to image                                                                                                                                                                                       9.8s 
 => => exporting layers                                                                                                                                                                                      9.8s
 => => writing image sha256:45e525fd5f2f9fbbb7679e96359934cd4b4a0658f6aaa39c0987718c87758b64                                                                                                                 0.0s
 => => naming to docker.io/xagentteam/toolserver-node:latest       

使用 docker images 命令查看,可以看到xagent的几个images已经出现在列表中

REPOSITORY                      TAG       IMAGE ID       CREATED          SIZE
xagentteam/toolserver-node      latest    45e525fd5f2f   18 minutes ago   3.75GB
xagentteam/xagent-server        latest    829edddf670b   19 minutes ago   1.29GB
xagentteam/toolserver-manager   latest    1fab5aa2bb99   22 minutes ago   1.03GB
xagentteam/toolserver-monitor   latest    803d4cd44e84   23 minutes ago   1.02GB

再运行

#  拉取的依赖容器并启动相应的服务
docker compose up

再使用 docker images 命令查看,依赖的images,比如redis,mongo,mysql也出现在列表中。在这里需要注意,系统中的某些端口不能被占用,比如3306,否则就会导致相应的应用启动失败

REPOSITORY                      TAG       IMAGE ID       CREATED          SIZE
xagentteam/toolserver-node      latest    45e525fd5f2f   23 minutes ago   3.75GB
xagentteam/xagent-server        latest    829edddf670b   24 minutes ago   1.29GB
xagentteam/toolserver-manager   latest    1fab5aa2bb99   28 minutes ago   1.03GB
xagentteam/toolserver-monitor   latest    803d4cd44e84   28 minutes ago   1.02GB
redis                           latest    76506809a39f   9 days ago       138MB
mongo                           latest    5acb2131d51f   11 days ago      757MB
mysql                           latest    f7fdab215ab7   7 weeks ago      605MB

同时,一些容器也会在系统中创建成功,可以使用docker ps --no-trunc查看(我的这个列表中mysql容器因为端口原因就启动失败了,需要更改被占用的端口后重启)

[root@opencloudos XAgent-1.0.0]# docker ps --no-trunc
                                NAMES
0c28937576b3036d988d8075c23ca5fa2acd952b0719879e2fd5301d463192bb   xagentteam/toolserver-node:0.2         "uvicorn main:app --host 0.0.0.0 --port 31942"                                                                                                      19 minutes ago   Up 19 minutes (healthy)   31942/tcp                                                                              friendly_darwin
3cf4eb9a46caf8bc774ad731a2dae9f6dffaf67ef6da85b5f8198a117f766dd0   xagentteam/xagent-server:latest        "python start_server.py"                                                                                                                            21 minutes ago   Up 21 minutes             0.0.0.0:5173->5173/tcp, :::5173->5173/tcp, 0.0.0.0:8090->8090/tcp, :::8090->8090/tcp   XAgent-Server
ede01c59c67f61dbbe7e16b984447fcdb9c65df39da264085dc001abb9b31b83   xagentteam/toolserver-node:latest      "uvicorn main:app --host 0.0.0.0 --port 31942"                                                                                                      21 minutes ago   Up 21 minutes             31942/tcp                                                                              xagent-main-ToolServerNode-1
8c5b52f2d082ed74603fa01bf75fbbbdd44301d482843c6e59dbda4f03b25347   xagentteam/toolserver-manager:latest   "gunicorn main:app -b 0.0.0.0:8080 --worker-class uvicorn.workers.UvicornWorker --workers 2 -t 600"                                                 21 minutes ago   Up 21 minutes (healthy)   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp                                              xagent-main-ToolServerManager-1
0c19c715098a7b719eeb427c13f3b0ddc6eacbf059df07bae36553aefc66170e   xagentteam/toolserver-node:0.2         "uvicorn main:app --host 0.0.0.0 --port 31942"                                                                                                      8 hours ago      Up 8 hours (healthy)      31942/tcp                                                                              nice_diffie
41f1b764cbdfce3fe7d2dfad75f90fdaca9e3abd660c8942b040268f4bcb1a34   xagentteam/toolserver-node:0.2         "uvicorn main:app --host 0.0.0.0 --port 31942"                                                                                                      11 hours ago     Up 11 hours (healthy)     31942/tcp                                                                              eager_greider
1a2bfe7c41fad33417ae9528135d3a46c9c24465fc934e5cf9228e8002762de7   mysql                                  "docker-entrypoint.sh --default-authentication-plugin=caching_sha2_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci"   11 hours ago     Up 8 hours (healthy)      0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                   xagent-main-xagent-mysql-1
379d82d0c10df5ef2933acffc6529569a390bbd5f79cc4abdd2149ee42ff435a   redis                                  "docker-entrypoint.sh redis-server --requirepass xagent"                                                                                            11 hours ago     Up 8 hours (healthy)      0.0.0.0:6379->6379/tcp, :::6379->6379/tcp                                              xagent-main-xagent-redis-1


如果顺利启动,则可以看到以下提示:

INFO:     Register env WebEnv with 2 tools!
xagent-100-ToolServerNode-1     | INFO:     Register env PythonNotebook with 2 tools!
xagent-100-ToolServerNode-1     | INFO:     Register env FileSystemEnv with 3 tools!
xagent-100-ToolServerNode-1     | INFO:     Register tool shell_command_executor!
xagent-100-ToolServerNode-1     | INFO:     Loaded 8 tools and 3 envs!
xagent-100-ToolServerNode-1     | INFO:     Application startup complete.
xagent-100-ToolServerNode-1     | INFO:     Uvicorn running on http://0.0.0.0:31942 (Press CTRL+C to quit)
xagent-100-xagent-mysql-1       | 2023-12-14T05:49:03.879382Z 8 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'
XAgent-Server                   | INFO:     Will watch for changes in these directories: ['/app']
XAgent-Server                   | INFO:     Uvicorn running on http://0.0.0.0:8090 (Press CTRL+C to quit)
XAgent-Server                   | INFO:     Started reloader process [1] using StatReload
xagent-100-xagent-mysql-1       | 2023-12-14T05:49:06.192883Z 9 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'
XAgent-Server                   | INFO:     Started server process [16]
XAgent-Server                   | INFO:     Waiting for application startup.
XAgent-Server                   | INFO:     Application startup complete.

访问XAgent-Server

XAgent-Server启动后,默认的访问地址是 http://localhost:5173, 要确保端口是对外开放的,首次访问该地址,会看到上个步骤的控制台上会打印访问的日志信息:


XAgent-Server                   |   XAgent Service Startup Param:
XAgent-Server                   |             app: app:app
XAgent-Server                   |             prod: False
XAgent-Server                   |             base_dir: XAgentServer
XAgent-Server                   |             use_redis: False
XAgent-Server                   |             recorder_root_dir: running_records
XAgent-Server                   |             default_login: True
XAgent-Server                   |             check_running: False
XAgent-Server                   |             host: 0.0.0.0
XAgent-Server                   |             port: 8090
XAgent-Server                   |             debug: True
XAgent-Server                   |             reload: True
XAgent-Server                   |             workers: 1
XAgent-Server                   |             share_url: https://x-agent.net/api/conv/community
XAgent-Server                   |             DB: 
XAgent-Server                   |             Redis: 
XAgent-Server                   |             Email: 
XAgent-Server                   |             Upload: 
XAgent-Server                   | XAgent Service Init Dependence.  
XAgent-Server                   | init a thread pool executor, max_workers: 1  
XAgent-Server                   | XAgent Service Init Dependence: Complete!  
XAgent-Server                   | Default user: Guest, token: xagent, you can use it to login  
XAgent-Server                   | XAgent Server Dependences:  
XAgent-Server                   |         Python: 3.10+ 
XAgent-Server                   |         FastAPI: Http server
XAgent-Server                   |         Websocket: long connect with client
XAgent-Server                   |         MySQL: save xagent data
XAgent-Server                   |         SqlAlchemy: ORM with MySQL
XAgent-Server                   |         Redis: save status of interaction
XAgent-Server                   |         Threading: run interaction
XAgent-Server                   |         APScheduler: send data to client and keep alive
XAgent-Server                   |         FastAPI APIRouter: manage websocket route
XAgent-Server                   |         XAgentError: XAgentServer.exts.exception_ext
XAgent-Server                   | XAgent Server Version:  
XAgent-Server                   |         V 1.1.0
XAgent-Server                   | Notes:  
XAgent-Server                   |         Since V 1.1.0, 
XAgent-Server                   |         Local storage will no longer be supported, replaced by Mysql.
XAgent-Server                   |         The service depends on Redis and Mysql, 
XAgent-Server                   |         so you need to install Redis and Mysql before using it.
XAgent-Server                   |         Before you use this service, please ensure that the following services are available:
XAgent-Server                   |             1. Redis on docker, port: 6379, you can start it by docker, default password: xagent
XAgent-Server                   |             2. Mysql on docker, port: 3306, you can start it by docker
XAgent-Server                   |             3. XAgent Tool Server is runnning on port 8080
XAgent-Server                   |             4. Port 8090 is not occupied

XAgent的部署及运行_第1张图片

部署及启动过程中的一些错误解决

错误列表

ToolServerNode—but the ‘h2’ package is not installed

我是使用的是XAgent-1.0.0版本,启动过程中xagentteam/toolserver-node:latest这个image的容器碰到以下错误:

ImportError: Using http2=True, but the 'h2' package is not installed. Make sure to install httpx using `pip install httpx[http2]`.
xagent-100-ToolServerNode-1     | 
xagent-100-ToolServerNode-1     | ERROR:    Application startup failed. Exiting.

解决方法

# 到\XAgent-1.0.0\dockerfiles\ToolServerNode\目录下
# 修改Dockerfile文件
# 在RUN pip install playwright && playwright install chromium &&  playwright install-deps这段之后添加:
RUN pip install httpx[http2]
# 注意,添加上面这段脚本后,要重新运行docker compose build 和 docker compose up

mysql启动后不停闪现的warning信息

后台服务启动后,如果不停闪现以下错误:

 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'

解决方法 请修改mysql的healthcheck段配置:

healthcheck:
     # test: [ "CMD", "mysqladmin","ping", "-h", "localhost" ]
     test: ["CMD-SHELL", "mysql -h localhost -u root -pxagent -e 'SELECT 1'"]
     #interval: 10s
     timeout: 20s
     retries: 20

如果以上配置修改不能解决您的问题,尝试将你的Xagent代码切换到master版本,我在1.00版本碰到该问题,切换到master版本后运行,以上问题应该已经被修复

max_workers must be greater than 0 错误

暂无解决方案,如果你是1.00版本,建议使用master版本尝试该问题是否能修复,总而言之,master版本似乎要比1.00版本稳定不少。

   |   File "/app/XAgent/function_handler.py", line 234, in handle_tool_call
XAgent-Server                   |     command_result = self.long_result_summary(
XAgent-Server                   |   File "/app/XAgent/function_handler.py", line 167, in long_result_summary
XAgent-Server                   |     with ThreadPoolExecutor(max_workers=len(result)) as pool:
XAgent-Server                   |   File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 144, in __init__
XAgent-Server                   |     raise ValueError("max_workers must be greater than 0")
XAgent-Server                   | ValueError: max_workers must be greater than 0

AttributeError: ‘ToolServerInterface’ object has no attribute ‘cookies’

伴随以上错误,同时会有以下异常信息:

 XAgentServer.exts.exception_ext.XAgentRunningError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /get_cookie

解决方法 问题是由localhost的8080端口沟通失败引起的,尝试使用IP地址,请注意打开8080端口的访问权限

你可能感兴趣的:(AI技术谈,agent,LLM)