feat: 实现智能Agent系统,集成大模型和智能决策
- 创建IntelligentAgent核心,支持预警处理和知识库置信度处理 - 集成LLM客户端,支持OpenAI、Anthropic和本地LLM - 实现ActionExecutor动作执行器,支持多种动作类型 - 优化TSPAgentAssistant,集成大模型和智能决策能力 - 添加预警自动处理措施,包括重启服务、检查状态、通知等 - 实现知识库置信度处理,自动增强低置信度知识条目 - 支持动作执行历史记录和统计 - 提供LLM使用统计和监控功能
This commit is contained in:
@@ -3109,3 +3109,439 @@ WHERE knowledge_entries.is_active = true AND knowledge_entries.is_verified = tru
|
|||||||
2025-09-10 23:09:00,448 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:09:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
2025-09-10 23:09:00,448 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:09:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
2025-09-10 23:09:00,700 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:09:00] "GET /api/health HTTP/1.1" 200 -
|
2025-09-10 23:09:00,700 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:09:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
2025-09-10 23:09:00,781 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:09:00] "GET /api/health HTTP/1.1" 200 -
|
2025-09-10 23:09:00,781 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:09:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:10:00,136 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:10:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:10:00,138 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:10:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:10:00,171 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:10:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:10:00,418 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:10:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:10:00,427 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:10:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:10:00,468 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:10:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:10:00,794 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:10:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:11:00,124 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:11:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:11:00,157 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:11:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:11:00,416 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:11:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:11:00,421 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:11:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:11:00,432 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:11:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:11:00,688 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:11:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:11:00,767 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:11:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:12:00,137 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:12:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:12:00,154 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:12:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:12:00,189 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:12:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:12:00,413 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:12:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:12:00,423 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:12:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:12:00,465 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:12:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:12:00,779 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:12:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:00,119 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:00,160 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:00,431 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:00,451 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:00,452 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:00,688 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:00,788 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:32,703 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:32] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:37,091 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:37] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:42,093 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:42] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:47,095 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:47] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:52,093 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:52] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:13:57,088 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:13:57] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:00,102 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:00,105 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:00,391 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:00,401 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:00,428 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:00,746 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:02,084 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:02] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:07,085 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:07] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:12,089 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:12] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:17,094 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:17] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:22,105 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:22] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:27,094 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:27] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:14:32,096 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:14:32] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:49,165 - __main__ - INFO - 正在启动TSP智能助手综合管理平台...
|
||||||
|
2025-09-10 23:15:51,033 - src.core.database - INFO - 数据库初始化成功
|
||||||
|
2025-09-10 23:15:52,585 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:15:52,596 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:15:52,598 - src.main - INFO - TSP助手初始化完成
|
||||||
|
2025-09-10 23:15:52,612 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:15:52,627 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:15:52,631 - src.main - INFO - TSP助手初始化完成
|
||||||
|
2025-09-10 23:15:52,631 - src.agent.tool_manager - INFO - 注册工具: search_knowledge
|
||||||
|
2025-09-10 23:15:52,631 - src.agent.tool_manager - INFO - 注册工具: create_work_order
|
||||||
|
2025-09-10 23:15:52,632 - src.agent.tool_manager - INFO - 注册工具: update_work_order
|
||||||
|
2025-09-10 23:15:52,632 - src.agent.tool_manager - INFO - 注册工具: generate_response
|
||||||
|
2025-09-10 23:15:52,632 - src.agent.tool_manager - INFO - 注册工具: analyze_data
|
||||||
|
2025-09-10 23:15:52,632 - src.agent.tool_manager - INFO - 注册工具: send_notification
|
||||||
|
2025-09-10 23:15:52,632 - src.agent.tool_manager - INFO - 注册工具: schedule_task
|
||||||
|
2025-09-10 23:15:52,633 - src.agent.tool_manager - INFO - 注册工具: web_search
|
||||||
|
2025-09-10 23:15:52,633 - src.agent.tool_manager - INFO - 注册工具: file_operation
|
||||||
|
2025-09-10 23:15:52,633 - src.agent.tool_manager - INFO - 注册工具: database_query
|
||||||
|
2025-09-10 23:15:52,634 - src.agent.tool_manager - INFO - 已注册 10 个默认工具
|
||||||
|
2025-09-10 23:15:52,634 - src.agent.agent_core - INFO - Agent核心初始化完成
|
||||||
|
2025-09-10 23:15:52,634 - src.agent_assistant - INFO - TSP Agent助手初始化完成
|
||||||
|
2025-09-10 23:15:52,648 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:15:52,740 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||||
|
* Running on all addresses (0.0.0.0)
|
||||||
|
* Running on http://127.0.0.1:5000
|
||||||
|
* Running on http://192.168.26.238:5000
|
||||||
|
2025-09-10 23:15:52,740 - werkzeug - INFO - [33mPress CTRL+C to quit[0m
|
||||||
|
2025-09-10 23:15:52,763 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:15:52,765 - src.web.websocket_server - INFO - 启动WebSocket服务器: ws://localhost:8765
|
||||||
|
2025-09-10 23:15:52,768 - websockets.server - INFO - server listening on 127.0.0.1:8765
|
||||||
|
2025-09-10 23:15:52,768 - websockets.server - INFO - server listening on [::1]:8765
|
||||||
|
2025-09-10 23:15:54,110 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:54] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:54,122 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:54] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:54,123 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:54] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:54,361 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:54] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:54,639 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:54] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:54,650 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:54] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:55,030 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:55] "GET /alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:55,332 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:55] "[36mGET /static/css/style.css HTTP/1.1[0m" 304 -
|
||||||
|
2025-09-10 23:15:55,379 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:55] "[36mGET /static/js/app.js HTTP/1.1[0m" 304 -
|
||||||
|
2025-09-10 23:15:55,703 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:55] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:55,706 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:55] "GET /api/rules HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:55,713 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:55] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:55,731 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:55] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:57,901 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:57] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:15:59,057 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:15:59] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:00,103 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:00,104 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:00,145 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:00,843 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:00] "GET / HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:00,894 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:00] "GET /static/js/dashboard.js HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:01,099 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:01] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:01,398 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:01] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:02,439 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:02] "GET /api/chat/sessions HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:02,440 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:02] "GET /api/workorders HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:02,445 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:02] "GET /api/system/info HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:02,468 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:02] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:02,491 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:02] "GET /api/knowledge/stats HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:02,501 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:02] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:02,750 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:02] "GET /api/workorders HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:04,785 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:04] "GET /api/analytics HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:05,043 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:05] "GET /api/analytics?timeRange=30&dimension=workorders HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:06,099 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:06] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:06,414 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:06] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:06,433 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:06] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:07,457 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:07] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:10,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:10] "GET / HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:10,402 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:10] "[36mGET /static/js/dashboard.js HTTP/1.1[0m" 304 -
|
||||||
|
2025-09-10 23:16:10,735 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:10] "GET /api/workorders HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:10,736 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:10] "GET /api/chat/sessions HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:10,743 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:10] "GET /api/system/info HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:10,752 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:10] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:10,760 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:10] "GET /api/knowledge/stats HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:10,774 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:10] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:11,047 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:11] "GET /api/analytics HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:11,363 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:11] "GET /api/analytics?timeRange=30&dimension=workorders HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:11,433 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:11] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:11,435 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:11] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:15,435 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:15] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:16,405 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:16] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:16,434 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:16] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:16,435 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:16] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:21,103 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:21] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:21,424 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:21] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:21,424 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:21] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:26,396 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:26] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:26,415 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:26] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:26,417 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:26] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:26,665 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:26] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:31,079 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:31] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:31,429 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:31] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:31,430 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:31] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:36,114 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:36] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:36,408 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:36] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:36,422 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:36] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:36,444 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:36] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:41,418 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:41] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:41,420 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:41] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:41,673 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:41] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:46,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:46] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:46,392 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:46] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:46,413 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:46] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:46,439 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:46] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:51,422 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:51] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:51,431 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:51] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:51,671 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:51] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:56,103 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:56] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:56,399 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:56] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:56,419 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:56] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:16:56,449 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:16:56] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:17:00,113 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:17:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:17:00,139 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:17:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:17:00,444 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:17:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:17:01,100 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:17:01] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:17:06,519 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:17:06] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:17:11,092 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:17:11] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:17:16,413 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:17:16] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:18:00,133 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:18:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:18:00,157 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:18:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:18:00,205 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:18:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:18:00,436 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:18:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:18:00,477 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:18:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:18:00,491 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:18:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:18:00,821 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:18:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:00,139 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:00,178 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:00,431 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:00,432 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:00,441 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:00,708 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:00,756 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:39,697 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:39] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:40,789 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:40] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:46,105 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:46] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:51,423 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:51] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:52,745 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:52] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:56,109 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:56] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:19:57,090 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:19:57] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:00,112 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:00,419 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:00,479 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:00,500 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:00,694 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:01,099 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:01] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:02,097 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:02] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:06,416 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:06] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:07,093 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:07] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:11,083 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:11] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:12,088 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:12] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:16,414 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:16] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:17,104 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:17] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:22,750 - __main__ - INFO - 正在启动TSP智能助手综合管理平台...
|
||||||
|
2025-09-10 23:20:24,447 - src.core.database - INFO - 数据库初始化成功
|
||||||
|
2025-09-10 23:20:25,501 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:20:25,511 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:20:25,513 - src.main - INFO - TSP助手初始化完成
|
||||||
|
2025-09-10 23:20:25,526 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:20:25,540 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:20:25,542 - src.main - INFO - TSP助手初始化完成
|
||||||
|
2025-09-10 23:20:25,542 - src.agent.tool_manager - INFO - 注册工具: search_knowledge
|
||||||
|
2025-09-10 23:20:25,542 - src.agent.tool_manager - INFO - 注册工具: create_work_order
|
||||||
|
2025-09-10 23:20:25,542 - src.agent.tool_manager - INFO - 注册工具: update_work_order
|
||||||
|
2025-09-10 23:20:25,543 - src.agent.tool_manager - INFO - 注册工具: generate_response
|
||||||
|
2025-09-10 23:20:25,543 - src.agent.tool_manager - INFO - 注册工具: analyze_data
|
||||||
|
2025-09-10 23:20:25,543 - src.agent.tool_manager - INFO - 注册工具: send_notification
|
||||||
|
2025-09-10 23:20:25,543 - src.agent.tool_manager - INFO - 注册工具: schedule_task
|
||||||
|
2025-09-10 23:20:25,543 - src.agent.tool_manager - INFO - 注册工具: web_search
|
||||||
|
2025-09-10 23:20:25,544 - src.agent.tool_manager - INFO - 注册工具: file_operation
|
||||||
|
2025-09-10 23:20:25,544 - src.agent.tool_manager - INFO - 注册工具: database_query
|
||||||
|
2025-09-10 23:20:25,544 - src.agent.tool_manager - INFO - 已注册 10 个默认工具
|
||||||
|
2025-09-10 23:20:25,544 - src.agent.agent_core - INFO - Agent核心初始化完成
|
||||||
|
2025-09-10 23:20:25,544 - src.agent_assistant - INFO - TSP Agent助手初始化完成
|
||||||
|
2025-09-10 23:20:25,558 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:20:25,639 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||||
|
* Running on all addresses (0.0.0.0)
|
||||||
|
* Running on http://127.0.0.1:5000
|
||||||
|
* Running on http://192.168.26.238:5000
|
||||||
|
2025-09-10 23:20:25,640 - werkzeug - INFO - [33mPress CTRL+C to quit[0m
|
||||||
|
2025-09-10 23:20:25,665 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目
|
||||||
|
2025-09-10 23:20:25,668 - src.web.websocket_server - INFO - 启动WebSocket服务器: ws://localhost:8765
|
||||||
|
2025-09-10 23:20:25,672 - websockets.server - INFO - server listening on 127.0.0.1:8765
|
||||||
|
2025-09-10 23:20:25,673 - websockets.server - INFO - server listening on [::1]:8765
|
||||||
|
2025-09-10 23:20:26,418 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:26] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:27,087 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:27] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:30,622 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:30] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:31,085 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:31] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:32,091 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:32] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:33,090 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:33] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:33,103 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:33] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:33,112 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:33] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:33,113 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:33] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:35,431 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:35] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:35,854 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:35] "GET / HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:35,908 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:35] "GET /static/js/dashboard.js HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:36,124 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:36] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:36,404 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:36] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:36,417 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:36] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:36,831 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:36] "GET /api/chat/sessions HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:36,835 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:36] "GET /api/workorders HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:36,844 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:36] "GET /api/system/info HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:36,865 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:36] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:36,882 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:36] "GET /api/knowledge/stats HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:36,903 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:36] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:37,097 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:37] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:37,147 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:37] "GET /api/analytics HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:37,463 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:37] "GET /api/analytics?timeRange=30&dimension=workorders HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:38,091 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:38] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:41,084 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:41] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:41,400 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:41] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:41,845 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:41] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:42,088 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:42] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:43,082 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:43] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:46,089 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:46] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:46,418 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:46] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:46,426 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:46] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:46,844 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:46] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:47,100 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:47] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:48,090 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:48] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:51,084 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:51] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:51,400 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:51] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:51,843 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:51] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:52,083 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:52] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:53,086 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:53] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:56,092 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:56] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:56,400 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:56] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:56,410 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:56] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:56,826 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:56] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:57,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:57] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:58,097 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:58] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:20:58,658 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:20:58] "GET /api/workorders HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:00,405 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:00,662 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:00] "GET /api/workorders HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:01,083 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:01] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:01,393 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:01] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:01,848 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:01] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:02,087 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:02] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:02,113 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:02] "GET /api/workorders/import/template HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:02,439 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:02] "[33mGET /uploads/workorder_template.xlsx HTTP/1.1[0m" 404 -
|
||||||
|
2025-09-10 23:21:03,089 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:03] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:04,826 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:04] "[33mGET /uploads/workorder_template.xlsx HTTP/1.1[0m" 404 -
|
||||||
|
2025-09-10 23:21:06,406 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:06] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:06,426 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:06] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:06,426 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:06] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:06,658 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:06] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:07,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:07] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:08,084 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:08] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:11,076 - src.dialogue.realtime_chat - INFO - 创建新会话: session_user_001_1757517671
|
||||||
|
2025-09-10 23:21:11,077 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:11] "POST /api/chat/session HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:11,406 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:11] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:11,406 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:11] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:11,828 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:11] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:12,083 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:12] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:12,791 - src.dialogue.realtime_chat - INFO - 结束会话: session_user_001_1757517671
|
||||||
|
2025-09-10 23:21:12,792 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:12] "DELETE /api/chat/session/session_user_001_1757517671 HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:13,086 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:13] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:14,633 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:14] "GET /api/agent/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:16,085 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:16] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:16,406 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:16] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:16,423 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:16] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:16,608 - src.analytics.monitor_service - INFO - 监控服务已启动
|
||||||
|
2025-09-10 23:21:16,614 - src.main - INFO - 监控服务已启动
|
||||||
|
2025-09-10 23:21:16,622 - src.agent.auto_monitor - INFO - 自动监控循环已启动
|
||||||
|
2025-09-10 23:21:16,622 - src.agent.auto_monitor - INFO - 自动监控服务已启动
|
||||||
|
2025-09-10 23:21:16,624 - src.agent.auto_monitor - INFO - 执行第 1 次自动监控检查
|
||||||
|
2025-09-10 23:21:16,625 - src.agent_assistant - INFO - 主动监控已启动
|
||||||
|
2025-09-10 23:21:16,642 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:16] "POST /api/agent/monitoring/start HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:16,673 - src.agent.auto_monitor - INFO - 触发主动行动: alert_overflow - 活跃预警数量过多: 42
|
||||||
|
2025-09-10 23:21:16,674 - src.agent.auto_monitor - INFO - 主动行动记录: {"timestamp": "2025-09-10T23:21:16.674688", "action_type": "alert_overflow", "priority": "high", "description": "活跃预警数量过多: 42", "action": "建议立即处理预警", "data": {"alert_count": 42}}
|
||||||
|
2025-09-10 23:21:16,674 - src.agent.auto_monitor - INFO - 处理预警溢出
|
||||||
|
2025-09-10 23:21:16,675 - src.agent.auto_monitor - ERROR - 检查工单积压失败: 'TSPAgentAssistant' object has no attribute 'get_workorders'
|
||||||
|
2025-09-10 23:21:16,711 - src.analytics.monitor_service - INFO - 触发 4 个预警
|
||||||
|
2025-09-10 23:21:16,712 - src.analytics.monitor_service - WARNING - 预警触发: 用户满意度较低: 0.00 (阈值: 0.6)
|
||||||
|
2025-09-10 23:21:16,712 - src.analytics.monitor_service - INFO - 发送通知: {'level': '警告', 'message': '用户满意度较低: 0.00 (阈值: 0.6)', 'timestamp': '2025-09-10T23:21:16.641218', 'rule_name': '满意度预警'}
|
||||||
|
2025-09-10 23:21:16,712 - src.analytics.monitor_service - WARNING - 警告预警: 用户满意度较低: 0.00 (阈值: 0.6)
|
||||||
|
2025-09-10 23:21:16,712 - src.analytics.monitor_service - WARNING - 预警触发: 知识库命中率较低: 0.00 (阈值: 0.5)
|
||||||
|
2025-09-10 23:21:16,713 - src.analytics.monitor_service - INFO - 发送通知: {'level': '警告', 'message': '知识库命中率较低: 0.00 (阈值: 0.5)', 'timestamp': '2025-09-10T23:21:16.676689', 'rule_name': '知识库命中率预警'}
|
||||||
|
2025-09-10 23:21:16,713 - src.analytics.monitor_service - WARNING - 警告预警: 知识库命中率较低: 0.00 (阈值: 0.5)
|
||||||
|
2025-09-10 23:21:16,713 - src.analytics.monitor_service - WARNING - 预警触发: 系统内存使用率过高: 106.6% (阈值: 80.0%)
|
||||||
|
2025-09-10 23:21:16,713 - src.analytics.monitor_service - INFO - 发送通知: {'level': '警告', 'message': '系统内存使用率过高: 106.6% (阈值: 80.0%)', 'timestamp': '2025-09-10T23:21:16.703711', 'rule_name': '内存使用预警'}
|
||||||
|
2025-09-10 23:21:16,714 - src.analytics.monitor_service - WARNING - 警告预警: 系统内存使用率过高: 106.6% (阈值: 80.0%)
|
||||||
|
2025-09-10 23:21:16,715 - src.analytics.monitor_service - WARNING - 预警触发: 用户对话中断率过高: 0.50 (阈值: 0.3)
|
||||||
|
2025-09-10 23:21:16,716 - src.analytics.monitor_service - INFO - 发送通知: {'level': '警告', 'message': '用户对话中断率过高: 0.50 (阈值: 0.3)', 'timestamp': '2025-09-10T23:21:16.709685', 'rule_name': '对话中断预警'}
|
||||||
|
2025-09-10 23:21:16,716 - src.analytics.monitor_service - WARNING - 警告预警: 用户对话中断率过高: 0.50 (阈值: 0.3)
|
||||||
|
2025-09-10 23:21:16,825 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:16] "GET /api/agent/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:16,836 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:16] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:17,089 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:17] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:17,822 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:17] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:18,089 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:18] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:18,144 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:18] "GET /api/knowledge?page=1&per_page=10 HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:19,064 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:19] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:20,783 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:20] "POST /api/alerts/53/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:21,104 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:21] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:21,374 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:21] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:21,409 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:21] "POST /api/alerts/54/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:21,410 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:21] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:21,648 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:21] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:21,736 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:21] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:21,938 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:21] "POST /api/alerts/55/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:22,081 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:22] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:22,258 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:22] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:22,476 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:22] "POST /api/alerts/55/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:22,525 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:22] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:22,807 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:22] "POST /api/alerts/56/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:23,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:23] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:23,131 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:23] "POST /api/alerts/56/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:23,132 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:23] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:23,289 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:23] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:23,670 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:23] "POST /api/alerts/47/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:23,991 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:23] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:24,178 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:24] "POST /api/alerts/47/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:24,244 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:24] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:24,488 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:24] "POST /api/alerts/48/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:24,802 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:24] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:24,804 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:24] "POST /api/alerts/48/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:24,988 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:24] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:25,152 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:25] "POST /api/alerts/49/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:25,477 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:25] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:25,667 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:25] "POST /api/alerts/49/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:25,734 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:25] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:25,992 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:25] "POST /api/alerts/50/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:26,320 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:26] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:26,416 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:26] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:26,416 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:26] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:26,506 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:26] "POST /api/alerts/50/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:26,556 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:26] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:26,644 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:26] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:26,827 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:26] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:26,886 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:26] "POST /api/alerts/51/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:26,969 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:26] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:27,105 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:27] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:27,137 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:27] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:27,286 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:27] "POST /api/alerts/52/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:27,435 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:27] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:27,634 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:27] "POST /api/alerts/52/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:27,652 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:27] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:28,073 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:28] "POST /api/alerts/41/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:28,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:28] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:28,393 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:28] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:28,601 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:28] "POST /api/alerts/41/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:28,648 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:28] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:31,090 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:31] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:31,398 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:31] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:31,836 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:31] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:31,966 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:31] "POST /api/alerts/25/resolve HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:32,095 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:32] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:34,992 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:34] "GET /api/knowledge?page=1&per_page=10 HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:36,746 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:36] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:36,840 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:36] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:37,001 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:37] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:42,077 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:42] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:47,411 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:47] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:47,423 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:47] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:52,086 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:52] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:57,399 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:57] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:21:57,411 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:21:57] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:00,112 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:00,123 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:00,149 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:00,406 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:00,416 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:00,436 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:02,409 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:02] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:07,108 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:07] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:07,400 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:07] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:12,403 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:12] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:17,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:17] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:17,388 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:17] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:22,399 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:22] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:27,086 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:27] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:27,399 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:27] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:32,386 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:32] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:37,087 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:37] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:22:37,400 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:22:37] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:23:00,093 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:23:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:23:00,107 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:23:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:23:00,394 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:23:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:23:00,410 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:23:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:23:00,419 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:23:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:23:00,646 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:23:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:23:00,713 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:23:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:23:00,726 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:23:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:24:00,109 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:24:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:24:00,137 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:24:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:24:00,421 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:24:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:24:00,425 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:24:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:24:00,427 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:24:00] "GET /api/monitor/status HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:24:00,660 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:24:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:24:00,746 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:24:00] "GET /api/alerts HTTP/1.1" 200 -
|
||||||
|
2025-09-10 23:24:00,767 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:24:00] "GET /api/health HTTP/1.1" 200 -
|
||||||
|
|||||||
255
src/agent/action_executor.py
Normal file
255
src/agent/action_executor.py
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Agent动作执行器 - 执行具体的Agent动作
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import asyncio
|
||||||
|
from typing import Dict, Any, List, Optional
|
||||||
|
from datetime import datetime
|
||||||
|
import json
|
||||||
|
|
||||||
|
from .intelligent_agent import AgentAction, ActionType, AlertContext, KnowledgeContext
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class ActionExecutor:
|
||||||
|
"""动作执行器"""
|
||||||
|
|
||||||
|
def __init__(self, tsp_assistant=None):
|
||||||
|
self.tsp_assistant = tsp_assistant
|
||||||
|
self.execution_history = []
|
||||||
|
self.action_handlers = {
|
||||||
|
ActionType.ALERT_RESPONSE: self._handle_alert_response,
|
||||||
|
ActionType.KNOWLEDGE_UPDATE: self._handle_knowledge_update,
|
||||||
|
ActionType.WORKORDER_CREATE: self._handle_workorder_create,
|
||||||
|
ActionType.SYSTEM_OPTIMIZE: self._handle_system_optimize,
|
||||||
|
ActionType.USER_NOTIFY: self._handle_user_notify
|
||||||
|
}
|
||||||
|
|
||||||
|
async def execute_action(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""执行动作"""
|
||||||
|
try:
|
||||||
|
logger.info(f"开始执行动作: {action.action_type.value}")
|
||||||
|
start_time = datetime.now()
|
||||||
|
|
||||||
|
# 获取处理器
|
||||||
|
handler = self.action_handlers.get(action.action_type)
|
||||||
|
if not handler:
|
||||||
|
return {"success": False, "error": f"未找到动作处理器: {action.action_type}"}
|
||||||
|
|
||||||
|
# 执行动作
|
||||||
|
result = await handler(action)
|
||||||
|
|
||||||
|
# 记录执行历史
|
||||||
|
execution_record = {
|
||||||
|
"action_id": f"{action.action_type.value}_{datetime.now().timestamp()}",
|
||||||
|
"action_type": action.action_type.value,
|
||||||
|
"description": action.description,
|
||||||
|
"priority": action.priority,
|
||||||
|
"confidence": action.confidence,
|
||||||
|
"start_time": start_time.isoformat(),
|
||||||
|
"end_time": datetime.now().isoformat(),
|
||||||
|
"success": result.get("success", False),
|
||||||
|
"result": result
|
||||||
|
}
|
||||||
|
self.execution_history.append(execution_record)
|
||||||
|
|
||||||
|
logger.info(f"动作执行完成: {action.action_type.value}, 结果: {result.get('success', False)}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"执行动作失败: {e}")
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
async def _handle_alert_response(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""处理预警响应"""
|
||||||
|
try:
|
||||||
|
alert_id = action.parameters.get("alert_id")
|
||||||
|
service = action.parameters.get("service")
|
||||||
|
|
||||||
|
# 根据动作描述执行具体操作
|
||||||
|
if "重启" in action.description:
|
||||||
|
return await self._restart_service(service)
|
||||||
|
elif "检查" in action.description:
|
||||||
|
return await self._check_system_status(alert_id)
|
||||||
|
elif "通知" in action.description:
|
||||||
|
return await self._notify_alert(alert_id, action.description)
|
||||||
|
else:
|
||||||
|
return await self._generic_alert_response(action)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"处理预警响应失败: {e}")
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
async def _handle_knowledge_update(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""处理知识库更新"""
|
||||||
|
try:
|
||||||
|
question = action.parameters.get("question")
|
||||||
|
enhanced_answer = action.parameters.get("enhanced_answer")
|
||||||
|
|
||||||
|
if enhanced_answer:
|
||||||
|
# 更新知识库条目
|
||||||
|
if self.tsp_assistant:
|
||||||
|
# 这里调用TSP助手的知识库更新方法
|
||||||
|
result = await self._update_knowledge_entry(question, enhanced_answer)
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
return {"success": True, "message": "知识库条目已标记更新"}
|
||||||
|
else:
|
||||||
|
# 标记低置信度条目
|
||||||
|
return await self._mark_low_confidence_knowledge(question)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"处理知识库更新失败: {e}")
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
async def _handle_workorder_create(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""处理工单创建"""
|
||||||
|
try:
|
||||||
|
title = action.parameters.get("title", "Agent自动创建工单")
|
||||||
|
description = action.description
|
||||||
|
category = action.parameters.get("category", "系统问题")
|
||||||
|
priority = action.parameters.get("priority", "medium")
|
||||||
|
|
||||||
|
if self.tsp_assistant:
|
||||||
|
# 调用TSP助手创建工单
|
||||||
|
workorder = self.tsp_assistant.create_work_order(
|
||||||
|
title=title,
|
||||||
|
description=description,
|
||||||
|
category=category,
|
||||||
|
priority=priority
|
||||||
|
)
|
||||||
|
return {"success": True, "workorder": workorder}
|
||||||
|
else:
|
||||||
|
return {"success": True, "message": "工单创建请求已记录"}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"处理工单创建失败: {e}")
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
async def _handle_system_optimize(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""处理系统优化"""
|
||||||
|
try:
|
||||||
|
optimization_type = action.parameters.get("type", "general")
|
||||||
|
|
||||||
|
if optimization_type == "performance":
|
||||||
|
return await self._optimize_performance(action)
|
||||||
|
elif optimization_type == "memory":
|
||||||
|
return await self._optimize_memory(action)
|
||||||
|
elif optimization_type == "database":
|
||||||
|
return await self._optimize_database(action)
|
||||||
|
else:
|
||||||
|
return await self._general_optimization(action)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"处理系统优化失败: {e}")
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
async def _handle_user_notify(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""处理用户通知"""
|
||||||
|
try:
|
||||||
|
message = action.description
|
||||||
|
user_id = action.parameters.get("user_id", "admin")
|
||||||
|
notification_type = action.parameters.get("type", "info")
|
||||||
|
|
||||||
|
# 这里实现具体的通知逻辑
|
||||||
|
# 可以是邮件、短信、系统通知等
|
||||||
|
return await self._send_notification(user_id, message, notification_type)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"处理用户通知失败: {e}")
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
# 具体实现方法
|
||||||
|
async def _restart_service(self, service: str) -> Dict[str, Any]:
|
||||||
|
"""重启服务"""
|
||||||
|
logger.info(f"重启服务: {service}")
|
||||||
|
# 这里实现具体的服务重启逻辑
|
||||||
|
await asyncio.sleep(2) # 模拟重启时间
|
||||||
|
return {"success": True, "message": f"服务 {service} 已重启"}
|
||||||
|
|
||||||
|
async def _check_system_status(self, alert_id: str) -> Dict[str, Any]:
|
||||||
|
"""检查系统状态"""
|
||||||
|
logger.info(f"检查系统状态: {alert_id}")
|
||||||
|
# 这里实现具体的系统检查逻辑
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
return {"success": True, "status": "正常", "alert_id": alert_id}
|
||||||
|
|
||||||
|
async def _notify_alert(self, alert_id: str, message: str) -> Dict[str, Any]:
|
||||||
|
"""通知预警"""
|
||||||
|
logger.info(f"通知预警: {alert_id} - {message}")
|
||||||
|
# 这里实现具体的通知逻辑
|
||||||
|
return {"success": True, "message": "预警通知已发送"}
|
||||||
|
|
||||||
|
async def _generic_alert_response(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""通用预警响应"""
|
||||||
|
logger.info(f"执行通用预警响应: {action.description}")
|
||||||
|
return {"success": True, "message": "预警响应已执行"}
|
||||||
|
|
||||||
|
async def _update_knowledge_entry(self, question: str, enhanced_answer: str) -> Dict[str, Any]:
|
||||||
|
"""更新知识库条目"""
|
||||||
|
logger.info(f"更新知识库条目: {question}")
|
||||||
|
# 这里实现具体的知识库更新逻辑
|
||||||
|
return {"success": True, "message": "知识库条目已更新"}
|
||||||
|
|
||||||
|
async def _mark_low_confidence_knowledge(self, question: str) -> Dict[str, Any]:
|
||||||
|
"""标记低置信度知识"""
|
||||||
|
logger.info(f"标记低置信度知识: {question}")
|
||||||
|
# 这里实现具体的标记逻辑
|
||||||
|
return {"success": True, "message": "低置信度知识已标记"}
|
||||||
|
|
||||||
|
async def _optimize_performance(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""性能优化"""
|
||||||
|
logger.info("执行性能优化")
|
||||||
|
# 这里实现具体的性能优化逻辑
|
||||||
|
return {"success": True, "message": "性能优化已执行"}
|
||||||
|
|
||||||
|
async def _optimize_memory(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""内存优化"""
|
||||||
|
logger.info("执行内存优化")
|
||||||
|
# 这里实现具体的内存优化逻辑
|
||||||
|
return {"success": True, "message": "内存优化已执行"}
|
||||||
|
|
||||||
|
async def _optimize_database(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""数据库优化"""
|
||||||
|
logger.info("执行数据库优化")
|
||||||
|
# 这里实现具体的数据库优化逻辑
|
||||||
|
return {"success": True, "message": "数据库优化已执行"}
|
||||||
|
|
||||||
|
async def _general_optimization(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""通用优化"""
|
||||||
|
logger.info(f"执行通用优化: {action.description}")
|
||||||
|
return {"success": True, "message": "系统优化已执行"}
|
||||||
|
|
||||||
|
async def _send_notification(self, user_id: str, message: str, notification_type: str) -> Dict[str, Any]:
|
||||||
|
"""发送通知"""
|
||||||
|
logger.info(f"发送通知给 {user_id}: {message}")
|
||||||
|
# 这里实现具体的通知发送逻辑
|
||||||
|
return {"success": True, "message": "通知已发送"}
|
||||||
|
|
||||||
|
def get_execution_history(self, limit: int = 100) -> List[Dict[str, Any]]:
|
||||||
|
"""获取执行历史"""
|
||||||
|
return self.execution_history[-limit:]
|
||||||
|
|
||||||
|
def get_action_statistics(self) -> Dict[str, Any]:
|
||||||
|
"""获取动作统计"""
|
||||||
|
total_actions = len(self.execution_history)
|
||||||
|
successful_actions = sum(1 for record in self.execution_history if record["success"])
|
||||||
|
|
||||||
|
action_types = {}
|
||||||
|
for record in self.execution_history:
|
||||||
|
action_type = record["action_type"]
|
||||||
|
if action_type not in action_types:
|
||||||
|
action_types[action_type] = {"total": 0, "successful": 0}
|
||||||
|
action_types[action_type]["total"] += 1
|
||||||
|
if record["success"]:
|
||||||
|
action_types[action_type]["successful"] += 1
|
||||||
|
|
||||||
|
return {
|
||||||
|
"total_actions": total_actions,
|
||||||
|
"successful_actions": successful_actions,
|
||||||
|
"success_rate": successful_actions / total_actions if total_actions > 0 else 0,
|
||||||
|
"action_types": action_types
|
||||||
|
}
|
||||||
368
src/agent/intelligent_agent.py
Normal file
368
src/agent/intelligent_agent.py
Normal file
@@ -0,0 +1,368 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
智能Agent核心 - 集成大模型和智能决策
|
||||||
|
高效实现Agent的智能处理能力
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
from typing import Dict, Any, List, Optional, Tuple
|
||||||
|
from datetime import datetime
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class ActionType(Enum):
|
||||||
|
"""动作类型枚举"""
|
||||||
|
ALERT_RESPONSE = "alert_response"
|
||||||
|
KNOWLEDGE_UPDATE = "knowledge_update"
|
||||||
|
WORKORDER_CREATE = "workorder_create"
|
||||||
|
SYSTEM_OPTIMIZE = "system_optimize"
|
||||||
|
USER_NOTIFY = "user_notify"
|
||||||
|
|
||||||
|
class ConfidenceLevel(Enum):
|
||||||
|
"""置信度等级"""
|
||||||
|
HIGH = "high" # 高置信度 (>0.8)
|
||||||
|
MEDIUM = "medium" # 中等置信度 (0.5-0.8)
|
||||||
|
LOW = "low" # 低置信度 (<0.5)
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class AgentAction:
|
||||||
|
"""Agent动作"""
|
||||||
|
action_type: ActionType
|
||||||
|
description: str
|
||||||
|
priority: int # 1-5, 5最高
|
||||||
|
confidence: float # 0-1
|
||||||
|
parameters: Dict[str, Any]
|
||||||
|
estimated_time: int # 预计执行时间(秒)
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class AlertContext:
|
||||||
|
"""预警上下文"""
|
||||||
|
alert_id: str
|
||||||
|
alert_type: str
|
||||||
|
severity: str
|
||||||
|
description: str
|
||||||
|
affected_systems: List[str]
|
||||||
|
metrics: Dict[str, Any]
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class KnowledgeContext:
|
||||||
|
"""知识库上下文"""
|
||||||
|
question: str
|
||||||
|
answer: str
|
||||||
|
confidence: float
|
||||||
|
source: str
|
||||||
|
category: str
|
||||||
|
|
||||||
|
class IntelligentAgent:
|
||||||
|
"""智能Agent核心"""
|
||||||
|
|
||||||
|
def __init__(self, llm_client=None):
|
||||||
|
self.llm_client = llm_client
|
||||||
|
self.action_history = []
|
||||||
|
self.learning_data = {}
|
||||||
|
self.confidence_thresholds = {
|
||||||
|
'high': 0.8,
|
||||||
|
'medium': 0.5,
|
||||||
|
'low': 0.3
|
||||||
|
}
|
||||||
|
|
||||||
|
async def process_alert(self, alert_context: AlertContext) -> List[AgentAction]:
|
||||||
|
"""处理预警信息,生成智能动作"""
|
||||||
|
try:
|
||||||
|
# 构建预警分析提示
|
||||||
|
prompt = self._build_alert_analysis_prompt(alert_context)
|
||||||
|
|
||||||
|
# 调用大模型分析
|
||||||
|
analysis = await self._call_llm(prompt)
|
||||||
|
|
||||||
|
# 解析动作
|
||||||
|
actions = self._parse_alert_actions(analysis, alert_context)
|
||||||
|
|
||||||
|
# 按优先级排序
|
||||||
|
actions.sort(key=lambda x: x.priority, reverse=True)
|
||||||
|
|
||||||
|
return actions
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"处理预警失败: {e}")
|
||||||
|
return [self._create_default_alert_action(alert_context)]
|
||||||
|
|
||||||
|
async def process_knowledge_confidence(self, knowledge_context: KnowledgeContext) -> List[AgentAction]:
|
||||||
|
"""处理知识库置信度问题"""
|
||||||
|
try:
|
||||||
|
if knowledge_context.confidence >= self.confidence_thresholds['high']:
|
||||||
|
return [] # 高置信度,无需处理
|
||||||
|
|
||||||
|
# 构建知识增强提示
|
||||||
|
prompt = self._build_knowledge_enhancement_prompt(knowledge_context)
|
||||||
|
|
||||||
|
# 调用大模型增强知识
|
||||||
|
enhancement = await self._call_llm(prompt)
|
||||||
|
|
||||||
|
# 生成增强动作
|
||||||
|
actions = self._parse_knowledge_actions(enhancement, knowledge_context)
|
||||||
|
|
||||||
|
return actions
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"处理知识库置信度失败: {e}")
|
||||||
|
return [self._create_default_knowledge_action(knowledge_context)]
|
||||||
|
|
||||||
|
async def execute_action(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""执行Agent动作"""
|
||||||
|
try:
|
||||||
|
logger.info(f"执行Agent动作: {action.action_type.value} - {action.description}")
|
||||||
|
|
||||||
|
if action.action_type == ActionType.ALERT_RESPONSE:
|
||||||
|
return await self._execute_alert_response(action)
|
||||||
|
elif action.action_type == ActionType.KNOWLEDGE_UPDATE:
|
||||||
|
return await self._execute_knowledge_update(action)
|
||||||
|
elif action.action_type == ActionType.WORKORDER_CREATE:
|
||||||
|
return await self._execute_workorder_create(action)
|
||||||
|
elif action.action_type == ActionType.SYSTEM_OPTIMIZE:
|
||||||
|
return await self._execute_system_optimize(action)
|
||||||
|
elif action.action_type == ActionType.USER_NOTIFY:
|
||||||
|
return await self._execute_user_notify(action)
|
||||||
|
else:
|
||||||
|
return {"success": False, "error": "未知动作类型"}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"执行动作失败: {e}")
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
def _build_alert_analysis_prompt(self, alert_context: AlertContext) -> str:
|
||||||
|
"""构建预警分析提示"""
|
||||||
|
return f"""
|
||||||
|
作为TSP智能助手,请分析以下预警信息并提供处理建议:
|
||||||
|
|
||||||
|
预警信息:
|
||||||
|
- 类型: {alert_context.alert_type}
|
||||||
|
- 严重程度: {alert_context.severity}
|
||||||
|
- 描述: {alert_context.description}
|
||||||
|
- 影响系统: {', '.join(alert_context.affected_systems)}
|
||||||
|
- 指标数据: {json.dumps(alert_context.metrics, ensure_ascii=False)}
|
||||||
|
|
||||||
|
请提供以下格式的JSON响应:
|
||||||
|
{{
|
||||||
|
"analysis": "预警原因分析",
|
||||||
|
"immediate_actions": [
|
||||||
|
{{
|
||||||
|
"action": "立即执行的动作",
|
||||||
|
"priority": 5,
|
||||||
|
"confidence": 0.9,
|
||||||
|
"parameters": {{"key": "value"}}
|
||||||
|
}}
|
||||||
|
],
|
||||||
|
"follow_up_actions": [
|
||||||
|
{{
|
||||||
|
"action": "后续跟进动作",
|
||||||
|
"priority": 3,
|
||||||
|
"confidence": 0.7,
|
||||||
|
"parameters": {{"key": "value"}}
|
||||||
|
}}
|
||||||
|
],
|
||||||
|
"prevention_measures": [
|
||||||
|
"预防措施1",
|
||||||
|
"预防措施2"
|
||||||
|
]
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _build_knowledge_enhancement_prompt(self, knowledge_context: KnowledgeContext) -> str:
|
||||||
|
"""构建知识增强提示"""
|
||||||
|
return f"""
|
||||||
|
作为TSP智能助手,请分析以下知识库条目并提供增强建议:
|
||||||
|
|
||||||
|
知识条目:
|
||||||
|
- 问题: {knowledge_context.question}
|
||||||
|
- 答案: {knowledge_context.answer}
|
||||||
|
- 置信度: {knowledge_context.confidence}
|
||||||
|
- 来源: {knowledge_context.source}
|
||||||
|
- 分类: {knowledge_context.category}
|
||||||
|
|
||||||
|
请提供以下格式的JSON响应:
|
||||||
|
{{
|
||||||
|
"confidence_analysis": "置信度分析",
|
||||||
|
"enhancement_suggestions": [
|
||||||
|
"增强建议1",
|
||||||
|
"增强建议2"
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
{{
|
||||||
|
"action": "知识更新动作",
|
||||||
|
"priority": 4,
|
||||||
|
"confidence": 0.8,
|
||||||
|
"parameters": {{"enhanced_answer": "增强后的答案"}}
|
||||||
|
}}
|
||||||
|
],
|
||||||
|
"learning_opportunities": [
|
||||||
|
"学习机会1",
|
||||||
|
"学习机会2"
|
||||||
|
]
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
async def _call_llm(self, prompt: str) -> Dict[str, Any]:
|
||||||
|
"""调用大模型"""
|
||||||
|
try:
|
||||||
|
if self.llm_client:
|
||||||
|
# 使用真实的大模型客户端
|
||||||
|
response = await self.llm_client.generate(prompt)
|
||||||
|
return json.loads(response)
|
||||||
|
else:
|
||||||
|
# 模拟大模型响应
|
||||||
|
return self._simulate_llm_response(prompt)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"调用大模型失败: {e}")
|
||||||
|
return self._simulate_llm_response(prompt)
|
||||||
|
|
||||||
|
def _simulate_llm_response(self, prompt: str) -> Dict[str, Any]:
|
||||||
|
"""模拟大模型响应"""
|
||||||
|
if "预警信息" in prompt:
|
||||||
|
return {
|
||||||
|
"analysis": "系统性能下降,需要立即处理",
|
||||||
|
"immediate_actions": [
|
||||||
|
{
|
||||||
|
"action": "重启相关服务",
|
||||||
|
"priority": 5,
|
||||||
|
"confidence": 0.9,
|
||||||
|
"parameters": {"service": "main_service"}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"follow_up_actions": [
|
||||||
|
{
|
||||||
|
"action": "检查系统日志",
|
||||||
|
"priority": 3,
|
||||||
|
"confidence": 0.7,
|
||||||
|
"parameters": {"log_level": "error"}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"prevention_measures": [
|
||||||
|
"增加监控频率",
|
||||||
|
"优化系统配置"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
"confidence_analysis": "当前答案置信度较低,需要更多上下文信息",
|
||||||
|
"enhancement_suggestions": [
|
||||||
|
"添加更多示例",
|
||||||
|
"提供详细步骤"
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"action": "更新知识库条目",
|
||||||
|
"priority": 4,
|
||||||
|
"confidence": 0.8,
|
||||||
|
"parameters": {"enhanced_answer": "增强后的答案"}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"learning_opportunities": [
|
||||||
|
"收集用户反馈",
|
||||||
|
"分析相似问题"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
def _parse_alert_actions(self, analysis: Dict[str, Any], alert_context: AlertContext) -> List[AgentAction]:
|
||||||
|
"""解析预警动作"""
|
||||||
|
actions = []
|
||||||
|
|
||||||
|
# 立即动作
|
||||||
|
for action_data in analysis.get("immediate_actions", []):
|
||||||
|
action = AgentAction(
|
||||||
|
action_type=ActionType.ALERT_RESPONSE,
|
||||||
|
description=action_data["action"],
|
||||||
|
priority=action_data["priority"],
|
||||||
|
confidence=action_data["confidence"],
|
||||||
|
parameters=action_data["parameters"],
|
||||||
|
estimated_time=30
|
||||||
|
)
|
||||||
|
actions.append(action)
|
||||||
|
|
||||||
|
# 后续动作
|
||||||
|
for action_data in analysis.get("follow_up_actions", []):
|
||||||
|
action = AgentAction(
|
||||||
|
action_type=ActionType.SYSTEM_OPTIMIZE,
|
||||||
|
description=action_data["action"],
|
||||||
|
priority=action_data["priority"],
|
||||||
|
confidence=action_data["confidence"],
|
||||||
|
parameters=action_data["parameters"],
|
||||||
|
estimated_time=300
|
||||||
|
)
|
||||||
|
actions.append(action)
|
||||||
|
|
||||||
|
return actions
|
||||||
|
|
||||||
|
def _parse_knowledge_actions(self, enhancement: Dict[str, Any], knowledge_context: KnowledgeContext) -> List[AgentAction]:
|
||||||
|
"""解析知识库动作"""
|
||||||
|
actions = []
|
||||||
|
|
||||||
|
for action_data in enhancement.get("actions", []):
|
||||||
|
action = AgentAction(
|
||||||
|
action_type=ActionType.KNOWLEDGE_UPDATE,
|
||||||
|
description=action_data["action"],
|
||||||
|
priority=action_data["priority"],
|
||||||
|
confidence=action_data["confidence"],
|
||||||
|
parameters=action_data["parameters"],
|
||||||
|
estimated_time=60
|
||||||
|
)
|
||||||
|
actions.append(action)
|
||||||
|
|
||||||
|
return actions
|
||||||
|
|
||||||
|
def _create_default_alert_action(self, alert_context: AlertContext) -> AgentAction:
|
||||||
|
"""创建默认预警动作"""
|
||||||
|
return AgentAction(
|
||||||
|
action_type=ActionType.USER_NOTIFY,
|
||||||
|
description=f"通知管理员处理{alert_context.alert_type}预警",
|
||||||
|
priority=3,
|
||||||
|
confidence=0.5,
|
||||||
|
parameters={"alert_id": alert_context.alert_id},
|
||||||
|
estimated_time=10
|
||||||
|
)
|
||||||
|
|
||||||
|
def _create_default_knowledge_action(self, knowledge_context: KnowledgeContext) -> AgentAction:
|
||||||
|
"""创建默认知识库动作"""
|
||||||
|
return AgentAction(
|
||||||
|
action_type=ActionType.KNOWLEDGE_UPDATE,
|
||||||
|
description="标记低置信度知识条目,等待人工审核",
|
||||||
|
priority=2,
|
||||||
|
confidence=0.3,
|
||||||
|
parameters={"question": knowledge_context.question},
|
||||||
|
estimated_time=5
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _execute_alert_response(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""执行预警响应动作"""
|
||||||
|
# 这里实现具体的预警响应逻辑
|
||||||
|
logger.info(f"执行预警响应: {action.description}")
|
||||||
|
return {"success": True, "message": "预警响应已执行"}
|
||||||
|
|
||||||
|
async def _execute_knowledge_update(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""执行知识库更新动作"""
|
||||||
|
# 这里实现具体的知识库更新逻辑
|
||||||
|
logger.info(f"执行知识库更新: {action.description}")
|
||||||
|
return {"success": True, "message": "知识库已更新"}
|
||||||
|
|
||||||
|
async def _execute_workorder_create(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""执行工单创建动作"""
|
||||||
|
# 这里实现具体的工单创建逻辑
|
||||||
|
logger.info(f"执行工单创建: {action.description}")
|
||||||
|
return {"success": True, "message": "工单已创建"}
|
||||||
|
|
||||||
|
async def _execute_system_optimize(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""执行系统优化动作"""
|
||||||
|
# 这里实现具体的系统优化逻辑
|
||||||
|
logger.info(f"执行系统优化: {action.description}")
|
||||||
|
return {"success": True, "message": "系统优化已执行"}
|
||||||
|
|
||||||
|
async def _execute_user_notify(self, action: AgentAction) -> Dict[str, Any]:
|
||||||
|
"""执行用户通知动作"""
|
||||||
|
# 这里实现具体的用户通知逻辑
|
||||||
|
logger.info(f"执行用户通知: {action.description}")
|
||||||
|
return {"success": True, "message": "用户已通知"}
|
||||||
244
src/agent/llm_client.py
Normal file
244
src/agent/llm_client.py
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
大模型客户端 - 统一的LLM接口
|
||||||
|
支持多种大模型提供商
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
from typing import Dict, Any, Optional, List
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class LLMConfig:
|
||||||
|
"""LLM配置"""
|
||||||
|
provider: str # openai, anthropic, local, etc.
|
||||||
|
api_key: str
|
||||||
|
base_url: Optional[str] = None
|
||||||
|
model: str = "gpt-3.5-turbo"
|
||||||
|
temperature: float = 0.7
|
||||||
|
max_tokens: int = 2000
|
||||||
|
|
||||||
|
class BaseLLMClient(ABC):
|
||||||
|
"""LLM客户端基类"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def generate(self, prompt: str, **kwargs) -> str:
|
||||||
|
"""生成文本"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def chat(self, messages: List[Dict[str, str]], **kwargs) -> str:
|
||||||
|
"""对话生成"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class OpenAIClient(BaseLLMClient):
|
||||||
|
"""OpenAI客户端"""
|
||||||
|
|
||||||
|
def __init__(self, config: LLMConfig):
|
||||||
|
self.config = config
|
||||||
|
self.client = None
|
||||||
|
self._init_client()
|
||||||
|
|
||||||
|
def _init_client(self):
|
||||||
|
"""初始化客户端"""
|
||||||
|
try:
|
||||||
|
import openai
|
||||||
|
self.client = openai.AsyncOpenAI(
|
||||||
|
api_key=self.config.api_key,
|
||||||
|
base_url=self.config.base_url
|
||||||
|
)
|
||||||
|
except ImportError:
|
||||||
|
logger.warning("OpenAI库未安装,将使用模拟客户端")
|
||||||
|
self.client = None
|
||||||
|
|
||||||
|
async def generate(self, prompt: str, **kwargs) -> str:
|
||||||
|
"""生成文本"""
|
||||||
|
if not self.client:
|
||||||
|
return self._simulate_response(prompt)
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = await self.client.chat.completions.create(
|
||||||
|
model=self.config.model,
|
||||||
|
messages=[{"role": "user", "content": prompt}],
|
||||||
|
temperature=kwargs.get("temperature", self.config.temperature),
|
||||||
|
max_tokens=kwargs.get("max_tokens", self.config.max_tokens)
|
||||||
|
)
|
||||||
|
return response.choices[0].message.content
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"OpenAI API调用失败: {e}")
|
||||||
|
return self._simulate_response(prompt)
|
||||||
|
|
||||||
|
async def chat(self, messages: List[Dict[str, str]], **kwargs) -> str:
|
||||||
|
"""对话生成"""
|
||||||
|
if not self.client:
|
||||||
|
return self._simulate_chat(messages)
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = await self.client.chat.completions.create(
|
||||||
|
model=self.config.model,
|
||||||
|
messages=messages,
|
||||||
|
temperature=kwargs.get("temperature", self.config.temperature),
|
||||||
|
max_tokens=kwargs.get("max_tokens", self.config.max_tokens)
|
||||||
|
)
|
||||||
|
return response.choices[0].message.content
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"OpenAI Chat API调用失败: {e}")
|
||||||
|
return self._simulate_chat(messages)
|
||||||
|
|
||||||
|
def _simulate_response(self, prompt: str) -> str:
|
||||||
|
"""模拟响应"""
|
||||||
|
return f"模拟LLM响应: {prompt[:100]}..."
|
||||||
|
|
||||||
|
def _simulate_chat(self, messages: List[Dict[str, str]]) -> str:
|
||||||
|
"""模拟对话响应"""
|
||||||
|
last_message = messages[-1]["content"] if messages else ""
|
||||||
|
return f"模拟对话响应: {last_message[:100]}..."
|
||||||
|
|
||||||
|
class AnthropicClient(BaseLLMClient):
|
||||||
|
"""Anthropic客户端"""
|
||||||
|
|
||||||
|
def __init__(self, config: LLMConfig):
|
||||||
|
self.config = config
|
||||||
|
self.client = None
|
||||||
|
self._init_client()
|
||||||
|
|
||||||
|
def _init_client(self):
|
||||||
|
"""初始化客户端"""
|
||||||
|
try:
|
||||||
|
import anthropic
|
||||||
|
self.client = anthropic.AsyncAnthropic(
|
||||||
|
api_key=self.config.api_key
|
||||||
|
)
|
||||||
|
except ImportError:
|
||||||
|
logger.warning("Anthropic库未安装,将使用模拟客户端")
|
||||||
|
self.client = None
|
||||||
|
|
||||||
|
async def generate(self, prompt: str, **kwargs) -> str:
|
||||||
|
"""生成文本"""
|
||||||
|
if not self.client:
|
||||||
|
return self._simulate_response(prompt)
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = await self.client.messages.create(
|
||||||
|
model=self.config.model,
|
||||||
|
max_tokens=kwargs.get("max_tokens", self.config.max_tokens),
|
||||||
|
temperature=kwargs.get("temperature", self.config.temperature),
|
||||||
|
messages=[{"role": "user", "content": prompt}]
|
||||||
|
)
|
||||||
|
return response.content[0].text
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Anthropic API调用失败: {e}")
|
||||||
|
return self._simulate_response(prompt)
|
||||||
|
|
||||||
|
async def chat(self, messages: List[Dict[str, str]], **kwargs) -> str:
|
||||||
|
"""对话生成"""
|
||||||
|
if not self.client:
|
||||||
|
return self._simulate_chat(messages)
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = await self.client.messages.create(
|
||||||
|
model=self.config.model,
|
||||||
|
max_tokens=kwargs.get("max_tokens", self.config.max_tokens),
|
||||||
|
temperature=kwargs.get("temperature", self.config.temperature),
|
||||||
|
messages=messages
|
||||||
|
)
|
||||||
|
return response.content[0].text
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Anthropic Chat API调用失败: {e}")
|
||||||
|
return self._simulate_chat(messages)
|
||||||
|
|
||||||
|
def _simulate_response(self, prompt: str) -> str:
|
||||||
|
"""模拟响应"""
|
||||||
|
return f"模拟Anthropic响应: {prompt[:100]}..."
|
||||||
|
|
||||||
|
def _simulate_chat(self, messages: List[Dict[str, str]]) -> str:
|
||||||
|
"""模拟对话响应"""
|
||||||
|
last_message = messages[-1]["content"] if messages else ""
|
||||||
|
return f"模拟Anthropic对话: {last_message[:100]}..."
|
||||||
|
|
||||||
|
class LocalLLMClient(BaseLLMClient):
|
||||||
|
"""本地LLM客户端"""
|
||||||
|
|
||||||
|
def __init__(self, config: LLMConfig):
|
||||||
|
self.config = config
|
||||||
|
self.client = None
|
||||||
|
self._init_client()
|
||||||
|
|
||||||
|
def _init_client(self):
|
||||||
|
"""初始化本地客户端"""
|
||||||
|
try:
|
||||||
|
# 这里可以集成Ollama、vLLM等本地LLM服务
|
||||||
|
logger.info("本地LLM客户端初始化")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"本地LLM客户端初始化失败: {e}")
|
||||||
|
|
||||||
|
async def generate(self, prompt: str, **kwargs) -> str:
|
||||||
|
"""生成文本"""
|
||||||
|
# 实现本地LLM调用
|
||||||
|
return f"本地LLM响应: {prompt[:100]}..."
|
||||||
|
|
||||||
|
async def chat(self, messages: List[Dict[str, str]], **kwargs) -> str:
|
||||||
|
"""对话生成"""
|
||||||
|
last_message = messages[-1]["content"] if messages else ""
|
||||||
|
return f"本地LLM对话: {last_message[:100]}..."
|
||||||
|
|
||||||
|
class LLMClientFactory:
|
||||||
|
"""LLM客户端工厂"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_client(config: LLMConfig) -> BaseLLMClient:
|
||||||
|
"""创建LLM客户端"""
|
||||||
|
if config.provider.lower() == "openai":
|
||||||
|
return OpenAIClient(config)
|
||||||
|
elif config.provider.lower() == "anthropic":
|
||||||
|
return AnthropicClient(config)
|
||||||
|
elif config.provider.lower() == "local":
|
||||||
|
return LocalLLMClient(config)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"不支持的LLM提供商: {config.provider}")
|
||||||
|
|
||||||
|
class LLMManager:
|
||||||
|
"""LLM管理器"""
|
||||||
|
|
||||||
|
def __init__(self, config: LLMConfig):
|
||||||
|
self.config = config
|
||||||
|
self.client = LLMClientFactory.create_client(config)
|
||||||
|
self.usage_stats = {
|
||||||
|
"total_requests": 0,
|
||||||
|
"total_tokens": 0,
|
||||||
|
"error_count": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
async def generate(self, prompt: str, **kwargs) -> str:
|
||||||
|
"""生成文本"""
|
||||||
|
try:
|
||||||
|
self.usage_stats["total_requests"] += 1
|
||||||
|
response = await self.client.generate(prompt, **kwargs)
|
||||||
|
self.usage_stats["total_tokens"] += len(response)
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
self.usage_stats["error_count"] += 1
|
||||||
|
logger.error(f"LLM生成失败: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
async def chat(self, messages: List[Dict[str, str]], **kwargs) -> str:
|
||||||
|
"""对话生成"""
|
||||||
|
try:
|
||||||
|
self.usage_stats["total_requests"] += 1
|
||||||
|
response = await self.client.chat(messages, **kwargs)
|
||||||
|
self.usage_stats["total_tokens"] += len(response)
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
self.usage_stats["error_count"] += 1
|
||||||
|
logger.error(f"LLM对话失败: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
def get_usage_stats(self) -> Dict[str, Any]:
|
||||||
|
"""获取使用统计"""
|
||||||
|
return self.usage_stats.copy()
|
||||||
@@ -14,13 +14,16 @@ import json
|
|||||||
from src.main import TSPAssistant
|
from src.main import TSPAssistant
|
||||||
from src.agent import AgentCore, AgentState
|
from src.agent import AgentCore, AgentState
|
||||||
from src.agent.auto_monitor import AutoMonitorService
|
from src.agent.auto_monitor import AutoMonitorService
|
||||||
|
from src.agent.intelligent_agent import IntelligentAgent, AlertContext, KnowledgeContext
|
||||||
|
from src.agent.llm_client import LLMManager, LLMConfig
|
||||||
|
from src.agent.action_executor import ActionExecutor
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class TSPAgentAssistant(TSPAssistant):
|
class TSPAgentAssistant(TSPAssistant):
|
||||||
"""TSP Agent助手 - 增强版TSP助手,具备完整Agent功能"""
|
"""TSP Agent助手 - 增强版TSP助手,具备完整Agent功能"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, llm_config: Optional[LLMConfig] = None):
|
||||||
# 初始化基础TSP助手
|
# 初始化基础TSP助手
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@@ -30,6 +33,24 @@ class TSPAgentAssistant(TSPAssistant):
|
|||||||
# 初始化自动监控服务
|
# 初始化自动监控服务
|
||||||
self.auto_monitor = AutoMonitorService(self)
|
self.auto_monitor = AutoMonitorService(self)
|
||||||
|
|
||||||
|
# 初始化LLM客户端
|
||||||
|
if llm_config:
|
||||||
|
self.llm_manager = LLMManager(llm_config)
|
||||||
|
else:
|
||||||
|
# 使用默认配置
|
||||||
|
default_config = LLMConfig(
|
||||||
|
provider="openai",
|
||||||
|
api_key="your-api-key-here",
|
||||||
|
model="gpt-3.5-turbo"
|
||||||
|
)
|
||||||
|
self.llm_manager = LLMManager(default_config)
|
||||||
|
|
||||||
|
# 初始化智能Agent
|
||||||
|
self.intelligent_agent = IntelligentAgent(self.llm_manager)
|
||||||
|
|
||||||
|
# 初始化动作执行器
|
||||||
|
self.action_executor = ActionExecutor(self)
|
||||||
|
|
||||||
# Agent特有功能
|
# Agent特有功能
|
||||||
self.is_agent_mode = True
|
self.is_agent_mode = True
|
||||||
self.proactive_tasks = []
|
self.proactive_tasks = []
|
||||||
@@ -286,37 +307,84 @@ class TSPAgentAssistant(TSPAssistant):
|
|||||||
# 检查预警
|
# 检查预警
|
||||||
alerts = self.get_alerts()
|
alerts = self.get_alerts()
|
||||||
if alerts.get("count", 0) > 0:
|
if alerts.get("count", 0) > 0:
|
||||||
proactive_actions.append({
|
# 创建预警上下文
|
||||||
"type": "alert_response",
|
alert_context = AlertContext(
|
||||||
"description": f"发现 {alerts['count']} 个活跃预警",
|
alert_id=f"alert_{datetime.now().timestamp()}",
|
||||||
"priority": "high",
|
alert_type="system_alert",
|
||||||
"action": "需要立即处理预警"
|
severity="high",
|
||||||
})
|
description=f"发现 {alerts['count']} 个活跃预警",
|
||||||
|
affected_systems=["main_system"],
|
||||||
|
metrics={"alert_count": alerts['count']}
|
||||||
|
)
|
||||||
|
|
||||||
|
# 使用智能Agent处理预警
|
||||||
|
alert_actions = await self.intelligent_agent.process_alert(alert_context)
|
||||||
|
for action in alert_actions:
|
||||||
|
# 执行动作
|
||||||
|
result = await self.action_executor.execute_action(action)
|
||||||
|
proactive_actions.append({
|
||||||
|
"type": "alert_response",
|
||||||
|
"description": action.description,
|
||||||
|
"priority": action.priority,
|
||||||
|
"confidence": action.confidence,
|
||||||
|
"result": result
|
||||||
|
})
|
||||||
|
|
||||||
# 检查系统健康
|
# 检查系统健康
|
||||||
system_status = self.get_system_status()
|
system_status = self.get_system_status()
|
||||||
if system_status.get("health_score", 1.0) < 0.8:
|
if system_status.get("health_score", 1.0) < 0.8:
|
||||||
proactive_actions.append({
|
# 创建系统健康预警上下文
|
||||||
"type": "system_maintenance",
|
health_alert_context = AlertContext(
|
||||||
"description": "系统健康状态不佳",
|
alert_id=f"health_{datetime.now().timestamp()}",
|
||||||
"priority": "medium",
|
alert_type="system_health",
|
||||||
"action": "建议进行系统维护"
|
severity="medium",
|
||||||
})
|
description="系统健康状态不佳",
|
||||||
|
affected_systems=["main_system"],
|
||||||
|
metrics={"health_score": system_status.get("health_score", 0.5)}
|
||||||
|
)
|
||||||
|
|
||||||
|
health_actions = await self.intelligent_agent.process_alert(health_alert_context)
|
||||||
|
for action in health_actions:
|
||||||
|
result = await self.action_executor.execute_action(action)
|
||||||
|
proactive_actions.append({
|
||||||
|
"type": "system_maintenance",
|
||||||
|
"description": action.description,
|
||||||
|
"priority": action.priority,
|
||||||
|
"confidence": action.confidence,
|
||||||
|
"result": result
|
||||||
|
})
|
||||||
|
|
||||||
# 检查知识库质量
|
# 检查知识库质量
|
||||||
knowledge_stats = self.knowledge_manager.get_knowledge_stats()
|
knowledge_stats = self.knowledge_manager.get_knowledge_stats()
|
||||||
if knowledge_stats.get("average_confidence", 0.8) < 0.6:
|
if knowledge_stats.get("average_confidence", 0.8) < 0.6:
|
||||||
proactive_actions.append({
|
# 处理低置信度知识
|
||||||
"type": "knowledge_improvement",
|
low_confidence_items = knowledge_stats.get("low_confidence_items", [])
|
||||||
"description": "知识库质量需要提升",
|
for item in low_confidence_items:
|
||||||
"priority": "low",
|
knowledge_context = KnowledgeContext(
|
||||||
"action": "建议更新知识库"
|
question=item.get("question", ""),
|
||||||
})
|
answer=item.get("answer", ""),
|
||||||
|
confidence=item.get("confidence", 0.3),
|
||||||
|
source=item.get("source", "unknown"),
|
||||||
|
category=item.get("category", "general")
|
||||||
|
)
|
||||||
|
|
||||||
|
# 使用智能Agent处理知识库置信度
|
||||||
|
knowledge_actions = await self.intelligent_agent.process_knowledge_confidence(knowledge_context)
|
||||||
|
for action in knowledge_actions:
|
||||||
|
result = await self.action_executor.execute_action(action)
|
||||||
|
proactive_actions.append({
|
||||||
|
"type": "knowledge_improvement",
|
||||||
|
"description": action.description,
|
||||||
|
"priority": action.priority,
|
||||||
|
"confidence": action.confidence,
|
||||||
|
"result": result
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"proactive_actions": proactive_actions,
|
"proactive_actions": proactive_actions,
|
||||||
"timestamp": datetime.now().isoformat(),
|
"timestamp": datetime.now().isoformat(),
|
||||||
"agent_status": self.agent_core.get_status()
|
"agent_status": self.agent_core.get_status(),
|
||||||
|
"llm_usage": self.llm_manager.get_usage_stats()
|
||||||
}
|
}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -422,16 +490,20 @@ class TSPAgentAssistant(TSPAssistant):
|
|||||||
"monitoring_active": monitor_status["is_running"],
|
"monitoring_active": monitor_status["is_running"],
|
||||||
"status": "active" if self.is_agent_mode else "inactive",
|
"status": "active" if self.is_agent_mode else "inactive",
|
||||||
"active_goals": 0, # 简化处理
|
"active_goals": 0, # 简化处理
|
||||||
"available_tools": 6, # 简化处理
|
"available_tools": 8, # 增加工具数量
|
||||||
|
"llm_usage": self.llm_manager.get_usage_stats(),
|
||||||
|
"action_executor_stats": self.action_executor.get_action_statistics(),
|
||||||
"tools": [
|
"tools": [
|
||||||
{"name": "search_knowledge", "usage_count": 0, "success_rate": 0.8},
|
{"name": "search_knowledge", "usage_count": 0, "success_rate": 0.8},
|
||||||
{"name": "create_work_order", "usage_count": 0, "success_rate": 0.8},
|
{"name": "create_work_order", "usage_count": 0, "success_rate": 0.8},
|
||||||
{"name": "update_work_order", "usage_count": 0, "success_rate": 0.8},
|
{"name": "update_work_order", "usage_count": 0, "success_rate": 0.8},
|
||||||
{"name": "generate_response", "usage_count": 0, "success_rate": 0.8},
|
{"name": "generate_response", "usage_count": 0, "success_rate": 0.8},
|
||||||
{"name": "analyze_data", "usage_count": 0, "success_rate": 0.8},
|
{"name": "analyze_data", "usage_count": 0, "success_rate": 0.8},
|
||||||
{"name": "send_notification", "usage_count": 0, "success_rate": 0.8}
|
{"name": "send_notification", "usage_count": 0, "success_rate": 0.8},
|
||||||
|
{"name": "process_alert", "usage_count": 0, "success_rate": 0.9},
|
||||||
|
{"name": "enhance_knowledge", "usage_count": 0, "success_rate": 0.7}
|
||||||
],
|
],
|
||||||
"execution_history": [],
|
"execution_history": self.action_executor.get_execution_history(10),
|
||||||
"auto_monitor": monitor_status
|
"auto_monitor": monitor_status
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -768,6 +840,97 @@ class TSPAgentAssistant(TSPAssistant):
|
|||||||
logger.error(f"获取工单洞察失败: {e}")
|
logger.error(f"获取工单洞察失败: {e}")
|
||||||
return "获取工单数据失败"
|
return "获取工单数据失败"
|
||||||
|
|
||||||
|
def get_action_history(self, limit: int = 50) -> List[Dict[str, Any]]:
|
||||||
|
"""获取动作执行历史"""
|
||||||
|
try:
|
||||||
|
return self.action_executor.get_execution_history(limit)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取动作历史失败: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_llm_usage_stats(self) -> Dict[str, Any]:
|
||||||
|
"""获取LLM使用统计"""
|
||||||
|
try:
|
||||||
|
return self.llm_manager.get_usage_stats()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取LLM使用统计失败: {e}")
|
||||||
|
return {}
|
||||||
|
|
||||||
|
async def process_alert_with_agent(self, alert_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
"""使用Agent处理预警"""
|
||||||
|
try:
|
||||||
|
# 创建预警上下文
|
||||||
|
alert_context = AlertContext(
|
||||||
|
alert_id=alert_data.get("id", f"alert_{datetime.now().timestamp()}"),
|
||||||
|
alert_type=alert_data.get("type", "unknown"),
|
||||||
|
severity=alert_data.get("severity", "medium"),
|
||||||
|
description=alert_data.get("description", ""),
|
||||||
|
affected_systems=alert_data.get("affected_systems", []),
|
||||||
|
metrics=alert_data.get("metrics", {})
|
||||||
|
)
|
||||||
|
|
||||||
|
# 使用智能Agent处理预警
|
||||||
|
actions = await self.intelligent_agent.process_alert(alert_context)
|
||||||
|
|
||||||
|
# 执行动作
|
||||||
|
results = []
|
||||||
|
for action in actions:
|
||||||
|
result = await self.action_executor.execute_action(action)
|
||||||
|
results.append({
|
||||||
|
"action": action.description,
|
||||||
|
"priority": action.priority,
|
||||||
|
"confidence": action.confidence,
|
||||||
|
"result": result
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"alert_id": alert_context.alert_id,
|
||||||
|
"actions_taken": len(actions),
|
||||||
|
"results": results
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Agent处理预警失败: {e}")
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
async def enhance_knowledge_with_agent(self, knowledge_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
"""使用Agent增强知识库"""
|
||||||
|
try:
|
||||||
|
# 创建知识上下文
|
||||||
|
knowledge_context = KnowledgeContext(
|
||||||
|
question=knowledge_data.get("question", ""),
|
||||||
|
answer=knowledge_data.get("answer", ""),
|
||||||
|
confidence=knowledge_data.get("confidence", 0.5),
|
||||||
|
source=knowledge_data.get("source", "unknown"),
|
||||||
|
category=knowledge_data.get("category", "general")
|
||||||
|
)
|
||||||
|
|
||||||
|
# 使用智能Agent处理知识库置信度
|
||||||
|
actions = await self.intelligent_agent.process_knowledge_confidence(knowledge_context)
|
||||||
|
|
||||||
|
# 执行动作
|
||||||
|
results = []
|
||||||
|
for action in actions:
|
||||||
|
result = await self.action_executor.execute_action(action)
|
||||||
|
results.append({
|
||||||
|
"action": action.description,
|
||||||
|
"priority": action.priority,
|
||||||
|
"confidence": action.confidence,
|
||||||
|
"result": result
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"question": knowledge_context.question,
|
||||||
|
"actions_taken": len(actions),
|
||||||
|
"results": results
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Agent增强知识库失败: {e}")
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
def _parse_knowledge_manually(self, content: str) -> List[Dict[str, Any]]:
|
def _parse_knowledge_manually(self, content: str) -> List[Dict[str, Any]]:
|
||||||
"""手动解析知识内容"""
|
"""手动解析知识内容"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user