17arhaan/Autonomous-Incident-Response-Agent

GitHub: 17arhaan/Autonomous-Incident-Response-Agent

基于多智能体协作的生产故障自动诊断与修复建议系统,利用 LLM 做根因分析并生成结构化报告。

Stars: 0 | Forks: 0

# 自主事件响应智能体 用于诊断生产事件并生成结构化报告的多智能体系统。 完整设计请参阅 `Incident_Response_Agent_Design.md`。 ## 技术栈 - Java 21, Spring Boot 3.3 - LangChain4j (LLM 提供者将在第 3 周及以后接入) - PostgreSQL (事件、智能体执行记录、通过 pgvector 实现的 Runbook 嵌入) - Redis (基线缓存、幂等性、SSE) ## 状态 **第 1-2 周 — 基础架构 (已完成)** - [x] 项目脚手架 (Maven, Spring Boot, 依赖项) - [x] 核心领域模型 (`IncidentTrigger`, `IncidentContext`, `AgentResult`, `IncidentReport`) - [x] `Agent` 接口 + 包含计时器/指标/错误包装的 `BaseAgent` - [x] 带有四阶段扇出/扇入管道的 `OrchestratorImpl` - [x] 针对 `incidents` + `agent_executions` 的 Flyway 数据库模式 - [x] REST API (`POST /api/incidents`, `GET /api/incidents/{id}`, 列表, 智能体追踪) - [x] 用于 Postgres + Redis 的 Docker Compose 配置 **第 3-4 周 — 核心智能体 (已完成)** - [x] `LlmClient` 抽象 + Stub 提供者 (可通过 `incident.llm.provider` 切换为真实提供者) - [x] `LogFetcherTool` (基于文件的 JSONL 固定数据) + `LogAggregatorTool` (堆栈跟踪聚类) - [x] `MetricsFetcherTool` + `BaselineCalculatorTool` (7天基线, 窗口内最大值比较) - [x] `DeployHistoryTool` (模拟 GitHub 发布) - [x] 真实的 `LogAnalyzerAgent` (聚类 → LLM 摘要) - [x] 真实的 `MetricsAgent` (偏差检测 > 2x → LLM 摘要) - [x] 真实的 `RootCauseAgent` (跨越日志 + 指标 + 部署的思维链, 并在上游数据降级时进行置信度校准) - [x] 场景 1 固定数据 (数据库连接池耗尽) **第 5 周 — Runbook 系统 (已完成)** - [x] YAML Runbook 库 (5 个 Runbook: db-pool, latency-cascade, service-down, memory-leak, deploy-regression) - [x] `RunbookLoader` 在启动时将 YAML 解析为类型化的 `Runbook` 记录 - [x] `RunbookSearchTool` — 内存中的 TF-IDF 余弦相似度 (与提供者无关,以便后续可以无缝接入 pgvector 后端) - [x] 真实的 `RunbookAgent` — Top-K 搜索, 基于阈值的匹配, 无匹配结果时的 LLM 降级备选方案 **第 6 周 — 通信器 + 实时进度 (已完成; Slack 发送已暂停)** - [x] `TemplateRendererTool` — 对 `classpath:templates/*.md` 进行 `{{key}}` 占位符替换 - [x] 模板: `slack-incident.md`, `postmortem.md`, `status-page.md` - [x] `CommunicatorAgent` 消费完整的组装上下文并渲染所有三个产物 - [x] `ProgressBus` + `/api/incidents/{id}/stream` (SSE) — 发出分阶段和分智能体的事件; 新订阅者从缓冲区中回填历史事件 - [ ] Slack 出站 Webhook — 已暂停 **第 7 周 — 优化与可靠性 (已完成)** - [x] MDC 关联日志 (`incidentId` + `agent` 贯穿每一行日志) - [x] 置信度校准:当日志/指标智能体降级时,会限制根因的置信度上限 - [x] Micrometer 指标:按智能体划分的 `agent.success`, `agent.failure`, `agent.duration`;通过 `/actuator/prometheus` 进行 Prometheus 抓取 - [x] 位于 `/ui` 的 Thymeleaf 仪表盘 — 列表视图 + 带有实时 SSE 进度、已渲染的假设、修复措施和完整复盘的详情视图 **第 8 周 — 演示场景与文档 (已完成)** - [x] 场景 1 固定数据 — 数据库连接池耗尽 (在 2026-04-28T14:32Z 的部署回退) - [x] 场景 2 固定数据 — recommender-service 中的内存泄漏 (近期无部署; 2026-04-30T11:55Z) - [x] 场景 3 固定数据 — auth-service 的级联超时 (2026-05-01T09:00Z) - [x] `scripts/trigger-scenarios.sh` — `./scripts/trigger-scenarios.sh [1|2|3|all]` - [x] README + 运行说明 - 第 6 周 — Slack 集成 + SSE 实时进度 - 第 7 周 — 置信度校准、可观测性、Web 仪表盘 - 第 8 周 — 三个演示场景 + 文档 ## 运行 ``` docker compose up -d ./mvnw spring-boot:run ``` 触发演示场景: ``` ./scripts/trigger-scenarios.sh 1 # DB connection pool exhaustion ./scripts/trigger-scenarios.sh 2 # Memory leak ./scripts/trigger-scenarios.sh 3 # Cascading auth timeouts ./scripts/trigger-scenarios.sh all ``` 或直接调用 API: ``` curl -X POST http://localhost:8080/api/incidents \ -H "Content-Type: application/json" \ -d '{ "source": "manual", "title": "Payment service errors spiking", "severity": "SEV2", "detectedAt": "2026-04-28T14:32:30Z", "affectedServices": ["payment-service", "order-service"] }' ``` 获取报告或流式传输实时进度: ``` curl http://localhost:8080/api/incidents/ curl http://localhost:8080/api/incidents//agents curl -N http://localhost:8080/api/incidents//stream # SSE ``` 在 浏览仪表盘。 Prometheus 指标:。 ## 布局 ``` src/main/java/com/arhaan/incident/ ├── IncidentApplication.java ├── api/ # REST + dashboard controllers, SSE stream ├── orchestrator/ # OrchestratorImpl, four-phase executor, ProgressBus ├── agents/ # Agent interface, BaseAgent, 5 agents ├── tools/ # Log/metrics/deploy/template tools ├── runbook/ # Runbook record, loader, search (TF-IDF) ├── llm/ # LlmClient interface, stub, prompt templates ├── models/ # domain records, enums, agent payloads ├── persistence/ # JPA entities + repositories └── config/ # AsyncConfig src/main/resources/ ├── application.yml ├── runbooks/ # 5 YAML runbooks ├── templates/ # Thymeleaf HTML + markdown templates ├── fixtures/ # logs/, metrics/, deploys/ for demo scenarios └── db/migration/ # Flyway schema scripts/ └── trigger-scenarios.sh ```
标签:AIOps, DLL 劫持, Docker Compose, Java 21, LangChain4j, Maven, pgvector, PostgreSQL, PyRIT, Redis, REST API, Runbook, Spring Boot 3.3, SRE, TF-IDF, 余弦相似度, 偏差过滤, 向量检索, 域名枚举, 多智能体系统, 大语言模型, 指标监控, 搜索引擎查询, 故障修复, 故障报告生成, 智能运维, 根因分析, 测试用例, 漏洞验证, 生产事件诊断, 系统架构, 自主事件响应, 自动化运维, 自定义请求头, 请求拦截, 运维预案