vatsal2412/incident-response-agent
GitHub: vatsal2412/incident-response-agent
基于历史知识库学习的AI多智能体事件响应系统,通过复用过往解决方案来大幅降低运维事件的MTTR。
Stars: 0 | Forks: 0
# 🚨 Incident Response Agent





**Team Secureonix | HackBaroda 2026**
*一个能够记住过往事件并从中学习的 AI 多智能体系统,可自动降低未来类似事件的 MTTR。*
## 📋 问题描述
**事件响应与历史学习**
技术社区和开源项目经常面临运维事件 —— 服务中断、安全问题和基础设施故障。每个事件都需要耗时的人工调查和解决。
**核心挑战**:团队反复从零开始解决同类事件,因为机构知识处于孤岛状态、未记录,或者在危机期间无法访问。
## 💡 解决方案概述
**Incident Response Agent** 是一个多智能体 AI 系统,它实现了一个 **7 阶段调查工作流**,并由包含 66 条真实事件记录的**持久化知识库**提供支持。
### 历史知识如何降低 MTTR
```
New Incident Submitted
│
▼
┌─────────────────────┐
│ Knowledge Search │ ← Searches 66+ historical incidents
│ (Similarity ≥ 60%) │ using weighted text + tag + metric matching
└────────┬────────────┘
│
┌────┴────┐
│ Match? │
└────┬────┘
Yes ──┘└── No
│ │
▼ ▼
MTTR: 2 min MTTR: 35 min ← Baseline manual debugging time
(AI reuses (New incident
solution) discovered)
```
当找到**相似度 >90%** 的事件时,智能体会在 **~2 分钟**内重用经过验证的解决方案,而人工**基线为 35 分钟** —— **MTTR 降低了 94%**。
## ✨ 已实现的功能
### 核心 AI 能力
| 功能 | 描述 |
|---|---|
| 🧠 **7 阶段调查** | 协调的多智能体工作流:知识检索 → 评估 → 深度调查 → 根因分析 → 解决方案生成 → 补救计划 → 学习 |
| 📚 **历史学习** | 持久化的 JSON 知识库,包含 66 个预置的真实事件;随着每次调查不断增长 |
| 🔍 **相似度匹配** | 跨标题 (30%)、描述 (20%)、服务 (20%)、标签 (15%)、指标 (15%) 的加权评分 |
| ⚡ **MTTR 降低** | 对于已知事件模式,从 35 分钟基线降低至 2 分钟 |
| 🤖 **多智能体系统** | 7 个专用智能体:InvestigatorAgent、KubernetesAgent、CloudAgent、MetricsAgent、LogAgent、CodeAnalysisAgent、HistoricalLearningAgent |
### 调查与分析
| 功能 | 描述 |
|---|---|
| 🎯 **根因检测** | 从以下方面识别原因:指标异常、日志模式、K8s pod 故障、代码回退、历史匹配 |
| 🛠️ **Git Diff 生成** | 为检测到的回退自动生成建议的代码/配置补丁 |
| 📋 **补救计划** | 带有优先级(紧急/高/中)和时间估算的分步行动计划 |
| 📊 **置信度评分** | 每个根因都根据证据权重附有置信度百分比 |
### 运维功能
| 功能 | 描述 |
|---|---|
| 🔔 **Webhook 摄取** | `POST /api/webhooks/alerts` — 接收 Alertmanager、Datadog 或通用 payload;触发后台调查 |
| 💬 **RAG 聊天机器人** | 浮动 AI 助手(右下角),通过引用知识库来回答问题 |
| ▶️ **交互式 Runbook** | 终端模态框,模拟执行补救命令并显示真实的日志输出 |
| 🔧 **Git 补丁 UI** | 显示建议的代码修复,以及一个“创建 Pull Request”操作按钮 |
| 📈 **MTTR 学习曲线** | 展示随着知识库增长 MTTR 随时间降低的 SVG 图表 |
### UI/UX
| 功能 | 描述 |
|---|---|
| 🌑 **深色玻璃拟态** | 采用玻璃拟态卡片、霓虹灯强调色和流畅动画的高级深色 UI |
| 🤖 **浮动 AI 助手** | 带有弹跳效果的机器人 FAB 按钮;可展开为全屏聊天面板 |
| ⏱️ **实时调查时间线** | 调查期间显示 7 步动画工作流进度条 |
| 📱 **响应式设计** | 适用于桌面和移动屏幕 |
| 🔴 **实时系统状态** | 带有 30 秒健康状态轮询的页眉指示器 |
## 🗂️ 数据集
**66 个预置的真实事件**,涵盖:
| 类别 | 数量 | 示例 |
|---|---|---|
| Kubernetes | 18 | CoreDNS 循环、etcd 压缩、驱逐风暴、RBAC 配置错误 |
| 网络 | 12 | Route53 TTL 配置错误、BGP 路由泄漏、mTLS 握手失败 |
| 数据库 | 10 | PostgreSQL 锁争用、连接池耗尽、复制延迟 |
| 安全 | 9 | CI 日志中的 Secret 泄露、Vault token 轮换失败 |
| Cloud/AWS | 8 | EBS 吞吐量限制、S3 对象锁定冲突、Lambda 冷启动级联 |
| CI/CD | 9 | ArgoCD 同步失败、Helm chart 版本漂移、部署回退 |
每个事件记录包含:`incident_id`、`title`、`severity`、`category`、`description`、`symptoms`、`root_cause`、`mitigation`、`resolution`、`prevention`、`mttr_minutes`。
数据集跨越两个时间批次(INC-2026-001 到 INC-2026-066),旨在展示智能体学习过程中 MTTR 的衰减情况。
## 🛠️ 技术栈
### 后端
- **Python 3.10+** — 核心语言
- **FastAPI** — 异步 REST API 框架
- **Uvicorn** — ASGI 服务器
- **Pydantic v2** — 请求/响应验证
- **Loguru** — 结构化日志记录
- **difflib** — 相似度匹配 (SequenceMatcher)
### 前端
- **Vanilla JavaScript** (ES2020,无框架)
- **HTML5 + CSS3** — 玻璃拟态深色 UI
- **SVG** — 自定义 MTTR 学习曲线图表
- **Google Fonts** — Outfit + JetBrains Mono
- **Fetch API** — 异步后端通信
### 数据存储
- **JSON 文件** — `knowledge_base/incidents.json`、`root_causes.json`、`solutions.json`、`patterns.json`
- 零外部数据库依赖 — 完全可移植
### 基础设施
- **Docker + Docker Compose** — 容器化部署
- **pytest + anyio** — 异步测试套件(9 个测试,100% 通过)
### 可选集成
- **Slack Bolt** — Slack events API(已配置,凭据可选)
- **Webhook 端点** — Alertmanager / Datadog / 通用 payload
## 📁 项目结构
```
Incident-Response-Agent-main/
├── agents/
│ └── agents.py # 7 specialized investigation agents
├── api/
│ └── server.py # FastAPI routes (12 endpoints)
├── backend/
│ ├── orchestrator.py # 7-phase workflow coordinator
│ └── knowledge_manager.py # KB CRUD + similarity matching
├── config/
│ └── settings.py # Environment-based configuration
├── frontend/ # Web dashboard UI files
│ ├── index.html # SPA shell
│ ├── script.js # All UI logic (~930 lines)
│ └── style.css # Glassmorphism theme (~1350 lines)
├── integrations/
│ └── slack_bot.py # Slack Bolt integration
├── knowledge_base/ # Runtime JSON storage (auto-created)
│ ├── incidents.json
│ ├── root_causes.json
│ ├── solutions.json
│ └── patterns.json
├── screenshots/ # Application screenshots
├── tests/
│ ├── test_agents.py # Agent unit tests
│ ├── test_new_features.py # Webhook / chat / runbook tests
│ └── test_orchestrator.py # MTTR learning tests
├── main.py # CLI investigation entry point
├── run_web_server.py # Web server launcher
├── requirements.txt
├── .env.example
├── GETTING_STARTED.md # Guide on getting started
├── PROJECT_SUMMARY.md # High-level architecture overview
├── USER_GUIDE.md # User guide for running agent
├── setup.bat # Setup script for Windows
├── setup.sh # Setup script for Linux/macOS
├── Dockerfile
├── docker-compose.yml
└── README.md
```
## 🚀 设置说明
### 前置条件
- Python 3.10 或更高版本
- pip(随 Python 提供)
- Git
### 1. 克隆仓库
```
git clone https://github.com/Nandinivora18/Incident-Response-Agent.git
cd Incident-Response-Agent-main
```
### 2. 创建虚拟环境
```
# Windows
python -m venv venv
.\venv\Scripts\activate
# Linux / macOS
python3 -m venv venv
source venv/bin/activate
```
### 3. 安装依赖
```
pip install -r requirements.txt
```
### 4. 配置环境(可选)
```
cp .env.example .env
# 如有需要编辑 .env — 默认设置开箱即用
```
### 5. 运行应用程序
```
python run_web_server.py
```
在浏览器中打开 **http://localhost:8000**。✅
### 6. 运行测试
```
python -m pytest tests/ -v
# 预期:9 个通过
```
### Docker(替代方案)
```
docker-compose up -d
# App 可通过 http://localhost:8000 访问
```
## 🔗 API 参考
### 核心端点
| 方法 | 端点 | 描述 |
|---|---|---|
| `GET` | `/api/health` | 系统健康检查 |
| `POST` | `/api/investigate` | 提交事件以进行调查 |
| `GET` | `/api/knowledge-base/incidents` | 列出存储的事件 |
| `GET` | `/api/knowledge-base/root-causes` | 常见根因模式 |
| `GET` | `/api/knowledge-base/solutions` | 解决方案库 |
| `GET` | `/api/knowledge-base/stats` | 知识库统计信息(MTTR、重用率) |
| `GET` | `/api/knowledge-base/similar/{title}` | 查找相似的历史事件 |
| `POST` | `/api/knowledge-base/chat` | RAG 聊天机器人查询 |
| `POST` | `/api/remediation/run-step` | 执行补救步骤(模拟) |
| `POST` | `/api/webhooks/alerts` | 接收 Alertmanager/Datadog webhook |
| `POST` | `/api/store-incident` | 手动存储事件 |
| `POST` | `/slack/events` | Slack 事件处理程序 |
### 示例:调查事件
```
curl -X POST http://localhost:8000/api/investigate \
-H "Content-Type: application/json" \
-d '{
"title": "CoreDNS Loop Detected in Kubernetes Cluster",
"severity": "high",
"service": "kubernetes-dns",
"affected_services": ["all-pods"],
"description": "Pods are logging Host not found exceptions. CoreDNS logs show Loop network loop detected panics.",
"logs": ["ERROR: Loop network loop detected", "Host not found: kubernetes.default"]
}'
```
**响应包含**:`root_cause`、`confidence`、`remediation_plan`、`similar_incidents`、`mttr_minutes`、`git_diff`、`learning_applied`
### 示例:Webhook 告警
```
curl -X POST http://localhost:8000/api/webhooks/alerts \
-H "Content-Type: application/json" \
-d '{
"alerts": [{
"labels": {"alertname": "HighMemoryUsage", "severity": "high", "service": "api-gateway"},
"annotations": {"description": "Memory usage exceeded 90% threshold"},
"status": "firing"
}]
}'
```
## 📸 截图
### 实时系统仪表板视图

