GOURABSARKAR/incident-response-agent

GitHub: GOURABSARKAR/incident-response-agent

这是一个基于 LangChain DeepAgents 构建的 AI 事件响应助手,旨在帮助值班工程师在 90 秒内通过日志分析生产故障并生成可执行的简报。

Stars: 0 | Forks: 0

# 事件响应 Agent 一个基于 LangChain 的 `deepagents` 库构建的 AI 驱动事件响应助手。帮助值班工程师诊断生产问题,并在 90 秒内生成可执行的事件简报。 ## 🎯 使用场景 **故事背景:** 一名开发者推送了一次错误的部署。API 错误率飙升。值班工程师收到警报。他们将日志和警报粘贴到 Agent 中 → 在 90 秒内获得诊断结果和 Slack 帖子。 ## 🏗️ 项目结构 ``` incident-response-agent/ ├── agent.py # Main entry point ├── requirements.txt # Python dependencies ├── .env.example # Environment configuration template ├── workspace/ # Agent's read/write workspace (auto-created) └── skills/ ├── log-parser/ # Skill 1: Diagnose issues from logs │ ├── SKILL.md # Skill instructions │ └── references/ │ └── common-errors.md # Error patterns lookup table └── incident-brief-summarizer/ # Skill 2: Generate incident briefs ├── SKILL.md # Skill instructions └── references/ ├── slack-post.md # Slack post template + examples └── checklist.md # Action checklist template + examples ``` ## 🚀 工作原理 ### 技能概览 | 技能 | 触发条件 | 功能说明 | |-------|---------|--------------| | **log-parser** | "something broke", "we have an incident", "here are the logs" | 读取错误日志,识别问题,检查部署历史,输出诊断结果 | | **incident-brief-summarizer** | "write the Slack post", "I need an incident update" | 接收诊断结果并生成可直接复制粘贴的 Slack 帖子 + 行动清单 | ### 工作流程 1. **工程师粘贴日志** → Agent 触发 `log-parser` 技能 2. **log-parser 分析** → 发现错误,检查部署时间,评估置信度 3. **输出诊断** → 故障内容、发生时间、可能原因、前 3 项行动 4. **Agent 触发** → `incident-brief-summarizer` 技能 5. **生成简报** → Slack 帖子(供团队使用)+ 行动清单(供工程师使用) 6. **工程师复制** → 粘贴到 Slack,遵循清单,解决事件 ### 渐进式披露 Agent 使用 **渐进式披露** 以提高效率: 1. 启动时 → 仅读取每个 SKILL.md 的 frontmatter `description` 2. 当用户提示匹配某个技能时 → 读取完整的 SKILL.md 3. 遵循指令(其中引用了参考资料和查找表) ## 📦 安装与运行 ### 1. 安装依赖 ``` pip install -r requirements.txt ``` ### 2. 配置环境变量 ``` # 复制示例环境文件 cp .env.example .env # 编辑 .env 并添加您的 API keys 和 configuration # 必填:ANTHROPIC_API_KEY 或 WATSON_API_KEY(取决于 MODEL_PROVIDER) # 可选:MCP_SERVER_URL 用于 MCP server integration ``` ### 3. 运行 Agent ``` python agent.py ``` ## ⚙️ 配置 Agent 支持两种模型提供商和可选的 MCP 服务器集成: ### 模型提供商 **选项 1:Anthropic Claude(默认)** ``` MODEL_PROVIDER=anthropic ANTHROPIC_API_KEY=your-anthropic-api-key ANTHROPIC_MODEL=anthropic:claude-haiku-4-5-20251001 ``` **选项 2:IBM WatsonX** ``` MODEL_PROVIDER=watsonx WATSON_API_KEY=your-watson-api-key WATSON_ML_URL=https://us-south.ml.cloud.ibm.com WATSON_PROJECT_ID=your-project-id WATSON_MODEL_ID=meta-llama/llama-3-3-70b-instruct ``` ### MCP 服务器集成(可选) 要启用 MCP(Model Context Protocol)工具以获得额外的调试功能: ``` MCP_SERVER_NAME=debug-assistant-mcp MCP_SERVER_URL=https://your-mcp-server.example.com/mcp MCP_SERVER_TRANSPORT=streamable-http ``` 将 `MCP_SERVER_URL` 留空以禁用 MCP 工具。您可以集成任何兼容 MCP 的服务器以扩展功能,例如创建工单、日志分析或其他调试工具。 查看 [`.env.example`](.env.example) 了解所有可用的配置选项。 ## 📝 使用示例 ### 场景:支付服务错误 **输入:** ``` We have an incident! Here are the logs: [2024-01-15 03:04:12] ERROR payment-service: NullPointerException at DiscountCalculator.java:47 [2024-01-15 03:04:13] ERROR payment-service: Failed to process checkout request [2024-01-15 03:04:14] ERROR payment-service: NullPointerException at DiscountCalculator.java:47 Deploy history: [2024-01-15 03:01:00] payment-service v2.5.0 deployed ``` **输出:** ``` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 📢 SLACK POST (copy → #incidents) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 🔴 Payment service is returning 500 errors — checkouts are failing **Started:** 2024-01-15 03:04 UTC **Impact:** ~30% of checkout requests failing (est. 200 users affected) **Status:** Identified — rolling back deploy **What we know:** - First error at 03:04, 3 minutes after payment-service deploy - NullPointerException in new discount calculation code - Error rate: 30% of requests (intermittent, not all users) **Next steps:** - Rolling back payment-service to v2.4.1 (ETA: 5 min) - Monitoring error rate after rollback **Owned by:** [your-name] **Next update:** 03:20 UTC (15 min) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ✅ ACTION CHECKLIST ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ## 立即操作 - [ ] Rollback payment-service to v2.4.1 Why: Error started 3 min after deploy, high confidence it's the cause - [ ] Monitor error rate for 5 minutes after rollback Why: Confirm rollback fixed the issue before closing incident - [ ] Check if any payments are stuck in "pending" state Why: Failed requests may have left incomplete transactions ## 如果这不起作用 - [ ] Check database connection pool status Why: 500 errors can also be caused by exhausted DB connections - [ ] Page payment-service owner (@jane-doe) Why: If rollback didn't help, need domain expert to investigate ## 解决后 - [ ] Post update to Slack in 15 minutes - [ ] Open a post-mortem ticket once resolved ``` ## 🛠️ 技能详解 ### log-parser 技能 **目的:** 根据错误日志诊断生产问题 **流程:** 1. **查找错误** → 扫描 ERROR、FATAL、Exception、5xx 状态码 2. **检查部署** → 将错误时间戳与部署历史关联 3. **输出诊断** → 包含置信度的结构化格式 **参考资料:** - [`common-errors.md`](skills/log-parser/references/common-errors.md) - HTTP 错误、运行时错误和部署模式的查找表 ### incident-brief-summarizer 技能 **目的:** 生成可直接复制粘贴的事件沟通内容 **流程:** 1. **读取诊断** → 从 log-parser 输出中提取关键事实 2. **撰写 Slack 帖子** → 使用模板创建团队更新 3. **撰写清单** → 生成优先级行动项 4. **输出两者** → 清晰分离,立即可用 **参考资料:** - [`slack-post.md`](skills/incident-brief-summarizer/references/slack-post.md) - 带有严重性表情符号的 Slack 帖子格式 - [`checklist.md`](skills/incident-brief-summarizer/references/checklist.md) - 常见场景的行动清单模式 ## 🎯 设计原则 1. **速度** → 从日志到行动计划仅需 90 秒 2. **清晰** → 使用通俗易懂的英语,无行话,语气冷静 3. **可执行** → 每个输出均可直接复制粘贴 4. **诚实** → 明确的置信度(高/中/低) 5. **实用**** → 专为凌晨 3 点的事件设计 ## 🔧 自定义 ### 添加新的错误模式 编辑 [`skills/log-parser/references/common-errors.md`](skills/log-parser/references/common-errors.md) 以添加: - 新的 HTTP 错误代码 - 应用程序特定错误 - 自定义部署模式 ### 修改参考资料 编辑 [`skills/incident-brief-summarizer/references/`](skills/incident-brief-summarizer/references/) 中的参考资料: - 调整 Slack 帖子格式以适应团队风格 - 添加公司特定的清单项 - 自定义严重性级别 ### 添加新技能 在 `skills/` 中创建一个包含 `SKILL.md` 文件的新文件夹: ``` --- name: my-skill description: When to use this skill (triggers) --- # my-skill ## 说明 Step-by-step instructions the agent follows ``` ## 📚 其他资源 - [LangChain DeepAgents 文档](https://python.langchain.com/docs/deepagents) - [MCP 协议规范](https://modelcontextprotocol.io/) - [Anthropic Claude API](https://docs.anthropic.com/) - [IBM WatsonX 文档](https://www.ibm.com/docs/en/watsonx-as-a-service) ## 📄 许可证 [在此处添加您的许可证] ## 🆘 支持 如有问题或疑问: - 查看 [common-errors.md](skills/log-parser/references/common-errors.md) 参考资料 - 查看 [references](skills/incident-brief-summarizer/references/) 以获取示例 - 在仓库中提交 issue **用 ❤️ 为全球的值班工程师打造**
标签:Agent开发, AI助手, BurpSuite集成, DeepAgents, DLL 劫持, LangChain, Python, Slack集成, 人工智能, 代码库, 大语言模型, 开箱即用, 故障诊断, 无后门, 智能运维, 生产环境, 用户模式Hook绕过, 监控告警, 网络调试, 自动化, 轻量级, 运维, 逆向工具