aqeelzaman/IncidentResponseCopilot
GitHub: aqeelzaman/IncidentResponseCopilot
一款基于多 Agent 架构的智能事件响应助手,通过 LangGraph 编排多个专业 Agent 自动分析告警与日志,并在约 90 秒内输出排序后的根因假设及逐步修复方案。
Stars: 0 | Forks: 0
# 事件响应 Copilot
AI 驱动的生产事件分诊系统。用户描述一个生产症状;
一个 LangGraph 监督器并行编排四个专业 Agent,并返回
一个排序后的根因假设和逐步修复计划——所有这些都在约 90 秒内完成。
## 架构
```
User → Next.js UI → FastAPI (SSE) → LangGraph Supervisor
├── Log Analyst → BigQuery
├── Runbook RAG → Pinecone (runbooks)
├── Incident History → Pinecone (incidents)
└── Remediation → GPT-4o (self-reflection)
```
## 技术栈
| 层级 | 技术 |
|-------|-----------|
| Frontend | Next.js 14 App Router · TypeScript · Tailwind CSS |
| Backend | Python 3.11 · FastAPI · Uvicorn · SSE streaming |
| Agents | LangGraph (supervisor pattern) · LangChain ReAct |
| LLM | OpenAI GPT-4o |
| Vector DB | Pinecone (`runbooks` + `incidents` 索引) |
| Data | BigQuery (`incident_copilot` 数据集) |
| Infra | Terraform · Cloud Run · Secret Manager |
| Observability | `trace_id` 贯穿于每次 Agent 调用 |
## 本地设置
### 前置条件
- Python 3.11+
- Node.js 18+
- OpenAI API key
- Pinecone API key
- 启用了 BigQuery 的 GCP 项目 (用于完整功能)
### Backend
```
cd backend
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
# 使用你的 API keys 编辑 .env
# Seed data (需要 GCP + Pinecone credentials)
python data/seed_bigquery.py
python data/seed_pinecone.py
# 运行 backend
python main.py
# → http://localhost:8000
```
### Frontend
```
cd frontend
npm install
cp .env.example .env.local
# 设置 BACKEND_URL=http://localhost:8000
npm run dev
# → http://localhost:3000
```
### 运行测试
```
cd backend
pytest tests/ -v
```
## 演示场景
**输入:**
**预期输出:**
- **Log Analyst:** BigQuery 中的 847 条 ERROR 日志 + `p99_latency = 4.2s`
- **Runbook RAG:** "DB Connection Pool Exhaustion" — 将 `pool_size` 从 10 增加到 50
- **Incident History:** 2 个相似的过往事件 (均为 DB pool exhaustion)
- **Remediation:** 根因:DB connection pool 已耗尽 (置信度: 0.91)。立即措施:修补 ConfigMap,重启 pod。后续措施:添加 pool 监控告警。
## GCP 部署
### 1. 构建并推送后端镜像
```
gcloud auth configure-docker
docker build -t gcr.io//incident-copilot:latest backend/
docker push gcr.io//incident-copilot:latest
```
### 2. 在 Secret Manager 中填充密钥
```
echo -n "sk-..." | gcloud secrets versions add openai-api-key --data-file=-
echo -n "pc-..." | gcloud secrets versions add pinecone-api-key --data-file=-
```
### 3. 应用 Terraform
```
cd infra
terraform init
terraform apply -var="project_id=" -var="backend_image=gcr.io//incident-copilot:latest"
```
### 4. 部署前端到 Vercel 或 Cloud Run
将 `BACKEND_URL` 环境变量设置为 Terraform 输出的 Cloud Run URL。
## 项目结构
```
incident-copilot/
├── frontend/ # Next.js 14 App Router UI
│ └── app/
│ ├── page.tsx # Three-panel chat interface
│ ├── api/triage/ # SSE proxy to FastAPI
│ └── components/ # IncidentInput, ChatWindow, TriageReport
├── backend/
│ ├── main.py # FastAPI + SSE streaming endpoint
│ ├── middleware/trace.py # trace_id injection via ContextVar
│ ├── agents/ # LangGraph nodes + specialist agents
│ │ ├── supervisor.py # StateGraph with parallel fan-out
│ │ ├── log_analyst.py # ReAct agent — BigQuery tools
│ │ ├── runbook_rag.py # ReAct agent — Pinecone runbook search
│ │ ├── incident_history.py # ReAct agent — Pinecone incident search
│ │ └── remediation.py # 3-step self-reflection chain (no tools)
│ ├── tools/ # LangChain @tool definitions
│ ├── data/ # Seed scripts + 50 runbook markdown files
│ └── tests/ # pytest with mocked LLM calls
└── infra/ # Terraform: Cloud Run, BigQuery, Secrets, VPC
```
## 可观测性
每个请求都会获得一个由 `TraceMiddleware` 注入的 `trace_id` (UUID)。它会:
- 存储在 `request.state.trace_id` 中
- 通过 `contextvars.ContextVar` 对所有 Agent 可用
- 在每次 LLM 调用中作为 `metadata.trace_id` 传递
- 在 SSE `done` 事件和 `X-Trace-ID` 响应头中返回
- 记录到 `BigQuery.trace_log` 表中
标签:AIOps, AV绕过, BigQuery, Cloud Run, DLL 劫持, ECS, FastAPI, GPT-4o, IT运维, LangChain, LangGraph, PagerDuty, Pinecone, PyRIT, Python, RAG, React, Socks5代理, SRE, SSE, Syscalls, Tailwind CSS, Terraform, TypeScript, 人工智能, 修复计划, 偏差过滤, 前后端分离, 向量数据库, 告警关联, 告警分诊, 多智能体系统, 大语言模型, 安全插件, 故障排查, 无后门, 根因分析, 模块化设计, 用户模式Hook绕过, 自动化修复, 自动化运维, 轻量级, 逆向工具