### 主仪表板

### 调查输入表单

### 活动智能体调查进度

### 详细调查结果

### 知识库浏览器

### 学习指标与统计曲线

### 调查审计历史

## 📊 性能
| 指标 | 数值 |
|---|---|
| MTTR — 新事件 | ~35 分钟(基线) |
| MTTR — 已知事件(>90% 匹配) | **~2 分钟** |
| MTTR 降低幅度 | **94%** |
| 知识库规模 | 66 个事件(预置) |
| 测试套件 | 9 个测试,100% 通过率 |
| 调查阶段 | 7 |
| API 端点 | 12 |
| 调查超时时间 | 120 秒 |
## 🧪 测试结果
```
tests/test_agents.py::test_metrics_agent PASSED
tests/test_agents.py::test_log_agent PASSED
tests/test_agents.py::test_k8s_agent PASSED
tests/test_agents.py::test_cloud_agent PASSED
tests/test_agents.py::test_code_analysis_agent PASSED
tests/test_new_features.py::test_run_remediation_step PASSED
tests/test_new_features.py::test_knowledge_base_chat PASSED
tests/test_new_features.py::test_receive_webhook_alert_generic PASSED
tests/test_orchestrator.py::test_orchestrator_new_vs_similar_mttr PASSED
======================== 9 passed in 3.02s ========================
```
## 🏗️ 架构
```
┌─────────────────────────────────────────────────────────┐
│ Frontend (SPA) │
│ Investigate │ Knowledge Base │ Statistics │ History │
│ + Floating AI Chatbot │
└──────────────────────┬──────────────────────────────────┘
│ HTTP / Fetch API
┌──────────────────────▼──────────────────────────────────┐
│ FastAPI (api/server.py) │
│ /investigate /chat /webhooks /remediation /health │
└──────────────────────┬──────────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────────┐
│ IncidentOrchestrator (7 phases) │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────────┐ │
│ │ K8sAgent │ │CloudAgent│ │MetricAgt │ │ LogAgent │ │
│ └──────────┘ └──────────┘ └──────────┘ └───────────┘ │
│ ┌──────────┐ ┌──────────────────┐ │
│ │CodeAgent │ │HistoricalLearning│ │
│ └──────────┘ └──────────────────┘ │
└──────────────────────┬──────────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────────┐
│ KnowledgeManager (JSON Storage) │
│ incidents.json │ root_causes.json │ solutions.json │
└─────────────────────────────────────────────────────────┘
```
## 📄 许可证
Apache 2.0 — 详情请参阅 [LICENSE](LICENSE)。
**由 Team Secureonix 用 ❤️ 构建 | HackBaroda 2026**
*AI 驱动的事件响应,在每次中断后都变得更聪明。*
标签:AI智能体, AV绕过, FastAPI, Python, Ruby, 安全规则引擎, 无后门, 知识库, 请求拦截, 运维自动化, 逆向工具