ToddLong6/incident-triage-agent
GitHub: ToddLong6/incident-triage-agent
基于AI的事件分级代理,自动化基础设施事件响应。
Stars: 0 | Forks: 0
# 事件分级代理
使用 **Google Cloud ADK**、**Gemini** 和 **MongoDB Atlas** 作为持久性组织记忆构建的 AI 动力型基础设施事件分级。
提交至 **Google Cloud 快速代理黑客松 — MongoDB 轨道**。
## 架构
```
┌──────────────────────────────────────────────────────────────────────┐
│ Incident Triage Agent │
│ │
│ ┌─────────────┐ ┌──────────────────────────────────────────┐ │
│ │ Dashboard │────▶│ Root Agent (ADK / Gemini) │ │
│ │ (HTML/JS) │◀────│ gemini-3.1-pro-preview │ │
│ │ SSE stream │ └────────┬─────────────┬────────────────┘ │ │
│ └─────────────┘ │ │ │ │
│ ┌─────────┘ └──────────┐ │ │
│ ┌──────▼──────┐ ┌───────────────▼──────┐ │ │
│ │ MongoDB │ │ Sub-Agent Pool │ │ │
│ │ MCP Server │ │ ┌─────────────────┐ │ │ │
│ │ (Cloud Run)│ │ │ Google Search │ │ │ │
│ │ │ │ │ Agent │ │ │ │
│ │ incidents │ │ ├─────────────────┤ │ │ │
│ │ collection │ │ │ URL Context │ │ │ │
│ │ (8 records)│ │ │ Agent │ │ │ │
│ └─────────────┘ │ └─────────────────┘ │ │ │
│ └──────────────────────┘ │ │
└──────────────────────────────────────────────────────────────────────┘
```
### 数据流
```
Alert Input ──▶ Root Agent ──▶ Step 1: Investigate
│ └─▶ MongoDB MCP: find similar incidents
│
├──────────▶ Step 2: Diagnose (root cause + confidence)
│
├──────────▶ Step 3: Present Findings
│ └─▶ [Human approval gate]
│
├──────────▶ Step 4: Generate Runbook (if approved)
│ └─▶ [Human approval gate]
│
├──────────▶ Step 5: Draft Stakeholder Email (if approved)
│
└──────────▶ Step 6: Log Incident ──▶ MongoDB Atlas
```
## MongoDB 架构
集合:`incident-triage-db` 中的 `incidents`
```
{
"incident_id": "INC-2024-001",
"title": "Payments API 500 errors",
"service": "payments-api",
"category": "api-failure",
"severity": "critical",
"description": "...",
"root_cause": "Database connection pool exhausted",
"runbook": ["Step 1: ...", "Step 2: ..."],
"resolution": "Increased pool size, deployed fix",
"tags": ["payments", "database", "connection-pool"]
}
```
## 设置
### 前置条件
- Python 3.11+(在 3.13 上测试过)
- 启用 Vertex AI API 的 Google Cloud 项目
- Google API 密钥 **或** 应用默认凭证(`gcloud auth application-default login`)
### 1 — 克隆并安装
```
git clone https://github.com/ToddLong6/incident-triage-agent.git
cd incident-triage-agent
pip install -r requirements.txt
```
### 2 — 配置环境
```
Copy-Item .env.example .env
# 编辑 .env 并添加 GOOGLE_API_KEY
notepad .env
```
### 3 — 运行
```
python server.py
```
然后在浏览器中打开 **http://localhost:8000/dashboard/**。
## 6 步分级工作流程
| 步骤 | 名称 | 描述 | 审批 |
|------|------|-------------|----------|
| 1 | **调查** | 分析警报 + 查询 MongoDB 中的类似事件 | 自动 |
| 2 | **诊断** | 以置信度水平识别根本原因 | 自动 |
| 3 | **呈现发现** | 总结影响、受影响系统、模式 | 自动 |
| 4 | **生成运行手册** | 具有回滚步骤的逐步修复 | 人工门控 |
| 5 | **起草电子邮件** | 专业利益相关者沟通 | 人工门控 |
| 6 | **记录事件** | 将完整记录持久化到 MongoDB Atlas | 自动 |
## 演示脚本
1. 打开 `http://localhost:8000/dashboard/`
2. 确保 **API 在线** 状态指示器为绿色,MongoDB 在右侧面板显示事件
3. 填写警报表单:
- **标题**:`Payments API 返回 500`
- **服务**:`payments-api`
- **严重性**:`CRITICAL`
- **描述**:`错误率在 UTC 14:23 时激增至 45%。日志中 Postgres 连接超时。结账流程中断。`
- **受影响系统**:`payments-api, checkout, postgres`
4. 点击 **运行分级**
5. 观察中心面板中的 6 个步骤流
6. MongoDB 历史匹配在右侧面板中突出显示
7. 批准运行手册 → 批准电子邮件 → 事件自动记录到 Atlas
## 项目结构
```
incident-triage-agent/
├── server.py # FastAPI server + MongoDB API endpoints
├── incident_triage_agent/
│ ├── __init__.py
│ └── agent.py # ADK root agent + sub-agents
├── frontend/
│ ├── index.html # Dark ops dashboard
│ ├── style.css # Dark theme with green accents
│ └── app.js # ADK SSE streaming client
├── requirements.txt
├── .env.example
├── .gitignore
└── LICENSE
```
## 技术栈
| 层 | 技术 |
|-------|------------|
| 代理框架 | Google Cloud ADK 2.1 |
| LLM | Gemini 3.1 Pro Preview |
| 持久性内存 | MongoDB Atlas(Cloud Run 上的 MCP 服务器) |
| 网络搜索 | Google Search Tool(ADK 内置) |
| URL 上下文 | ADK URL 上下文工具 |
| 后端 | FastAPI + uvicorn |
| 前端 | Vanilla HTML/CSS/JS(无框架) |
标签:ADK, Gemini, Google Cloud, Google Cloud Rapid Agent Hackathon, MongoDB Atlas, MongoDB Track, OISF, 事件分类, 人工智能, 基础设施, 开源框架, 持续集成, 故障处理, 故障诊断, 日志管理, 用户模式Hook绕过, 组织记忆, 自动化运维, 自定义脚本, 运行手册, 黑客松