Skip to content

add mydba agent #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ You are a professional Alibaba Cloud RDS Copilot, specializing in providing cust
- **Safety Awareness**: Ensure no operations negatively impact customer databases.
```

## Use Cases
### mydba
Alibaba Cloud Database MyDBA Agent(README.md)
- Buy RDS
buy RDS
- Diagnose RDS
diagnose RDS

## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
Expand Down
8 changes: 8 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ git clone https://github.com/aliyun/alibabacloud-rds-openapi-mcp-server.git
- **安全性注意**:在执行任何操作时,需确保不会对客户的数据库造成负面影响。
```

## 使用案例
### mydba
阿里云数据库 MyDBA 智能体(README_cn.md)
- 购买RDS
购买RDS
- 诊断RDS
诊断RDS

## 贡献指南
欢迎贡献代码!请提交Pull Request:
1. Fork 本仓库
Expand Down
Binary file added assets/buy_rds.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buy_rds_cn.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/diagnose.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/diagnose_cn.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 141 additions & 0 deletions component/mydba/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@

English | 中文


# Alibaba Cloud Database MyDBA Agent

## Features

1. **Supports management of Alibaba Cloud RDS**, including:
- Instance information query
- RDS Issue analysis
- Purchase and modify RDS instance

2. **Query data for self-built databases**, assisting with data queries, statistics and analysis.

## Installation Guide

### Environment Preparation

