Skip to content

Commit 27143bb

Browse files
authored
feat: usage cases mini aiops (#92)
2 parents af8af86 + a482500 commit 27143bb

File tree

13 files changed

+499
-0
lines changed

13 files changed

+499
-0
lines changed

02-use-cases/mini_aiops/README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# AI运维 Agent - Mini AIOps
2+
3+
## 概述
4+
5+
> 本项目基于Veadk开发,实现了一个基于AI的运维智能工具
6+
7+
## 核心功能
8+
9+
本项目提供以下核心功能:
10+
11+
- 智能云资源巡检:自动梳理云上资源运行状态,发现潜在风险
12+
- 一键问题诊断:结合日志、监控和主机诊断能力给出故障原因分析
13+
- 运维知识问答:基于内置知识库回答常见运维问题和 SOP 流程
14+
- 多 Agent 协同:通过 CCAPI 等 MCP 工具自动执行部分运维操作
15+
- 长短期记忆:结合会话记忆与长期记忆提供持续性的运维助手体验
16+
17+
## Agent 能力
18+
19+
本项目当前内置一个总控 Agent 和一个子 Agent:
20+
21+
- ve_ai_ops_agent:面向云计算运维场景的总控 Agent,负责理解用户需求并规划巡检、诊断和优化流程。
22+
- ccapi_agent:专注云资源管控的子 Agent,通过 CCAPI MCP 工具集查看和调整云上资源配置。
23+
24+
## 本地运行
25+
26+
### 环境准备
27+
28+
开始前,请确保您的开发环境满足以下要求:
29+
30+
- Python 3.10 或更高版本
31+
- VeADK 0.2.28 或更高版本
32+
- 推荐使用 `uv` 进行依赖管理
33+
- <a target="_blank" href="https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey">获取火山方舟 API KEY</a>
34+
- <a target="_blank" href="https://console.volcengine.com/iam/keymanage/">获取火山引擎 AK/SK</a>
35+
36+
### 快速入门
37+
38+
请按照以下步骤在本地部署和运行本项目。
39+
40+
#### 1. 下载代码并安装依赖
41+
42+
```bash
43+
# 克隆代码仓库
44+
git clone https://github.com/volcengine/agentkit-samples.git
45+
cd agentkit-samples/02-use-cases/mini_aiops
46+
47+
# 安装项目依赖
48+
uv sync --index-url https://pypi.tuna.tsinghua.edu.cn/simple
49+
```
50+
51+
#### 2. 配置环境变量
52+
53+
```bash
54+
export MODEL_AGENT_API_KEY="xxxxx"
55+
export VOLCENGINE_ACCESS_KEY="xxxxxx"
56+
export VOLCENGINE_SECRET_KEY="xxxxxx"
57+
```
58+
59+
#### 4. 启动服务
60+
61+
1. 请先保证环境变量配置正确
62+
63+
2. 本地`veadk web`启动测试(注意:请保持在`agentkit-samples/02-use-cases`目录)
64+
65+
```bash
66+
veadk web
67+
```
68+
69+
1. 进入服务url `http://127.0.0.1:8000`
70+
2. 选择`mini_aiops`
71+
3. 与Agent进行对话
72+
73+
#### 5. 测试服务
74+
75+
![image1](./img/image1.png)
76+
77+
## 目录结构说明
78+
79+
```plaintext
80+
mini_aiops/
81+
├── agent.py # AIOps Agent 定义
82+
├── README.md # 使用说明与功能介绍
83+
├── requirements.txt# 依赖列表(基于 veadk-python)
84+
├── pyproject.toml # 项目配置(uv/构建配置)
85+
├── sop_aiops.md # 运维 SOP 文档(可导入到知识库)
86+
├── img/ # README 中使用的示意截图
87+
└── uv.lock # uv 生成的锁定文件
88+
```
89+
90+
## AgentKit 部署
91+
92+
```bash
93+
# 1. 进入`mini_aiops`
94+
cd mini_aiops
95+
# 2. 初始化配置
96+
agentkit config
97+
# 3. 根据说明进行配置
98+
# 注意:第7步无需设置环境变量,第8步可以选择cloud模式
99+
100+
# 4. 部署
101+
agentkit launch
102+
```
103+
104+
部署过程完成后,由于运维MCP工具需要ECS相关权限,请前往控制台开通相关权限
105+
106+
进入控制台
107+
108+
![image4](./img/image4.png)
109+
110+
开通相关权限
111+
112+
![image5](./img/image5.png)
113+
114+
## 示例提示词
115+
116+
以下是一些常用的提示词示例:
117+
118+
"创建IAM用户"
119+
"查看现有的ECS实例"
120+
"列出可用的资源类型"
121+
"更新某个资源的配置"
122+
123+
## 效果展示
124+
125+
部署中,控制台界面
126+
![image2](./img/image2.png)
127+
部署完成后,bash界面
128+
![image3](./img/image3.png)
129+
130+
线上测试成功
131+
![image6](./img/image6.png)
132+
133+
## 常见问题
134+
135+
常见问题列表待补充。
136+
137+
## 代码许可
138+
139+
本项目采用开源许可证,详情请参考项目根目录下的 LICENSE 文件。
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .agent import root_agent # noqa

02-use-cases/mini_aiops/agent.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import os
2+
3+
from google.adk.planners import BuiltInPlanner
4+
from google.adk.tools.mcp_tool.mcp_toolset import (
5+
McpToolset,
6+
StdioServerParameters,
7+
StdioConnectionParams,
8+
)
9+
from google.genai import types
10+
from veadk import Agent
11+
from veadk.auth.veauth.utils import get_credential_from_vefaas_iam
12+
from veadk.config import getenv # noqa
13+
from veadk.knowledgebase.knowledgebase import KnowledgeBase
14+
from veadk.memory.short_term_memory import ShortTermMemory
15+
from agentkit.apps import AgentkitAgentServerApp
16+
17+
env_dict = {
18+
"VOLCENGINE_ACCESS_KEY": os.getenv("VOLCENGINE_ACCESS_KEY"),
19+
"VOLCENGINE_SECRET_KEY": os.getenv("VOLCENGINE_SECRET_KEY"),
20+
}
21+
if not (env_dict["VOLCENGINE_ACCESS_KEY"] and env_dict["VOLCENGINE_SECRET_KEY"]):
22+
credential = get_credential_from_vefaas_iam()
23+
env_dict["VOLCENGINE_ACCESS_KEY"] = credential.access_key_id
24+
env_dict["VOLCENGINE_SECRET_KEY"] = credential.secret_access_key
25+
env_dict["VOLCENGINE_SESSION_TOKEN"] = credential.session_token
26+
27+
short_term_memory = ShortTermMemory(backend="local")
28+
29+
### Auto create knowledgebase if not exist for aiops
30+
knowledgebase = KnowledgeBase(backend="local", index="aiops_kb", top_k=3)
31+
32+
file_path = os.path.join(os.path.dirname(__file__), "sop_aiops.md")
33+
knowledgebase.add_from_files(files=[file_path])
34+
35+
### control center mcp server
36+
server_parameters = StdioServerParameters(
37+
command="uvx",
38+
args=[
39+
"--from",
40+
"git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_ccapi",
41+
"mcp-server-ccapi",
42+
],
43+
env=env_dict,
44+
)
45+
46+
ccapi_mcp_toolset = McpToolset(
47+
connection_params=StdioConnectionParams(
48+
server_params=server_parameters, timeout=180.0
49+
),
50+
errlog=None,
51+
)
52+
53+
agent: Agent = Agent(
54+
name="root_agent",
55+
model_name="deepseek-v3-1-terminus",
56+
description="云资源管控智能体",
57+
instruction="你是一个云资源管控专家,擅长通过 CCAPI 管理各类云资源",
58+
knowledgebase=knowledgebase,
59+
tools=[ccapi_mcp_toolset],
60+
planner=BuiltInPlanner(
61+
thinking_config=types.ThinkingConfig(
62+
include_thoughts=False,
63+
thinking_budget=0,
64+
)
65+
),
66+
)
67+
68+
root_agent = agent
69+
70+
71+
agent_server_app = AgentkitAgentServerApp(
72+
agent=agent,
73+
short_term_memory=short_term_memory,
74+
)
75+
76+
if __name__ == "__main__":
77+
agent_server_app.run(host="0.0.0.0", port=8000)

02-use-cases/mini_aiops/deploy.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
agentkit config \
5+
--agent_name mini_aiops \
6+
--entry_point agent.py \
7+
--description "a mini agent for aiops" \
8+
--launch_type cloud \
9+
--image_tag v1.0.0 \
10+
--region cn-beijing
11+
12+
agentkit launch
13+
508 KB
Loading
55.3 KB
Loading
116 KB
Loading
93.6 KB
Loading
92.8 KB
Loading
503 KB
Loading

0 commit comments

Comments
 (0)