MohammadHeydari/Deep-Agent-IT-Incident-Response

GitHub: MohammadHeydari/Deep-Agent-IT-Incident-Response

基于 LangChain Deep Agents 和 FastAPI 构建的自主 IT 事件响应系统,通过多子代理流水线对系统告警进行自动分析并生成可操作的修复步骤。

Stars: 0 | Forks: 0

# Deep Agent IT 事件响应 一个使用 **LangChain Deep Agents** 和 **FastAPI** 构建的自主 IT 事件响应系统。该系统监控真实的系统资源,通过 webhook 发送警报,使用多 subagent pipeline 对其进行分析,并返回可操作的修复步骤——所有这些均无需人工干预。 ## 架构 ``` monitor.py (psutil) reads real system metrics ↓ POST /alert (FastAPI Webhook) ↓ ┌─────────────────────────────┐ │ Deep Agent │ │ │ │ collector → normalize │ │ screener → severity │ │ analyzer → root cause │ │ fixer → remediation │ └─────────────────────────────┘ ↓ JSON Response + Console Output ``` ### 子代理 | Subagent | 职责 | |----------|---------------| | **Collector** | 解析并标准化原始警报 | | **Screener** | 分配严重性级别 (LOW/MEDIUM/HIGH/CRITICAL) 和紧急程度 | | **Analyzer** | 识别根本原因 (仅限 HIGH/CRITICAL) | | **Fixer** | 生成逐步修复操作或进行上报 | ## 项目结构 ``` deep-agent-it-incident-response/ ├── .env # API keys (not committed) ├── .gitignore ├── requirements.txt ├── llm.py # LLM client setup ├── tools.py # LangChain tools ├── subagents.py # Subagent definitions ├── main.py # Deep agent orchestrator ├── webhook.py # FastAPI webhook server └── monitor.py # Real-time system monitor (psutil) ``` ## 设置 ### 1. 克隆仓库 ``` git clone https://github.com/mohammadheydari/deep-agent-it-incident-response.git cd deep-agent-it-incident-response ``` ### 2. 创建虚拟环境 ``` python -m venv venv # Windows .\venv\Scripts\Activate.ps1 # macOS/Linux source venv/bin/activate ``` ### 3. 安装依赖 ``` pip install -r requirements.txt ``` ### 4. 配置环境变量 在根目录下创建一个 `.env` 文件: ``` AVVALAI_API_KEY=your-api-key AVVALAI_BASE_URL=https://api.avalai.ir/v1 AVVALAI_MODEL=gpt-4o-mini ``` ## 用法 ### 步骤 1 — 启动 webhook 服务器 ``` uvicorn webhook:server --reload --port 8000 ``` ### 步骤 2 — 启动系统监控 打开第二个终端并运行: ``` python monitor.py ``` 监控器将每 10 秒读取一次您机器上的真实指标,并在超过阈值时自动向 webhook 发送警报。 ### 默认阈值 ``` THRESHOLDS = { "cpu": 90, # CPU usage % "ram": 85, # RAM usage % "disk": 95, # Disk usage % "gpu": 90, # GPU usage % } ``` ### 输出示例 ``` Monitoring started. Checking every 10s... Thresholds: CPU>90% | RAM>85% | Disk>95% [ALERT] Disk usage at 96.5% on MyPC at 07:48 UTC. Free: 11.5GB of 328.3GB. [AGENT] To address the high disk usage on C:\, follow these remediation steps: 1. Run Disk Cleanup... 2. Identify large files... ``` ## 手动测试 在不运行监控器的情况下发送测试警报: **PowerShell:** ``` Invoke-RestMethod -Uri "http://localhost:8000/alert" ` -Method POST ` -ContentType "application/json" ` -Body '{"alert": "CPU spike to 100% on prod-db-01 at 14:32 UTC. 500 errors on API gateway."}' ``` **curl:** ``` curl -X POST http://localhost:8000/alert \ -H "Content-Type: application/json" \ -d '{"alert": "CPU spike to 100% on prod-db-01 at 14:32 UTC."}' ``` ### 健康检查 ``` curl http://localhost:8000/health ``` ## 连接外部监控工具 您也可以通过将外部工具(如 Datadog 或 Zabbix)的 webhook 指向 `/alert` 来进行连接: ``` URL: http://your-server:8000/alert Method: POST Payload: {"alert": "$EVENT_TITLE - $EVENT_MSG"} ``` ## 依赖要求 ``` langchain langgraph deepagents langchain-openai fastapi uvicorn python-dotenv psutil requests gputil ``` ## 工作原理 本项目实现了 LangChain 的 **Deep Agent** 模式: - **Orchestrator** 保持简洁,并将任务委托给各个 subagent - 每个 **subagent** 在其自身独立的、短生命周期的循环中运行 - **harness** 自动管理上下文窗口限制 - agent 根据警报的严重性在运行时决定工作流 - `monitor.py` 使用 `psutil` 读取**真实的系统指标**——无需外部监控工具
标签:AV绕过, DLL 劫持, FastAPI, IT运维, LangChain, Python, Socks5代理, 大语言模型, 无后门, 自动化响应, 轻量级, 逆向工具