jadhav-prathamesh/aegis-incident-response
GitHub: jadhav-prathamesh/aegis-incident-response
一个基于多智能体架构的 AI 事件响应平台,用于自动化生产事件的根因分析、修复执行和效果验证。
Stars: 0 | Forks: 0
# Aegis — "Multi-Agent AI 事件响应平台"
这是一个用于自动化生产事件管理的多智能体 AI 事件响应平台,负责统筹完整的事件生命周期:理解、根因分析、修复规划、执行、监控和验证。
## 架构
```
Incident → Orchestrator → Planner → Executor → Observer → Validator
↓ ↓ ↓ ↓ ↓
Decision RCA Plan Actions Health Validation
+ Search + Approval + Metrics + Compliance
```
### 核心 Agent
| Agent | 职责 |
|-------|---------------|
| **Orchestrator** | 接收事件,做出由 LLM 驱动的决策,协调所有 Agent |
| **Planner** | 事件理解,任务分解,通过向量搜索进行修复规划 |
| **Executor** | 运行已批准的操作(重启、扩容、回滚、故障转移等) |
| **Observer** | 健康检查、Prometheus 指标、告警关联、日志分析 |
| **Validator** | 通过合成测试、合规性检查、基线对比来验证修复效果 |
### 核心服务
| 模块 | 描述 |
|--------|-------------|
| `config.py` | Pydantic Settings,包含 11 个嵌套配置组 |
| `models.py` | 30 多个 Pydantic 领域模型和枚举 |
| `exceptions.py` | 30 多个带有 HTTP 映射的类型化异常类 |
| `embeddings.py` | 兼容 OpenAI 的嵌入服务,具备本地兜底 |
| `vector_db.py` | ChromaDB 和 pgvector 后端 |
| `knowledge_base.py` | 语义 + 词法混合知识搜索 |
| `action_dispatcher.py` | 15 个带有真实 shell 执行能力的操作处理器 |
| `approval.py` | 完整的审批工作流,支持开发环境自动审批 |
| `monitoring.py` | HTTP/TCP 健康检查、Prometheus、Alertmanager、k8s 状态 |
| `validation.py` | 合成测试、合规性检查、基线对比 |
| `similar_incidents.py` | 向量 + 暴力搜索的事件相似度检索 |
| `incident_store.py` | 内存级事件存储库 |
| `logging.py` | Structlog,带有标准库兜底 |
## 技术栈
- **语言:** Python 3.12+
- **AI:** LangGraph, LangChain, 兼容 OpenAI 的 API
- **后端:** FastAPI + uvicorn
- **Vector DB:** ChromaDB / pgvector
- **缓存:** Redis
- **数据库:** PostgreSQL (asyncpg)
- **监控:** Prometheus, Grafana
- **仪表盘:** Streamlit
- **基础设施:** Docker, Docker Compose
- **测试:** pytest (54 个测试)
## 快速开始
### 前置条件
- Python 3.12+
- Docker & Docker Compose(用于全栈部署)
### 本地开发
```
# 创建并激活 virtual environment
python -m venv .venv
.venv\Scripts\activate
# 安装所有 dependencies
pip install -e ".[dev]"
# 运行所有测试(54 个测试)
python -m pytest tests/ -v
# 启动 API server (http://localhost:8000)
python -m src.main
# 启动 dashboard (http://localhost:8501)
streamlit run src/dashboard/app.py
```
### 快速 API 验证
```
# 在另一个终端中,验证 API 是否正在运行:
curl http://localhost:8000/health
# Response: {"status":"healthy","version":"1.0.0"}
curl http://localhost:8000/ready
# Response: {"status":"ready"}
```
### Docker Compose (全栈)
```
# 复制并编辑 environment config
cp .env.example .env
# 启动所有服务
docker-compose up -d
```
这将启动:
- **API** — `http://localhost:8000`
- **仪表盘** — `http://localhost:8501`
- **PostgreSQL** — `localhost:5432`
- **Redis** — `localhost:6379`
- **ChromaDB** — `localhost:8100`
- **Prometheus** — `localhost:9090`
- **Grafana** — `localhost:3000`
## API Endpoint
### 健康
- `GET /health` — 存活探针
- `GET /ready` — 就绪探针
- `GET /info` — 平台信息
### 事件
- `GET /api/v1/incidents` — 列出所有事件
- `GET /api/v1/incidents/{id}` — 通过 ID 获取事件
- `POST /api/v1/incidents` — 创建事件
- `PATCH /api/v1/incidents/{id}` — 更新事件
- `GET /api/v1/incidents/{id}/similar` — 查找相似事件
### 审批
- `GET /api/v1/approvals/pending` — 列出待审批请求
- `POST /api/v1/approvals` — 创建审批请求
- `POST /api/v1/approvals/{id}/approve` — 批准
- `POST /api/v1/approvals/{id}/reject` — 拒绝
### Agent
- `POST /api/v1/agents/execute` — 执行 Agent 任务
- `GET /api/v1/agents/types` — 列出 Agent 类型
- `GET /api/v1/agents/{type}/health` — Agent 健康检查
### 监控
- `GET /api/v1/monitoring/health/{service}` — HTTP 健康检查
- `GET /api/v1/monitoring/metrics/{resource}` — 资源指标
- `GET /api/v1/monitoring/alerts` — 活跃告警
- `GET /api/v1/monitoring/deployments/{service}` — 部署状态
### 验证
- `POST /api/v1/validation/synthetic` — 运行合成测试
- `POST /api/v1/validation/alerts` — 验证告警解决情况
- `POST /api/v1/validation/compliance` — 检查合规性
- `POST /api/v1/validation/baselines` — 对比基线
- `POST /api/v1/validation/rollback` — 验证回滚
## 配置
所有配置均通过环境变量或 `.env` 文件进行管理。嵌套配置使用带有前缀的环境变量:
| 前缀 | 配置类 | 示例 |
|--------|---------------|---------|
| `DB_` | DatabaseSettings | `DB_HOST=localhost` |
| `REDIS_` | RedisSettings | `REDIS_PORT=6379` |
| `VECTOR_DB_` | VectorDBSettings | `VECTOR_DB_PROVIDER=chroma` |
| `LLM_` | LLMSettings | `LLM_MODEL=gpt-4` |
| `AGENT_` | AgentSettings | `AGENT_DEFAULT_TIMEOUT=300` |
| `SECURITY_` | SecuritySettings | `SECURITY_SECRET_KEY=...` |
| `MONITORING_` | MonitoringSettings | `MONITORING_PROMETHEUS_URL=...` |
| `INTEGRATION_` | IntegrationSettings | `INTEGRATION_SLACK_ENABLED=true` |
## 项目结构
```
incident-intelligence-platform/
├── src/
│ ├── core/ # Domain logic, services, models
│ ├── agents/ # AI agent implementations (LangGraph)
│ ├── api/ # FastAPI REST endpoints
│ ├── dashboard/ # Streamlit dashboard
│ └── main.py # API entry point
├── tests/ # 54 pytest tests
├── config/ # Prometheus config
├── Dockerfile
├── docker-compose.yml
└── pyproject.toml
```
## 测试
```
# 运行所有测试
python -m pytest tests/ -v
# 运行特定测试文件
python -m pytest tests/test_api.py -v
# 运行并生成 coverage
python -m pytest tests/ --cov=src
```
## 已知的 Windows 问题
- **uuid_utils DLL 被阻止**:Windows 应用程序控制可能会阻止原生 `_uuid_utils.pyd` 扩展。应用程序会自动回退到纯 Python 的 `uuid4()` 生成方式。无需更改配置。
## 许可证
开源
标签:AIOps, DLL 劫持, Kubernetes, 多智能体, 大语言模型, 搜索引擎查询, 故障响应, 根因分析, 测试用例, 自定义请求头, 请求拦截, 运维自动化, 逆向工具