costaadiego1989/nexus-aiops-platform

GitHub: costaadiego1989/nexus-aiops-platform

Nexus 是一个基于 LangGraph 的分层多 Agent 智能运维平台,用于在基础设施告警触发后自主完成事件分级、并行调查、根因定位和修复建议。

Stars: 0 | Forks: 0

# 🎯 Nexus AI-Ops 平台 [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue?logo=typescript)](https://www.typescriptlang.org/) [![LangGraph](https://img.shields.io/badge/LangGraph-Agent_Framework-orange)](https://langchain-ai.github.io/langgraphjs/) [![Express](https://img.shields.io/badge/Express-API-green?logo=express)](https://expressjs.com/) [![SSE](https://img.shields.io/badge/SSE-Real--time_Streaming-purple)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) ## 🧠 什么是 Nexus? Nexus 是一个 AI 驱动的故障响应平台,它模仿了精英 SRE 团队的运作方式——但是是自主的。当接收到基础设施告警时,**Commander agent** 会进行分类,委派给**专家 agent**,并将调查结果综合成可执行的解决方案——所有这一切都在 60 秒内完成。 **这不是一个 ChatGPT 包装器。** 它是一个生产级的多 agent 系统,具有: - 分层编排(Commander → 专家) - 结合特定领域工具的并行调查 - 具有实时流式传输的事件驱动架构 - Guardrails、审计日志和 PII 过滤 - 自动生成的复盘报告 ## 🏗️ 架构 ``` 🚨 Infrastructure Alert │ ▼ ┌─────────────────────────────┐ │ COMMANDER AGENT │ │ • Classifies severity │ │ • Selects investigators │ │ • Synthesizes root cause │ └──────┬──────────┬───────┬───┘ │ │ │ ▼ ▼ ▼ ┌──────────┐ ┌────────┐ ┌──────────┐ │ INFRA │ │ APP │ │ SECURITY │ │Specialist│ │Special.│ │Specialist│ │ │ │ │ │ │ │•Prometheus│ │• Logs │ │• Access │ │• K8s pods │ │• Traces│ │• CVEs │ │• Resources│ │• Deploy│ │• Anomaly │ └──────────┘ └────────┘ └──────────┘ │ │ │ ▼ ▼ ▼ ┌─────────────────────────────┐ │ SYNTHESIS + RESOLVE │ │ • Root cause identified │ │ • Remediation proposed │ │ • Post-mortem generated │ └─────────────────────────────┘ │ ▼ 📊 Real-time Dashboard (SSE) ``` ## ⚡ 实时演示 ![展示 agent 实时调查的仪表板](https://img.shields.io/badge/Status-Working_Demo-brightgreen) ``` [Pipeline] Incidente iniciado. Triage em andamento... [Commander] Severidade: P2 | Domínios: infra, app [Infra Specialist] Investigando... (8 tools, 20s) [App Specialist] Investigando... (7 tools, 31s) [Commander] Causa raiz: Deploy v2.4.1 introduziu memory leak no endpoint POST /api/reports/export → OOMKilled [Commander] Ação: Rollback imediato para v2.4.0 ✅ Resolvido em 56s ``` ## 🛠️ 技术栈 | 层级 | 技术 | 原因 | |-------|-----------|-----| | **语言** | TypeScript | 完全的类型安全,Zod 运行时验证 | | **Agent 框架** | LangGraph | 使用 `createReactAgent` 的生产级 ReAct 循环 | | **LLM** | LangChain + OpenRouter | 多模型网关,与提供商无关 | | **API** | Express | REST 端点 + SSE 流式传输 | | **流式传输** | Server-Sent Events | 无需 WebSocket 复杂性的实时仪表板 | | **验证** | Zod | 工具参数 schema,结构化输出 | | **Guardrails** | 自定义 | 允许列表,PII 过滤,迭代上限,审计 | ## 🚀 快速开始 ``` git clone https://github.com/costaadiego1989/nexus-aiops-platform.git cd nexus-aiops-platform npm install # 配置您的 LLM API key cp .env.example .env # 编辑 .env → 添加您的 OpenRouter key (https://openrouter.ai/keys) # 启动平台 npm run dev # 打开 dashboard # → http://localhost:3002 ``` ### 通过 CLI 进行测试 ``` # 触发调查 curl -X POST http://localhost:3002/incidents \ -H 'Content-Type: application/json' \ -d '{"alert": "API api-server: latency p99 8s, error rate 15%, pods CrashLoopBackOff OOMKilled. Last deploy: v2.4.1 2h ago."}' # 实时流式传输 events curl http://localhost:3002/incidents//stream # 获取最终报告 curl http://localhost:3002/incidents/ ``` ## 📁 项目结构 ``` src/ ├── config.ts # Environment configuration ├── llm-client.ts # LangChain ChatOpenAI (OpenRouter) ├── types.ts # Shared interfaces & type definitions ├── index.ts # Express server entry point │ ├── tools/ # Domain-specific investigation tools │ ├── prometheus.ts # Metrics: CPU, memory, error rates, restarts │ ├── logs.ts # Application logs + distributed traces (Jaeger) │ ├── kubernetes.ts # Pod status, kubectl describe, events │ ├── security.ts # Access patterns, CVE scanning, anomaly detection │ └── index.ts # Tool grouping per specialist │ ├── agents/ # AI agents with autonomous decision-making │ ├── base-agent.ts # Generic ReAct loop (LangGraph createReactAgent) │ ├── commander.ts # Incident Commander: triage + synthesis │ ├── infra-specialist.ts # Infrastructure investigation │ ├── app-specialist.ts # Application debugging │ └── security-specialist.ts # Security assessment │ ├── orchestrator/ # Multi-agent coordination │ ├── pipeline.ts # Event-driven hierarchical orchestration │ └── guardrails.ts # Safety: allowlist, PII filter, audit, limits │ ├── postmortem/ # Automated report generation │ └── generator.ts # LLM-powered post-mortem writer │ └── routes/ # HTTP API layer ├── health.ts # GET /health ├── incidents.ts # POST + GET /incidents └── stream.ts # SSE real-time event streaming public/ └── index.html # Live dashboard (EventSource + dark UI) ``` ## 🧩 设计模式 | 模式 | 位置 | 功能描述 | |---------|-------|-------------| | **ReAct 循环** | `base-agent.ts` | 思考 → 行动 → 观察 → 重复直到解决 | | **分层编排** | `pipeline.ts` | Commander 负责委派、收集、综合 | | **Fan-out / Fan-in** | `pipeline.ts` | 专家并行运行(`Promise.all`) | | **事件驱动** | `pipeline.ts` | 发出事件 → 监听器响应(SSE,审计) | | **Guardrails** | `guardrails.ts` | 工具允许列表,namespace 保护,PII 脱敏 | | **结构化输出** | `commander.ts` | 用于分类和综合的 JSON schema | | **关注点分离** | 架构 | 工具 / Agent / 编排器 / 路由 | | **单例** | `pipeline.ts` | 单一 pipeline 实例,共享状态 | ## 🔒 Guardrails 与安全 - **工具允许列表** — 只能调用已批准的工具 - **Namespace 保护** — 关键 namespace(kube-system,monitoring)被阻止 - **迭代限制** — Agent 不能无限循环(每个专家最多 5 次) - **PII 过滤** — 电子邮件、CPF、信用卡在输出中被脱敏 - **审计日志** — 每个 agent 的操作都带有时间戳记录 - **审批关卡** — 破坏性操作需要人工批准(可扩展) ## 📊 API 参考 | 方法 | 端点 | 描述 | 响应 | |--------|----------|-------------|----------| | `POST` | `/incidents` | 启动新调查 | `{incidentId, stream}` | | `GET` | `/incidents` | 列出所有事件 | `IncidentState[]` | | `GET` | `/incidents/:id` | 完整的故障详情 | `IncidentState` | | `GET` | `/incidents/:id/stream` | SSE 事件流 | 逐事件更新 | | `GET` | `/health` | 服务健康检查 | `{status, uptime}` | ## 🎓 背景 作为[应用 AI 工程](https://github.com/unipds-engenharia-de-ia-aplicada)研究生课程的毕业项目而开发——整合了全部 6 个模块的概念: - **模块 02**:LLM API 集成、流式传输、函数调用 - **模块 03**:Model Context Protocol (MCP)、工具定义 - **模块 04**:ReAct agent、多 agent 系统、LangGraph 编排 - **模块 06**:AI-Ops、guardrails、治理、故障响应 从 Python/CrewAI 参考架构改编为使用 LangGraph 的完全 TypeScript 实现。 ## 📝 许可证 MIT
标签:AI-Ops, LangGraph, SRE, TypeScript, 偏差过滤, 多智能体, 子域名突变, 安全插件, 自动化响应, 自动化攻击, 自定义请求头