1816x/Self-Healing-Agent

GitHub: 1816x/Self-Healing-Agent

一个端到端可复现的 AI 自愈事件响应演示系统,监控应用日志与指标、诊断故障根因并自动开启修复 PR。

Stars: 0 | Forks: 0

# 自愈事件 Agent 这是一个事件响应 Agent,它会监控演示应用的日志和指标,检测故障,通过为 Claude 提供真实的工具(读取日志、查询指标、`git blame`、读取源码)来诊断根本原因,以 diff 的形式提出具体的修复方案,并开启一个包含代码更改及其背后逻辑的 Pull Request。仪表盘会展示每个事件在流水线中的流转状态:检测到 (detected) → 诊断中 (diagnosing) → 已诊断 (diagnosed) → 已提供修复方案 (fix proposed) → 已开启 PR (PR opened)。 这种应用场景是真实且活跃的 —— [HolmesGPT](https://github.com/robusta-dev/holmesgpt) (CNCF Sandbox, SRE agent) 和 [automatron](https://github.com/creasty/automatron) 已经将相同的理念商业化。本仓库是一个范围明确、从零开始的版本:没有使用任何 Agent 框架,每一层都清晰明确且端到端可解释。 ## 重要提示:这些 bug 是故意的 演示应用的故障是**作为真实、刻意的 commit 注入的**(`scripts/inject_bug.sh`,在阶段 1 中引入)—— 并非意外。这正是让整个闭环可复现的原因:任何人只要克隆了这个仓库,就能每次都触发相同的事件,观察相同的检测过程,并看到相同的 Agent 诊断结果。请查看 `PLAN.md` 中的 bug 目录。 ## 架构 ``` demo-app (Python/FastAPI, bugs injected as real commits) │ structured JSON logs + /metrics (Prometheus format) ▼ monitor (Go daemon) │ tails logs, scrapes metrics, sliding-window detectors, │ debounce/dedup → writes incident to SQLite ▼ agent (Python + Claude function calling) │ tools: read_logs · get_metrics · git_log/git_blame · │ read_source · propose_fix(diff) │ validates diff (applies + tests pass) → opens PR via GitHub API ▼ dashboard (Next.js) reads SQLite → incident timeline, tool-call trace, diff view ``` 一个 SQLite 文件 (`incidents.db`) 就是这三层之间的契约 —— 不需要消息中间件,也不需要额外维护任何服务。 ## 仓库结构 | 路径 | 说明 | |------|------| | `demo-app/` | 带有结构化日志和 `/metrics` endpoint 的 Python/FastAPI 服务 | | `monitor/` | Go daemon:日志/指标检测器,事件写入器 | | `agent/` | Python:Claude 工具调用循环,diff 验证,PR 开启器 | | `dashboard/` | Next.js 事件仪表盘 | | `scripts/` | `inject_bug.sh`, `run_demo.sh` | | `docs/` | `design-decisions.md`,架构说明 | | `PLAN.md` | 本项目遵循的完整阶段规划图 | ## 状态 阶段 0-2 已完成 —— 演示应用、监控 daemon 以及所有三个检测器(错误率、p95 延迟、内存增长)已经能够针对真实注入的 bug 进行端到端运作。接下来是阶段 3(Claude 诊断 Agent)。请查看 `PLAN.md` 了解阶段规划,以及 `docs/design-decisions.md` 了解该架构如此设计的缘由。 ## 快速开始 ``` scripts/run_demo.sh # terminal 1: demo app + monitor + steady load scripts/inject_bug.sh b1 # terminal 2: pick one — b1, b2, or b3 ``` 几秒钟内,相应的检测器就会触发,一个事件就会记录到 `incidents.db` 中: | Bug | 回退表现 | 检测器 | |-----|-----------|----------| | `b1` | `/checkout` 每次请求都出现 500 错误 | `error_rate` (基于日志) | | `b2` | `/products` 变慢 (模拟 N+1 问题) | `latency_p95` (基于指标) | | `b3` | 内存缓存无限增长 | `memory_growth` (基于指标) | ``` sqlite3 incidents.db 'SELECT id, kind, status, occurrences, evidence FROM incidents;' ``` 在尝试另一个注入之前撤销当前注入:`git reset --hard HEAD~1`(注入的 commit 仅限本地 —— `inject_bug.sh` 绝不会将其 push)。
标签:AIOps, AV绕过, EVTX分析, FastAPI, 日志审计, 根因分析, 自动化运维, 自定义请求头, 自愈系统, 逆向工具