基于 Hermes Agent(Nous Research 开源自进化 AI Agent 框架)构建的轻量级 DevOps 自动化 Agent,通过 REST API 对外暴露部署、监控、告警三大能力。
- 智能部署流水线 —
pull → test → build → deploy → verify五步流水线,失败自动回滚,每次部署后自进化生成可复用 Skill - 多维度健康监控 — HTTP / TCP / SSL 证书 / 磁盘 / 内存 / CPU / Docker 容器 七维度检查,支持 Cron 定时巡检
- 日志智能分析 — 正则 + LLM 双模式异常检测,11 种内置错误模式,敏感信息自动脱敏,P0/P1/P2 分级告警
- 自进化闭环 — 借助 Hermes Agent 的 Skill 系统和三层记忆,每次运维操作都会沉淀经验,越用越智能
- 开箱即用 — 提供 Docker Compose 一键部署,3 个配置文件即可接入你的基础设施
┌─────────────────────────────────┐
│ FastAPI (uvicorn) │
│ :8000/api/v1/* │
│ /deploy /monitor /alerts │
└──────────────┬──────────────────┘
│
┌──────────────▼──────────────────┐
│ Hermes Agent Core │
│ Skills │ Memory │ Cron │ Tools │
└──────────────┬──────────────────┘
│
┌──────────────▼──────────────────┐
│ Custom Plugins │
│ deploy / monitor / log_analyzer │
└──────────────────────────────────┘
- Python 3.11+
- Git
- Docker(可选,用于容器化部署)
- Hermes Agent(一键安装脚本会自动安装)
# 克隆项目
git clone <repo-url> hermes-agent
cd hermes-agent
# 一键安装(安装 Hermes Agent + Python 依赖 + 链接插件)
chmod +x scripts/install.sh
./scripts/install.sh
# 或手动安装
uv sync编辑 config/targets.yaml 填入你的服务信息:
targets:
- id: my-api
name: "My API Service"
type: http
url: "https://api.example.com/health"
expected_status: 200
timeout_seconds: 10编辑 config/alert_rules.yaml 配置告警规则和 Webhook 地址。
# 开发模式(热重载)
./scripts/start.sh --dev
# Docker 部署
./scripts/start.sh --docker
# 生产模式(gunicorn + 4 workers)
./scripts/start.sh --prod浏览器打开 http://localhost:8000/docs 查看 Swagger API 文档。
| 方法 | 路径 | 说明 |
|---|---|---|
POST |
/api/v1/deploy |
触发部署流水线 |
GET |
/api/v1/deploy/{task_id} |
查询部署任务状态 |
GET |
/api/v1/deploy/history |
部署历史列表 |
触发部署示例:
curl -X POST http://localhost:8000/api/v1/deploy \
-H "Content-Type: application/json" \
-d '{
"repo_url": "https://github.com/user/repo",
"branch": "main",
"environment": "staging",
"steps": ["pull", "test", "build", "deploy", "verify"],
"rollback_on_failure": true
}'响应:
{
"task_id": "deploy-20260507143000-staging",
"repo_url": "https://github.com/user/repo",
"branch": "main",
"environment": "staging",
"status": "running",
"steps_executed": [
{"step": "pull", "success": true, "output": "Already up to date."}
]
}| 方法 | 路径 | 说明 |
|---|---|---|
POST |
/api/v1/monitor |
触发全量/指定目标健康检查 |
GET |
/api/v1/monitor/status |
所有目标最新状态 |
GET |
/api/v1/monitor/status/{id} |
单个目标详情 |
GET |
/api/v1/monitor/history |
监控历史记录 |
触发健康检查示例:
# 全量检查
curl -X POST http://localhost:8000/api/v1/monitor
# 仅检查 HTTP 类型目标
curl -X POST http://localhost:8000/api/v1/monitor \
-H "Content-Type: application/json" \
-d '{"check_type": "http"}'
# 检查指定目标
curl -X POST http://localhost:8000/api/v1/monitor \
-H "Content-Type: application/json" \
-d '{"target_ids": ["api-gateway", "postgres-primary"]}'| 方法 | 路径 | 说明 |
|---|---|---|
POST |
/api/v1/alerts/analyze |
触发日志分析 |
GET |
/api/v1/alerts/history |
告警历史 |
GET |
/api/v1/alerts/rules |
当前告警规则 |
PUT |
/api/v1/alerts/rules |
更新告警规则 |
日志分析示例:
# 分析指定日志文件
curl -X POST http://localhost:8000/api/v1/alerts/analyze \
-H "Content-Type: application/json" \
-d '{
"path": "/var/log/app/error.log",
"max_lines": 5000,
"since_hours": 24
}'
# 分析整个目录(正则模式 + LLM 辅助)
curl -X POST http://localhost:8000/api/v1/alerts/analyze \
-H "Content-Type: application/json" \
-d '{
"path": "/var/log",
"use_llm": true,
"since_hours": 1
}'| 方法 | 路径 | 说明 |
|---|---|---|
GET |
/health |
服务健康检查 |
hermes-agent/
├── api/ # FastAPI 服务层
│ ├── main.py # 应用入口
│ ├── schemas.py # Pydantic 请求/响应模型
│ └── routes/
│ ├── deploy.py # 部署路由
│ ├── monitor.py # 监控路由
│ └── alerts.py # 告警路由
├── plugins/ # Hermes 自定义插件
│ ├── deploy_plugin.py # 部署流水线插件
│ ├── monitor_plugin.py # 服务监控插件
│ └── log_analyzer_plugin.py # 日志分析插件
├── skills/ # 预置 DevOps Skill
│ ├── deploy-rollback.SKILL.md # 部署与回滚
│ ├── health-check.SKILL.md # 健康检查
│ └── incident-response.SKILL.md# 故障响应
├── config/
│ ├── config.yaml # Hermes 主配置
│ ├── targets.yaml # 监控目标定义
│ └── alert_rules.yaml # 告警规则定义
├── scripts/
│ ├── install.sh # 一键安装脚本
│ └── start.sh # 启动脚本
├── tests/ # 测试
├── Dockerfile
├── docker-compose.yml
├── pyproject.toml
└── requirements.txt
| 指标 | 检查方式 | 告警阈值 |
|---|---|---|
| HTTP 状态码 | curl -w '%{http_code}' |
≠ 200 |
| 响应时间 | curl -w '%{time_total}' |
> 2s |
| SSL 证书 | openssl s_client |
< 7 天过期 |
| 磁盘使用率 | df -h |
> 80% 告警,> 95% 紧急 |
| 内存使用率 | free -m |
> 90% |
| CPU 使用率 | top -bn1 |
> 85% |
| Docker 容器 | docker ps -a |
≠ Up |
| 级别 | 响应 SLA | 示例 |
|---|---|---|
| P0 紧急 | 5 分钟确认,60 分钟解决 | 生产服务不可用、数据库断连、磁盘耗尽 |
| P1 重要 | 15 分钟确认,4 小时解决 | 服务响应缓慢、SSL 即将过期、容器异常停止 |
| P2 一般 | 1 小时确认 | 部署通知、磁盘预警、非关键告警 |
Hermes DevOps Agent 借助 Hermes Agent 的闭环学习系统实现持续进化:
- 部署经验沉淀 — 每次部署完成后,
deploy_plugin的post_tool_call钩子自动将成功/失败经验写入SKILL.md,下次遇到同类任务直接复用 - 错误模式学习 —
log_analyzer_plugin将从告警中识别出的新错误模式记录为候选规则,持续扩充识别能力 - 跨会话记忆 — 通过 Hermes 的三层记忆系统(瞬时/工作/长期),Agent 记住各环境的部署参数和历史告警基线
编辑 config/targets.yaml,添加目标后无需重启:
targets:
- id: new-service
name: "New Service"
type: http
url: "https://new.example.com/health"
expected_status: 200编辑 config/alert_rules.yaml,或通过 API 动态更新:
curl -X PUT http://localhost:8000/api/v1/alerts/rules \
-H "Content-Type: application/json" \
-d '{"rules": [...]}'在 plugins/ 目录下创建 .py 文件,Hermes Agent 会自动发现并加载。插件支持注册命令、工具函数和生命周期钩子。详见 Hermes Agent 插件文档。
Hermes Agent 原生支持 17 个消息平台(企业微信、钉钉、飞书、Slack、Telegram 等)。启动消息网关即可将部署结果和告警推送到指定频道:
hermes gateway # 启动消息网关# 配置环境变量
export ANTHROPIC_API_KEY=sk-ant-...
export P0_WEBHOOK_URL=https://hooks.slack.com/...
export P1_WEBHOOK_URL=https://hooks.slack.com/...
# 启动
docker compose up -d
# 查看日志
docker compose logs -f
# 停止
docker compose downMIT