Skip to content

Commit 64157c0

Browse files
authored
Merge pull request #10 from junliang-xjl/feature/agent
add mydba agent
2 parents efa580a + 0b568cf commit 64157c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+5712
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ You are a professional Alibaba Cloud RDS Copilot, specializing in providing cust
141141
- **Safety Awareness**: Ensure no operations negatively impact customer databases.
142142
```
143143

144+
## Use Cases
145+
### mydba
146+
Alibaba Cloud Database MyDBA Agent(<a href="./component/mydba/README.md">README.md</a>)
147+
- Buy RDS
148+
<img src="./assets/buy_rds.gif" alt="buy RDS" width="500"/>
149+
- Diagnose RDS
150+
<img src="./assets/diagnose.gif" alt="diagnose RDS" width="500"/>
151+
144152
## Contributing
145153
Contributions are welcome! Please feel free to submit a Pull Request.
146154
1. Fork the repository

README_CN.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ git clone https://github.com/aliyun/alibabacloud-rds-openapi-mcp-server.git
138138
- **安全性注意**:在执行任何操作时,需确保不会对客户的数据库造成负面影响。
139139
```
140140

141+
## 使用案例
142+
### mydba
143+
阿里云数据库 MyDBA 智能体(<a href="./component/mydba/README_cn.md">README_cn.md</a>)
144+
- 购买RDS
145+
<img src="./assets/buy_rds_cn.gif" alt="购买RDS" width="500"/>
146+
- 诊断RDS
147+
<img src="./assets/diagnose_cn.gif" alt="诊断RDS" width="500"/>
148+
141149
## 贡献指南
142150
欢迎贡献代码!请提交Pull Request:
143151
1. Fork 本仓库

assets/buy_rds.gif

4.1 MB
Loading

assets/buy_rds_cn.gif

5 MB
Loading

assets/diagnose.gif

2.04 MB
Loading

assets/diagnose_cn.gif

3.04 MB
Loading

