hariramnagarajan5-stack/AIRP
GitHub: hariramnagarajan5-stack/AIRP
基于 LangGraph 和 Gradio 构建的多 Agent 事件响应平台,通过 RAG、网络搜索和 LLM 三路并行分析事件日志并一键推送修复方案至 Slack 和 JIRA。
Stars: 0 | Forks: 1
## title: Agentic Incident Response Platform
emoji: 🤖
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.44.1
python_version: "3.11"
app_file: app.py
pinned: false
license: mit
# 🤖 Agentic Incident Response Platform
这是一个基于 LangGraph + Gradio 的多 Agent 应用。它使用三种并行的“专家”策略(基于您自身知识库的 RAG、实时网络搜索以及纯 LLM 推理)来分析事件日志,让人工挑选最佳的修复方案,然后将其直接发送到 **Slack** 并在 **JIRA** 中创建工单。
## 工作原理
1. 将事件日志 / JSON / 截图粘贴到 **Analysis** 标签页中。
2. 点击 **Run Analysis** —— 三位专家将独立提出根本原因和修复步骤,并附带置信度分数:
- 📚 **RAG** —— 基于您在 **RAG** 标签页中上传的文档
- 🌐 **Web** —— 基于实时的 Tavily 网络搜索
- 🧠 **LLM** —— 模型自身的知识
3. 选择您最信任的修复方案。
4. 点击 **🚀 Use Selected → Send to Slack & JIRA** —— 这将立即向您的 Slack 频道发布格式化的事件摘要,并在您的 JIRA 项目中创建一个工单。
## 必需配置(Space secrets)
此 Space 需要 API 密钥/token 来与您的 LLM 提供商、Slack 和 JIRA 进行通信。
请在此 Space 的 **Settings → Variables and secrets** 下进行设置(请设置为 *secrets*,而不是公共变量):
| Secret | Required | Notes |
|---|---|---|
| `OPENAI_API_KEY` 或 `ANTHROPIC_API_KEY` 或 `OPENROUTER_API_KEY` | 是(任选其一) | LLM 提供商 |
| `SLACK_BOT_TOKEN` | 用于 Slack 发布 | `xoxb-...`,需要 `chat:write` 权限 |
| `SLACK_CHANNEL` | 可选 | 默认为 `#incidents` |
| `JIRA_SERVER` | 用于 JIRA 工单 | 例如 `https://your-domain.atlassian.net` |
| `JIRA_USERNAME` | 用于 JIRA 工单 | 您的 Atlassian 账户邮箱 |
| `JIRA_API_TOKEN` | 用于 JIRA 工单 | 获取自 id.atlassian.com/manage/api-tokens |
| `JIRA_PROJECT_KEY` | 可选 | 默认为 `OPS` |
| `TAVILY_API_KEY` | 可选 | 启用 Web 搜索专家 |
如果缺少其中任何一项,相应的功能将平滑降级,并在 UI 中显示警告,而不会导致整个应用程序崩溃。
您也可以在运行时直接将密钥粘贴到 **Config** 标签页中,而无需使用 secrets —— 这在快速测试时非常有用。
## 文件
- `app.py` —— 主应用程序(LangGraph pipeline + Gradio UI)
- `requirements.txt` —— Python 依赖项
- `incidents_rag.csv` —— 您可以在 **RAG** 标签页中上传的示例知识库
## 📦 文件已更新
### 1. **app.py**
更新内容:
- `send_slack_message()` - 使用 Slack SDK 发送消息
- `create_jira_ticket()` - 使用 Jira SDK 创建工单
- `finalize()` 函数 - 点击后发送至 Slack 并创建 JIRA
- Config 标签页 - 直接在 UI 中输入凭据
### 2. **requirements.txt**
添加内容:
```
slack-sdk>=3.23.0
jira>=3.13.0
```
### 3. **SLACK_JIRA_SETUP.md**
完整的设置指南,包含:
- 如何创建 Slack bot
- 如何获取 Slack token
- 如何创建 JIRA API token
- 故障排除步骤
## 🚀 快速开始(3 个步骤)
### 步骤 1:安装依赖项
```
pip install -r requirements.txt
```
### 步骤 2:获取凭据
**Slack Bot Token:**
1. 前往 https://api.slack.com/apps
2. 创建新应用
3. 添加权限:`chat:write`, `channels:read`
4. 安装到工作区
5. 复制 Bot Token (xoxb-...)
**JIRA 凭据:**
1. 从您的 JIRA 实例获取服务器 URL
2. 前往 https://id.atlassian.com/manage/api-tokens
3. 创建 API token
4. 记下您的用户名(邮箱)
### 步骤 3:运行应用
**选项 A:环境变量(推荐)**
```
export SLACK_BOT_TOKEN="xoxb-..."
export SLACK_CHANNEL="#incidents"
export JIRA_SERVER="https://your-domain.atlassian.net"
export JIRA_USERNAME="your-email@company.com"
export JIRA_API_TOKEN="your-token"
export JIRA_PROJECT_KEY="OPS"
export OPENAI_API_KEY="sk-..."
python3 app.py
```
**选项 B:通过 Web UI**
```
python3 app.py
# 转到“Config”标签页
# 粘贴所有凭据
```
## 📖 工作原理
### 现在(直接使用 SDK)
```
Click "🚀 Use Selected → Send to Slack & JIRA"
↓
Slack SDK (direct) + Jira SDK (direct)
↓
✅ Instant Slack message
✅ Instant JIRA ticket
✅ Confirmation shown in UI
```
## 🎯 使用工作流
### 1. 粘贴事件日志
```
Go to "Analysis" tab
Paste logs from your logs/JSON/screenshots
```
### 2. 点击 "Run Analysis"
```
App analyzes with 3 experts:
- RAG (knowledge base)
- Web (Tavily search)
- LLM (your LLM model)
Shows confidence scores for each
```
### 3. 人工循环(挑选最佳修复方案)
```
Select the option you trust most
(usually the one with highest confidence)
```
### 4. 点击 "🚀 Use Selected → Send to Slack & JIRA"
```
✅ Slack message appears in #incidents channel
✅ JIRA ticket created in OPS project
✅ Results shown in Final & Status tabs
```
## 🔧 配置
### 在环境变量中
```
# Slack
SLACK_BOT_TOKEN=xoxb-1234567890-...
SLACK_CHANNEL=#incidents
# JIRA
JIRA_SERVER=https://your-domain.atlassian.net
JIRA_USERNAME=your-email@company.com
JIRA_API_TOKEN=your-api-token
JIRA_PROJECT_KEY=OPS
# LLM(选择一个)
OPENAI_API_KEY=sk-...
# 或
ANTHROPIC_API_KEY=sk-ant-...
# 可选
TAVILY_API_KEY=tvly-...
```
### 在 UI 中(Config 标签页)
```
Slack Bot Token: [xoxb-...]
Slack Channel: [#incidents]
JIRA Server: [https://your-domain.atlassian.net]
JIRA Username: [your-email@company.com]
JIRA API Token: [your-token]
JIRA Project Key: [OPS]
LLM Key: [sk-...]
Tavily Key (optional): [tvly-...]
```
## ✅ 发送内容
### Slack 消息(自动格式化)
```
🚨 **P1 Incident** in order-service
*Root Cause:* Database connection pool exhaustion
*First Action:* Identify slow queries using EXPLAIN ANALYZE
*Remediation Steps:*
1. Add indexes on filtered columns
2. Optimize JOIN operations
3. Implement connection timeouts
4. Monitor with APM tools
```
### JIRA 工单(自动创建)
```
Project: OPS
Type: Task
Summary: Connection timed out in order-service
Description: Full remediation cookbook with all steps
Priority: High (auto-mapped from P1/P2/P3/P4)
```
## 🧪 测试
### 测试 Slack 连接
```
python3 << 'EOF'
from slack_sdk import WebClient
token = "xoxb-your-token"
client = WebClient(token=token)
try:
response = client.chat_postMessage(
channel="#test-channel",
text="Test message"
)
print(f"✅ Slack working! Message: {response['ts']}")
except Exception as e:
print(f"❌ Slack error: {e}")
EOF
```
### 测试 JIRA 连接
```
python3 << 'EOF'
from jira import JIRA
try:
jira = JIRA(
server="https://your-domain.atlassian.net",
basic_auth=("your@email.com", "your-token")
)
print(f"✅ JIRA connected! Projects: {jira.projects()}")
except Exception as e:
print(f"❌ JIRA error: {e}")
EOF
```
## 🆘 常见问题与修复
| 问题 | 解决方案 |
|-------|----------|
| "Slack Bot Token not configured" | 设置 `SLACK_BOT_TOKEN` 环境变量或在 Config 标签页中粘贴 |
| "Bot not in channel" | 在 Slack 中邀请 bot 加入 #incidents 频道 |
| "Channel not found" | 检查频道名称(应为 `#incidents`) |
| "JIRA authentication failed" | 验证 JIRA 凭据(服务器、用户名、token) |
| "Project not found" | 使用正确的 JIRA 项目 key |
| 导入错误 | 运行 `pip install -r requirements.txt` |
**查看完整故障排除指南:** 打开 `SLACK_JIRA_SETUP.md`
## 📋 设置清单
- [ ] 已下载最新的 `app.py` 和 `requirements.txt`
- [ ] 已运行 `pip install -r requirements.txt`
- [ ] 已在 api.slack.com/apps 创建 Slack 应用
- [ ] 已添加 bot 权限:`chat:write`, `channels:read`
- [ ] 已将 bot 安装到工作区
- [ ] 已邀请 bot 加入 #incidents 频道
- [ ] 已复制 Slack bot token (xoxb-...)
- [ ] 已在 id.atlassian.com/manage/api-tokens 创建 JIRA API token
- [ ] 已记下 JIRA 服务器 URL、用户名、项目 key
- [ ] 已设置环境变量 或 准备好在 UI 中粘贴
- [ ] 运行 `python3 app.py`
- [ ] 打开 http://localhost:7860
- [ ] 测试:粘贴日志 → 运行分析 → 挑选 → 发送至 Slack 和 JIRA
- [ ] ✅ Slack 频道中出现消息
- [ ] ✅ JIRA 项目中出现工单
## 🎓 架构
```
┌──────────────────────────┐
│ Incident Analysis │
│ RAG | Web | LLM Expert │
└────────────┬─────────────┘
│
↓
User selects remediation
│
↓
┌─────────────────────────────────────┐
│ Click "Use Selected..." │
│ (Send to Slack & JIRA) │
└────┬──────────────────────┬─────────┘
│ │
↓ ↓
Slack SDK Jira SDK
(slack_sdk) (jira package)
│ │
↓ ↓
Slack JIRA
#incidents OPS-123
(Message) (Ticket)
│ │
↓ ↓
✅ Sent ✅ Created
```
## 🚀 立即开始
```
# 1. 安装
pip install -r requirements.txt
# 2. 设置凭据(选项 A)
export SLACK_BOT_TOKEN="xoxb-..."
export JIRA_SERVER="https://..."
export JIRA_USERNAME="you@email.com"
export JIRA_API_TOKEN="..."
export OPENAI_API_KEY="sk-..."
# 3. 运行
python3 app.py
# 4. 打开浏览器
# http://localhost:7860
```
## 📚 文档
- **SLACK_JIRA_SETUP.md** - 详细的设置指南
- **incidents_rag.csv** - 用于 RAG 的 100 个事件/解决方案示例
- **QUICK_START.md** - 5 分钟快速入门
**就是这样!您现在拥有了直接的 Slack 和 JIRA 集成。** 🎉
当您点击 "Use Selected as Final Remediation" 时:
- ✅ Slack 消息已发送至 #incidents
- ✅ JIRA 工单已在您的项目中创建
- ✅ 应用 UI 中会显示状态
不再有 Composio 问题,不再有模拟,只有直接的实时集成!🚀
标签:AI智能体, Gradio, Jira, LangGraph, Petitpotam, RAG, 库, 应急响应, 自动化运维, 逆向工具