1. **Install `uv`**:
- Install `uv` via [Astral](https://docs.astral.sh/uv/getting-started/installation/)
- Install `uv` via [GitHub README](https://github.com/astral-sh/uv#installation)
- Download `uv` from [GitHub Release](https://github.com/astral-sh/uv/releases)

2. **Install Python**:
- Use the following command to install Python:

```shell
uv python install 3.12
```

3. **Apply for a LLM api key**:
- Compatible with OpenAI client, support Qwen and Deepseek.

4. **Prepare an Alibaba Cloud account AK/SK**:
- Ensure your account having the access permission with Alibaba Cloud RDS service (Policy Name: AliyunRDSFullAccess).

### Install Dependencies

Install dependency modules using `uv`:

```shell
export UV_DEFAULT_INDEX="https://mirrors.aliyun.com/pypi/simple" # optional
uv sync --inexact
```

### Service Initialization

1. **Prepare Configuration File**
- Default path: `/usr/local/mydba/config_app.ini`
- Configure parameters in the `model`, `app`, and `rag` sections:

```ini
[common]
debug = False
config_database = sqlite:///usr/local/mydba/sqlite_app.db

[log]
dir = /usr/local/mydba/logs
name = mydba
file_level = INFO

[model]
api_key = sk-xxx ; LLM api key
base_url = https://api.deepseek.com ; LLM api base url (example is the model address of Deepseek)
model = deepseek-chat ; LLM model name (example is the model name of Deepseek)
max_tokens = 1000
temperature = 1.0

[app]
refresh_interval = 60
max_steps = 100
security_key = xxxxxxxxxxxxxxxx ; Key for encryption, 16-byte length, for internal data protection

[rag]
api_key = sk-xxx ; LLM api key
base_url = https://dashscope.aliyuncs.com/compatible-mode/v1 ; LLM api base url (example is the model address of Qwen)
embedding = text-embedding-v2 ; Embedding model name (Qwen supports embedding api calls)
data_dir = /usr/local/mydba/vector_store
```

2. **Initialize Agent**
- 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.

```shell
uv --directory /path/to/mydba \
run init_config.py \
init-project \ # Initialize project
--config_file /usr/local/mydba/config_app.ini \ # Configuration file path
--reset \ # Clear existing configuration (optional)
--rds_access_id xxxxxx \ # Replace with your Alicloud account ID
--rds_access_key xxxxxx # Replace with your Alicloud account secret
```

3. **Add Self-Built Database**
- 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.

```shell
uv --directory /path/to/mydba \
run init_config.py \
add-db \ # Add self-built database
--config_file /usr/local/mydba/config_app.ini \ # Path to the configuration file
--db_info 'mysql####127.0.0.1##3306##root##123456##utf8mb4##mybase' # Database connection info, pay attention to the escape of special characters
```

4. **Initialize RAG Tool**
- 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**.

```shell
uv --directory /path/to/mydba/mydba/mcp/rag \ # RAG working directory ./mydba/mcp/rag
run rag_init.py \ # Run RAG initialization script
init-config \ # Initialize configuration
--config_file /usr/local/mydba/config_app.ini # Path to the configuration file
```

### Service Startup

- Execute the start command: **`mydba`** (install agent via MyBase console, this command will register in the OS)

```shell
mydba
```

- Or use the startup script: **`mydba.sh`** (built-in startup script, use directly if default installation path is unchanged)

```shell
sh /path/to/mydba/shell/mydba.sh
```

- Or manually execute the following commands:

```shell
# Set environment variables (optional, default: /usr/local/mydba/config_app.ini)
export MYDBA_CONFIG_FILE=/path/to/mydba/config_app.ini
# Start RAG Server
nohup uv --directory /path/to/mydba/mydba/mcp/rag run rag_server.py >> /path/to/mydba/logs/rag.log 2>&1 &
# Start MyDBA
uv --directory /path/to/mydba run main.py
```

## Contact Us

- Welcome joining the DingTalk group for feedback, refer to the README.md of RDS MCP for details.
140 changes: 140 additions & 0 deletions component/mydba/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

English | 中文


# 阿里云数据库 MyDBA 智能体

## 特性

1. **支持对阿里云 RDS 进行管理**,包括:
- 实例信息查询
- 问题分析
- 购买与变配
2. **对自建数据库进行问数**,帮助进行数据查询、统计与分析。

## 安装指南

### 环境准备

1. **安装 `uv`**:
- [Astral](https://docs.astral.sh/uv/getting-started/installation/) 安装 `uv`
- [GitHub README](https://github.com/astral-sh/uv#installation) 安装 `uv`
- [GitHub Release](https://github.com/astral-sh/uv/releases) 下载 `uv`

2. **安装 Python**:
- 使用以下命令安装 Python:

```shell
uv python install 3.12
```

3. **申请大模型 Key**:
- 兼容 OpenAI 客户端,支持通义千问、Deepseek。

4. **准备阿里云账号**:
- 确保你有阿里云 RDS 服务访问权限(策略名:AliyunRDSFullAccess)的账号凭证。

### 安装依赖

使用 `uv` 安装依赖模块:

```shell
export UV_DEFAULT_INDEX="https://mirrors.aliyun.com/pypi/simple"
uv sync --inexact
```

### 服务初始化

1. **准备配置文件**
- 默认路径:`/usr/local/mydba/config_app.ini`
- 配置好 `model`、`app` 和 `rag` 部分的参数项:

```ini
[common]
debug = False
config_database = sqlite:///usr/local/mydba/sqlite_app.db

[log]
dir = /usr/local/mydba/logs
name = mydba
file_level = INFO

[model]
api_key = sk-xxx ; 大模型 key
base_url = https://api.deepseek.com ; 大模型调用地址(这里是 Deepseek 模型地址)
model = deepseek-chat ; 模型名称(这里是 Deepseek 模型名称)
max_tokens = 1000
temperature = 1.0

[app]
refresh_interval = 60
max_steps = 100
security_key = xxxxxxxxxxxxxxxx ; 加密 key,固定 16 字节长度,用于工程内部数据保护

[rag]
api_key = sk-xxx ; 大模型 key
base_url = https://dashscope.aliyuncs.com/compatible-mode/v1 ; 大模型调用地址(这里是通义模型地址)
embedding = text-embedding-v2 ; embedding 模型名称(通义千问支持 embedding 调用)
data_dir = /usr/local/mydba/vector_store
```

2. **初始化 Agent**
- 执行以下命令以初始化 Agent。请确保您已经正确配置了 **`config_app.ini`** 文件,并用您的阿里云账号替换 `xxxxxx`。

```shell
uv --directory /path/to/mydba \
run init_config.py \
init-project \ # 初始化工程
--config_file /usr/local/mydba/config_app.ini \ # 配置文件路径
--reset \ # 清空已有配置(可选)
--rds_access_id xxxxxx \ # 替换为您的阿里云账号 ID
--rds_access_key xxxxxx # 替换为您的阿里云账号密钥
```

3. **添加自建数据库**
- 执行以下命令以添加自建数据库。请确保您已正确配置 **`config_app.ini`** 文件,并根据实际情况替换 `--db_info` 参数中的数据库连接信息。

```shell
uv --directory /path/to/mydba \
run init_config.py \
add-db \ # 添加自建数据库
--config_file /usr/local/mydba/config_app.ini \ # 配置文件路径
--db_info 'mysql####127.0.0.1##3306##root##123456##utf8mb4##mybase' # 数据库连接信息,注意特殊字符的转义
```

4. **初始化 RAG 工具**
- 执行以下命令以初始化 RAG 工具。请确保您已经正确配置了 **`config_app.ini`** 文件,并添加了**自建数据库**。

```shell
uv --directory /path/to/mydba/mydba/mcp/rag \ # 这里是 RAG 的工作目录 ./mydba/mcp/rag
run rag_init.py \ # 运行 RAG 初始化脚本
init-config \ # 初始化配置
--config_file /usr/local/mydba/config_app.ini # 配置文件路径
```

### 服务启动

- 执行启动命令:**`mydba`** 通过控制台安装的智能体,会在操作系统注册此命令。

```shell
mydba
```

- 或者执行启动脚本:**`mydba.sh`** 智能体自带的启动脚本,如果没有修改默认的安装路径,可直接使用。

```shell
sh /path/to/mydba/shell/mydba.sh
```

- 或者手动执行如下命令:

```shell
# 配置环境变量(可选,默认:/usr/local/mydba/config_app.ini)
export MYDBA_CONFIG_FILE=/path/to/mydba/config_app.ini
# 启动 RAG Server
nohup uv --directory /path/to/mydba/mydba/mcp/rag run rag_server.py >> /path/to/mydba/logs/rag.log 2>&1 &
# 启动 MyDBA
uv --directory /path/to/mydba run main.py
```

## 联系我们

- 向上查看 RDS MCP 的 README.md,加入钉钉群。
27 changes: 27 additions & 0 deletions component/mydba/config_app.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[common]
debug = False
config_database = sqlite:///usr/local/mydba/sqlite_app.db

[log]
dir = /usr/local/mydba/logs
name = mydba
file_level = INFO

[model]
api_key =
base_url =
model =
max_tokens = 1000
temperature = 1.0

[app]
refresh_interval = 60
max_steps = 100
# 16字节长度
security_key =

[rag]
api_key =
base_url =
embedding =
data_dir = /usr/local/mydba/vector_store
Loading