component/mydba/README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<p align="center">English | <a href="./README_CN.md">中文</a><br></p>
2+
3+
# Alibaba Cloud Database MyDBA Agent
4+
5+
## Features
6+
7+
1. **Supports management of Alibaba Cloud RDS**, including:
8+
- Instance information query
9+
- RDS Issue analysis
10+
- Purchase and modify RDS instance
11+
12+
2. **Query data for self-built databases**, assisting with data queries, statistics and analysis.
13+
14+
## Installation Guide
15+
16+
### Environment Preparation
17+
18+
1. **Install `uv`**:
19+
- Install `uv` via [Astral](https://docs.astral.sh/uv/getting-started/installation/)
20+
- Install `uv` via [GitHub README](https://github.com/astral-sh/uv#installation)
21+
- Download `uv` from [GitHub Release](https://github.com/astral-sh/uv/releases)
22+
23+
2. **Install Python**:
24+
- Use the following command to install Python:
25+
26+
```shell
27+
uv python install 3.12
28+
```
29+
30+
3. **Apply for a LLM api key**:
31+
- Compatible with OpenAI client, support Qwen and Deepseek.
32+
33+
4. **Prepare an Alibaba Cloud account AK/SK**:
34+
- Ensure your account having the access permission with Alibaba Cloud RDS service (Policy Name: AliyunRDSFullAccess).
35+
36+
### Install Dependencies
37+
38+
Install dependency modules using `uv`:
39+
40+
```shell
41+
export UV_DEFAULT_INDEX="https://mirrors.aliyun.com/pypi/simple" # optional
42+
uv sync --inexact
43+
```
44+
45+
### Service Initialization
46+
47+
1. **Prepare Configuration File**
48+
- Default path: `/usr/local/mydba/config_app.ini`
49+
- Configure parameters in the `model`, `app`, and `rag` sections:
50+
51+
```ini
52+
[common]
53+
debug = False
54+
config_database = sqlite:///usr/local/mydba/sqlite_app.db
55+
56+
[log]
57+
dir = /usr/local/mydba/logs
58+
name = mydba
59+
file_level = INFO
60+
61+
[model]
62+
api_key = sk-xxx ; LLM api key
63+
base_url = https://api.deepseek.com ; LLM api base url (example is the model address of Deepseek)
64+
model = deepseek-chat ; LLM model name (example is the model name of Deepseek)
65+
max_tokens = 1000
66+
temperature = 1.0
67+
68+
[app]
69+
refresh_interval = 60
70+
max_steps = 100
71+
security_key = xxxxxxxxxxxxxxxx ; Key for encryption, 16-byte length, for internal data protection
72+
73+
[rag]
74+
api_key = sk-xxx ; LLM api key
75+
base_url = https://dashscope.aliyuncs.com/compatible-mode/v1 ; LLM api base url (example is the model address of Qwen)
76+
embedding = text-embedding-v2 ; Embedding model name (Qwen supports embedding api calls)
77+
data_dir = /usr/local/mydba/vector_store
78+
```
79+
80+
2. **Initialize Agent**
81+
- Execute the following command to initialize the Agent. Ensure you have correctly configured the **`config_app.ini`** file and replace `xxxxxx` with your Alibaba Cloud account AK/SK.
82+
83+
```shell
84+
uv --directory /path/to/mydba \
85+
run init_config.py \
86+
init-project \ # Initialize project
87+
--config_file /usr/local/mydba/config_app.ini \ # Configuration file path
88+
--reset \ # Clear existing configuration (optional)
89+
--rds_access_id xxxxxx \ # Replace with your Alicloud account ID
90+
--rds_access_key xxxxxx # Replace with your Alicloud account secret
91+
```
92+
93+
3. **Add Self-Built Database**
94+
- Execute the following command to add a self-built database. Ensure you have correctly configured the **`config_app.ini`** file and replace `--db_info` parameters with actual database connection details.
95+
96+
```shell
97+
uv --directory /path/to/mydba \
98+
run init_config.py \
99+
add-db \ # Add self-built database
100+
--config_file /usr/local/mydba/config_app.ini \ # Path to the configuration file
101+
--db_info 'mysql####127.0.0.1##3306##root##123456##utf8mb4##mybase' # Database connection info, pay attention to the escape of special characters
102+
```
103+
104+
4. **Initialize RAG Tool**
105+
- Execute the following command to initialize the RAG tool. Ensure you have correctly configured the **`config_app.ini`** file and added the **self-built database**.
106+
107+
```shell
108+
uv --directory /path/to/mydba/mydba/mcp/rag \ # RAG working directory ./mydba/mcp/rag
109+
run rag_init.py \ # Run RAG initialization script
110+
init-config \ # Initialize configuration
111+
--config_file /usr/local/mydba/config_app.ini # Path to the configuration file
112+
```
113+
114+
### Service Startup
115+
116+
- Execute the start command: **`mydba`** (install agent via MyBase console, this command will register in the OS)
117+
118+
```shell
119+
mydba
120+
```
121+
122+
- Or use the startup script: **`mydba.sh`** (built-in startup script, use directly if default installation path is unchanged)
123+
124+
```shell
125+
sh /path/to/mydba/shell/mydba.sh
126+
```
127+
128+
- Or manually execute the following commands:
129+
130+
```shell
131+
# Set environment variables (optional, default: /usr/local/mydba/config_app.ini)
132+
export MYDBA_CONFIG_FILE=/path/to/mydba/config_app.ini
133+
# Start RAG Server
134+
nohup uv --directory /path/to/mydba/mydba/mcp/rag run rag_server.py >> /path/to/mydba/logs/rag.log 2>&1 &
135+
# Start MyDBA
136+
uv --directory /path/to/mydba run main.py
137+
```
138+
139+
## Contact Us
140+
141+
- Welcome joining the DingTalk group for feedback, refer to the README.md of RDS MCP for details.

component/mydba/README_CN.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<p align="center"><a href="./README.md">English</a> | 中文<br></p>
2+
3+
# 阿里云数据库 MyDBA 智能体
4+
5+
## 特性
6+
7+
1. **支持对阿里云 RDS 进行管理**,包括:
8+
- 实例信息查询
9+
- 问题分析
10+
- 购买与变配
11+
2. **对自建数据库进行问数**,帮助进行数据查询、统计与分析。
12+
13+
## 安装指南
14+
15+
### 环境准备
16+
17+
1. **安装 `uv`**
18+
- [Astral](https://docs.astral.sh/uv/getting-started/installation/) 安装 `uv`
19+
- [GitHub README](https://github.com/astral-sh/uv#installation) 安装 `uv`
20+
- [GitHub Release](https://github.com/astral-sh/uv/releases) 下载 `uv`
21+
22+
2. **安装 Python**
23+
- 使用以下命令安装 Python:
24+
25+
```shell
26+
uv python install 3.12
27+
```
28+
29+
3. **申请大模型 Key**
30+
- 兼容 OpenAI 客户端,支持通义千问、Deepseek。
31+
32+
4. **准备阿里云账号**
33+
- 确保你有阿里云 RDS 服务访问权限(策略名:AliyunRDSFullAccess)的账号凭证。
34+
35+
### 安装依赖
36+
37+
使用 `uv` 安装依赖模块:
38+
39+
```shell
40+
export UV_DEFAULT_INDEX="https://mirrors.aliyun.com/pypi/simple"
41+
uv sync --inexact
42+
```
43+
44+
### 服务初始化
45+
46+
1. **准备配置文件**
47+
- 默认路径:`/usr/local/mydba/config_app.ini`
48+
- 配置好 `model``app``rag` 部分的参数项:
49+
50+
```ini
51+
[common]
52+
debug = False
53+
config_database = sqlite:///usr/local/mydba/sqlite_app.db
54+
55+
[log]
56+
dir = /usr/local/mydba/logs
57+
name = mydba
58+
file_level = INFO
59+
60+
[model]
61+
api_key = sk-xxx ; 大模型 key
62+
base_url = https://api.deepseek.com ; 大模型调用地址(这里是 Deepseek 模型地址)
63+
model = deepseek-chat ; 模型名称(这里是 Deepseek 模型名称)
64+
max_tokens = 1000
65+
temperature = 1.0
66+
67+
[app]
68+
refresh_interval = 60
69+
max_steps = 100
70+
security_key = xxxxxxxxxxxxxxxx ; 加密 key,固定 16 字节长度,用于工程内部数据保护
71+
72+
[rag]
73+
api_key = sk-xxx ; 大模型 key
74+
base_url = https://dashscope.aliyuncs.com/compatible-mode/v1 ; 大模型调用地址(这里是通义模型地址)
75+
embedding = text-embedding-v2 ; embedding 模型名称(通义千问支持 embedding 调用)
76+
data_dir = /usr/local/mydba/vector_store
77+
```
78+
79+
2. **初始化 Agent**
80+
- 执行以下命令以初始化 Agent。请确保您已经正确配置了 **`config_app.ini`** 文件,并用您的阿里云账号替换 `xxxxxx`
81+
82+
```shell
83+
uv --directory /path/to/mydba \
84+
run init_config.py \
85+
init-project \ # 初始化工程
86+
--config_file /usr/local/mydba/config_app.ini \ # 配置文件路径
87+
--reset \ # 清空已有配置(可选)
88+
--rds_access_id xxxxxx \ # 替换为您的阿里云账号 ID
89+
--rds_access_key xxxxxx # 替换为您的阿里云账号密钥
90+
```
91+
92+
3. **添加自建数据库**
93+
- 执行以下命令以添加自建数据库。请确保您已正确配置 **`config_app.ini`** 文件,并根据实际情况替换 `--db_info` 参数中的数据库连接信息。
94+
95+
```shell
96+
uv --directory /path/to/mydba \
97+
run init_config.py \
98+
add-db \ # 添加自建数据库
99+
--config_file /usr/local/mydba/config_app.ini \ # 配置文件路径
100+
--db_info 'mysql####127.0.0.1##3306##root##123456##utf8mb4##mybase' # 数据库连接信息,注意特殊字符的转义
101+
```
102+
103+
4. **初始化 RAG 工具**
104+
- 执行以下命令以初始化 RAG 工具。请确保您已经正确配置了 **`config_app.ini`** 文件,并添加了**自建数据库**
105+
106+
```shell
107+
uv --directory /path/to/mydba/mydba/mcp/rag \ # 这里是 RAG 的工作目录 ./mydba/mcp/rag
108+
run rag_init.py \ # 运行 RAG 初始化脚本
109+
init-config \ # 初始化配置
110+
--config_file /usr/local/mydba/config_app.ini # 配置文件路径
111+
```
112+
113+
### 服务启动
114+
115+
- 执行启动命令:**`mydba`** 通过控制台安装的智能体,会在操作系统注册此命令。
116+
117+
```shell
118+
mydba
119+
```
120+
121+
- 或者执行启动脚本:**`mydba.sh`** 智能体自带的启动脚本,如果没有修改默认的安装路径,可直接使用。
122+
123+
```shell
124+
sh /path/to/mydba/shell/mydba.sh
125+
```
126+
127+
- 或者手动执行如下命令:
128+
129+
```shell
130+
# 配置环境变量(可选,默认:/usr/local/mydba/config_app.ini)
131+
export MYDBA_CONFIG_FILE=/path/to/mydba/config_app.ini
132+
# 启动 RAG Server
133+
nohup uv --directory /path/to/mydba/mydba/mcp/rag run rag_server.py >> /path/to/mydba/logs/rag.log 2>&1 &
134+
# 启动 MyDBA
135+
uv --directory /path/to/mydba run main.py
136+
```
137+
138+
## 联系我们
139+
140+
- 向上查看 RDS MCP 的 README.md,加入钉钉群。

component/mydba/config_app.ini

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[common]
2+
debug = False
3+
config_database = sqlite:///usr/local/mydba/sqlite_app.db
4+
5+
[log]
6+
dir = /usr/local/mydba/logs
7+
name = mydba
8+
file_level = INFO
9+
10+
[model]
11+
api_key =
12+
base_url =
13+
model =
14+
max_tokens = 1000
15+
temperature = 1.0
16+
17+
[app]
18+
refresh_interval = 60
19+
max_steps = 100
20+
# 16字节长度
21+
security_key =
22+
23+
[rag]
24+
api_key =
25+
base_url =
26+
embedding =
27+
data_dir = /usr/local/mydba/vector_store

0 commit comments

Comments
 (0)