bhatasif17/IRCC
GitHub: bhatasif17/IRCC
基于微软智能体框架构建的AI驱动SRE系统,通过多智能体编排自动化完成基础设施事件的诊断、根因分析与修复方案推荐。
Stars: 0 | Forks: 0
# AI 驱动的 SRE 智能体系统
一个基于 **Microsoft Agent Framework** 的生产级多智能体 AI 系统,用于自动化基础设施事件的诊断和修复的 SRE 工作流。
## 🎯 概述
本 MVP 展示了四个专业 AI 智能体的复杂编排,它们协同工作以诊断和解决基础设施事件。每个智能体使用 LLM 指令,在结构化工作流中提供专业化的能力。
```
Alert Triggered
↓
[Monitoring Agent] - Validates incident data, extracts metrics
↓
[Diagnosis Agent] - Analyzes logs/metrics, determines root cause
↓
[Solution Agent] - Recommends fixes with confidence scores
↓
[Execution Agent] - Simulates remediation execution
↓
[Notification Service] - Sends alerts (console/Slack)
```
## 🏗️ 架构
### 技术栈
- **.NET 8** - 具有可空引用类型的现代 C#
- **Microsoft Agent Framework (1.2.0)** - LLM 驱动的智能体编排
- **OpenAI API** - 智能决策制定(推荐使用 gpt-4)
- **ASP.NET Core 8** - 用于触发工作流的 REST API
### 项目结构
```
AI-poweredSRE/
├── Agents/
│ ├── BaseAgent.cs # Base class with common agent logic
│ ├── MonitoringAgent.cs # Step 1: Validate & enrich incidents
│ ├── DiagnosisAgent.cs # Step 2: Determine root causes
│ ├── SolutionAgent.cs # Step 3: Recommend fixes
│ └── ExecutionAgent.cs # Step 4: Simulate execution
├── Workflows/
│ └── SreWorkflow.cs # Agent orchestration (graph-based)
├── Models/
│ ├── Incident.cs # Input model
│ ├── DiagnosisResult.cs # Agent output type
│ ├── SolutionResult.cs # Agent output type
│ ├── WorkflowState.cs # Session state
│ └── SreWorkflowResult.cs # Final result model
├── Services/
│ ├── LlmClientFactory.cs # LLM client initialization
│ └── NotificationService.cs # Console/Slack notifications
├── Controllers/
│ └── IncidentController.cs # REST API endpoint
└── Program.cs # Dependency injection setup
```
## 🤖 智能体系统
### 1. 监控智能体
- **角色**:验证事件数据并提取关键指标
- **输入**:原始事件报告(服务、错误类型、指标)
- **输出**:带有严重性评估的标准化事件
- **提示词**:“You are a Monitoring Agent in an SRE system...”
### 2. 诊断智能体
- **角色**:分析事件数据以确定根本原因
- **输入**:事件 + 监控结果
- **输出**:根本原因、解释、故障组件
- **提示词**:“You are a Diagnosis Agent - a senior SRE engineer...”
### 3. 解决方案智能体
- **角色**:推荐具有置信度的修复措施
- **输入**:诊断结果
- **输出**:修复列表、严重性、置信度分数 (0-1)
- **提示词**:“You are a Solution Agent - an expert SRE...”
### 4. 执行智能体
- **角色**:模拟执行推荐的修复措施(仅限 MVP)
- **输入**:解决方案建议
- **输出**:执行状态和日志
- **提示词**:“You are an Execution Agent - responsible for simulating SRE actions...”
## 🔗 工作流编排
`SreWorkflow` 类实现了基于图的智能体编排:
```
public async Task ExecuteAsync(Incident incident)
{
// Step 1: Monitoring
var monitoringResult = await _monitoringAgent.ProcessIncidentAsync(incident);
// Step 2: Diagnosis (depends on Step 1)
var diagnosisResult = await _diagnosisAgent.DiagnoseAsync(incident, monitoringResult);
// Step 3: Solution (depends on Step 2)
var solutionResult = await _solutionAgent.SolveAsync(diagnosisResult);
// Step 4: Execution (depends on Step 3)
var executionResult = await _executionAgent.ExecuteAsync(solutionResult, incident);
// Aggregate and notify
return AggregateResults(...);
}
```
**主要特性:**
- 带有状态传递的顺序智能体执行
- 智能体之间的强类型路由
- 错误处理和回退机制
- 结构化输出验证
## 📡 API 参考
### 触发事件工作流
```
POST /api/incident
Content-Type: application/json
{
"service": "payment-api",
"error": "timeout",
"metrics": {
"cpu": "85%",
"latency": "2000ms",
"error_rate": "10%"
}
}
```
### 响应
```
{
"incident_id": "550e8400-e29b-41d4-a716-446655440000",
"root_cause": "Service timeout - possible resource contention or external dependency delay",
"explanation": "Analysis shows CPU at 85% with elevated latency...",
"fixes": ["restart_service", "check_external_dependencies", "monitor_cpu"],
"severity": "high",
"confidence": 0.85,
"action_taken": "restart_service, check_external_dependencies, monitor_cpu",
"notification_sent": true,
"processed_at": "2026-04-23T21:15:30Z"
}
```
### 健康检查
```
GET /health
{
"status": "healthy",
"timestamp": "2026-04-23T21:15:30Z"
}
```
## 🚀 快速入门
### 前置条件
- .NET 8 SDK
- OpenAI API 密钥或 Azure OpenAI 配置
### 安装说明
1. **克隆并还原依赖**
cd /Users/asifbhat/Projects/AI-poweredSRE
dotnet restore
2. **配置 LLM 凭证**
更新 `appsettings.json`:
{
"OpenAI": {
"ApiKey": "your-api-key-here",
"Model": "gpt-4-turbo"
}
}
或设置环境变量:
export OPENAI_API_KEY=sk-...
3. **构建项目**
dotnet build
4. **运行应用程序**
dotnet run
API 可访问地址:`https://localhost:5001`
### 测试
1. **使用 VS Code REST Client**(.http 文件)
打开:test.http
在任何事件上点击 "Send Request"
2. **使用 curl**
curl -X POST http://localhost:5019/api/incident \
-H "Content-Type: application/json" \
-d '{
"service": "payment-api",
"error": "timeout",
"metrics": {"cpu": "85%", "latency": "2000ms"}
}'
3. **健康检查**
curl http://localhost:5019/health
## 📊 示例事件类型
系统可处理各种事件场景:
### 场景 1:超时
- **典型诊断**:资源争用,外部依赖延迟
- **典型修复**:restart_service, check_external_dependencies, monitor_cpu
- **严重性**:高
### 场景 2:服务崩溃
- **典型诊断**:内存泄漏,未处理的异常,资源耗尽
- **典型修复**:restart_service, scale_up_memory, analyze_heap_dump
- **严重性**:严重
### 场景 3:高延迟
- **典型诊断**:性能下降,查询效率低下
- **典型修复**:scale_up, optimize_queries, cache_results
- **严重性**:中
### 场景 4:连接错误
- **典型诊断**:网络问题,依赖项不可用
- **典型修复**:check_network, restart_service, verify_connectivity
- **严重性**:高
## 🔒 安全注意事项
- **API 密钥**:切勿提交凭证;请使用环境变量或 Azure Key Vault
- **执行模拟**:当前 MVP 模拟所有操作;生产环境需要审批工作流
- **速率限制**:MVP 中未实现;请在生产环境中添加
- **CORS**:为本地开发配置;请在生产环境中进行限制
## 📈 生产环境增强
生产部署的未来路线图:
1. **真实执行层**
- Azure SDK 集成以进行实际的资源管理
- Kubernetes API 客户端用于集群操作
- 数据库连接用于持久化事件存储
2. **高级编排**
- 基于诊断置信度的条件分支
- 针对独立任务的并行智能体执行
- 事件升级工作流
3. **通知集成**
- Slack webhook 集成
- PagerDuty 事件创建
- 具有丰富格式的电子邮件警报
4. **可观测性**
- Application Insights 集成
- 带有相关 ID 的结构化日志
- 智能体性能指标
5. **状态管理**
- 基于 Redis 的会话存储
- 事件历史持久化
- 用于合规性的审计跟踪
## 🧪 测试
### 单元测试(未来)
- 智能体提示词验证
- JSON 响应解析
- 错误处理
### 集成测试(未来)
- 完整工作流执行
- 模拟 OpenAI 响应
- API 端点验证
### 负载测试(未来)
- 并发事件处理
- 响应时间 SLA
- 资源利用率
## 📝 日志与监控
每个智能体都会记录详细信息:
```
[MonitoringAgent] Processing incident: 550e8400-e29b-41d4-a716-446655440000
[DiagnosisAgent] Root cause: Service timeout - possible resource contention
[SolutionAgent] Recommended severity: high, confidence: 0.85
[ExecutionAgent] Simulating: restart_service, check_external_dependencies
[NotificationService] NOTIFICATION: Alert sent successfully
```
## 📄 许可证
本项目是 AI 驱动的 SRE 计划的一部分。
## 📞 支持
如有问题或疑问:
- 检查日志以获取详细的错误信息
- 在 `SystemPrompt` 常量中查看智能体提示词
- 验证 API 密钥配置
- 首先使用 `/health` 端点进行测试
**使用 Microsoft Agent Framework 构建,实现智能 SRE 自动化**
标签:AIOps, ASP.NET Core 8, GPT-4, IT运维, Microsoft Agent Framework, .NET 8, OpenAI, Petitpotam, PyRIT, REST API, Simulated Remediation, Socks5代理, SRE, 人工智能, 偏差过滤, 内存规避, 告警通知, 命令中心, 基础设施管理, 多智能体系统, 工作流编排, 指标监控, 故障诊断, 根因分析, 模块化设计, 用户模式Hook绕过, 站点可靠性工程, 自动化修复, 自动化攻击, 自动化运维