diff --git a/logs/dashboard.log b/logs/dashboard.log index a3ff5ab..4ee8fed 100644 --- a/logs/dashboard.log +++ b/logs/dashboard.log @@ -3545,3 +3545,132 @@ WHERE knowledge_entries.is_active = true AND knowledge_entries.is_verified = tru 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 - +2025-09-10 23:56:59,913 - __main__ - INFO - 正在启动TSP智能助手综合管理平台... +2025-09-10 23:57:01,660 - src.core.database - INFO - 数据库初始化成功 +2025-09-10 23:57:02,839 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目 +2025-09-10 23:57:02,847 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目 +2025-09-10 23:57:02,848 - src.main - INFO - TSP助手初始化完成 +2025-09-10 23:57:02,857 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目 +2025-09-10 23:57:02,866 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目 +2025-09-10 23:57:02,868 - src.main - INFO - TSP助手初始化完成 +2025-09-10 23:57:02,868 - src.agent.tool_manager - INFO - 注册工具: search_knowledge +2025-09-10 23:57:02,868 - src.agent.tool_manager - INFO - 注册工具: create_work_order +2025-09-10 23:57:02,868 - src.agent.tool_manager - INFO - 注册工具: update_work_order +2025-09-10 23:57:02,869 - src.agent.tool_manager - INFO - 注册工具: generate_response +2025-09-10 23:57:02,869 - src.agent.tool_manager - INFO - 注册工具: analyze_data +2025-09-10 23:57:02,869 - src.agent.tool_manager - INFO - 注册工具: send_notification +2025-09-10 23:57:02,869 - src.agent.tool_manager - INFO - 注册工具: schedule_task +2025-09-10 23:57:02,869 - src.agent.tool_manager - INFO - 注册工具: web_search +2025-09-10 23:57:02,870 - src.agent.tool_manager - INFO - 注册工具: file_operation +2025-09-10 23:57:02,870 - src.agent.tool_manager - INFO - 注册工具: database_query +2025-09-10 23:57:02,870 - src.agent.tool_manager - INFO - 已注册 10 个默认工具 +2025-09-10 23:57:02,870 - src.agent.agent_core - INFO - Agent核心初始化完成 +2025-09-10 23:57:03,803 - src.agent_assistant - INFO - TSP Agent助手初始化完成 +2025-09-10 23:57:03,815 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目 +2025-09-10 23:57:03,899 - werkzeug - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * 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:57:03,902 - werkzeug - INFO - Press CTRL+C to quit +2025-09-10 23:57:03,941 - src.knowledge_base.knowledge_manager - INFO - 向量化器加载成功,包含 48 个条目 +2025-09-10 23:57:03,944 - src.web.websocket_server - INFO - 启动WebSocket服务器: ws://localhost:8765 +2025-09-10 23:57:03,949 - websockets.server - INFO - server listening on [::1]:8765 +2025-09-10 23:57:03,952 - websockets.server - INFO - server listening on 127.0.0.1:8765 +2025-09-10 23:57:04,054 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:04] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:04,311 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:04] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:09,019 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:09] "GET / HTTP/1.1" 200 - +2025-09-10 23:57:09,316 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:09] "GET /static/js/dashboard.js HTTP/1.1" 200 - +2025-09-10 23:57:10,100 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:10] "GET /api/chat/sessions HTTP/1.1" 200 - +2025-09-10 23:57:10,111 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:10] "GET /api/workorders HTTP/1.1" 200 - +2025-09-10 23:57:10,122 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:10] "GET /api/system/info HTTP/1.1" 200 - +2025-09-10 23:57:10,161 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:10] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:10,167 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:10] "GET /api/knowledge/stats HTTP/1.1" 200 - +2025-09-10 23:57:10,179 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:10] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:10,525 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:10] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:11,894 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:11] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:11,912 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:11] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:12,148 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:12] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:12,348 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:12] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:12,358 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:12] "GET /api/monitor/status HTTP/1.1" 200 - +2025-09-10 23:57:12,890 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:12] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:14,605 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:14] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:15,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:15] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:17,178 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:17] "GET /api/chat/sessions HTTP/1.1" 200 - +2025-09-10 23:57:17,296 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:17] "GET /api/workorders HTTP/1.1" 200 - +2025-09-10 23:57:17,311 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:17] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:17,321 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:17] "GET /api/knowledge/stats HTTP/1.1" 200 - +2025-09-10 23:57:17,984 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:17] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:57:19,622 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:19] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:57:19,887 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:19] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:20,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:20] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:57:24,800 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:24] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:26,267 - src.analytics.monitor_service - INFO - 监控服务已启动 +2025-09-10 23:57:26,267 - src.main - INFO - 监控服务已启动 +2025-09-10 23:57:26,272 - src.agent.auto_monitor - INFO - 自动监控循环已启动 +2025-09-10 23:57:26,273 - src.agent.auto_monitor - INFO - 自动监控服务已启动 +2025-09-10 23:57:26,273 - src.agent.auto_monitor - INFO - 执行第 1 次自动监控检查 +2025-09-10 23:57:26,273 - src.agent_assistant - INFO - 主动监控已启动 +2025-09-10 23:57:26,282 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:26] "POST /api/agent/monitoring/start HTTP/1.1" 200 - +2025-09-10 23:57:26,349 - src.agent.auto_monitor - INFO - 触发主动行动: alert_overflow - 活跃预警数量过多: 34 +2025-09-10 23:57:26,350 - src.agent.auto_monitor - INFO - 主动行动记录: {"timestamp": "2025-09-10T23:57:26.350917", "action_type": "alert_overflow", "priority": "high", "description": "活跃预警数量过多: 34", "action": "建议立即处理预警", "data": {"alert_count": 34}} +2025-09-10 23:57:26,351 - src.agent.auto_monitor - INFO - 处理预警溢出 +2025-09-10 23:57:26,355 - src.agent.auto_monitor - ERROR - 检查工单积压失败: 'TSPAgentAssistant' object has no attribute 'get_workorders' +2025-09-10 23:57:26,405 - src.analytics.monitor_service - INFO - 触发 4 个预警 +2025-09-10 23:57:26,406 - src.analytics.monitor_service - WARNING - 预警触发: 用户满意度较低: 0.00 (阈值: 0.6) +2025-09-10 23:57:26,407 - src.analytics.monitor_service - INFO - 发送通知: {'level': '警告', 'message': '用户满意度较低: 0.00 (阈值: 0.6)', 'timestamp': '2025-09-10T23:57:26.283431', 'rule_name': '满意度预警'} +2025-09-10 23:57:26,408 - src.analytics.monitor_service - WARNING - 警告预警: 用户满意度较低: 0.00 (阈值: 0.6) +2025-09-10 23:57:26,408 - src.analytics.monitor_service - WARNING - 预警触发: 知识库命中率较低: 0.00 (阈值: 0.5) +2025-09-10 23:57:26,409 - src.analytics.monitor_service - INFO - 发送通知: {'level': '警告', 'message': '知识库命中率较低: 0.00 (阈值: 0.5)', 'timestamp': '2025-09-10T23:57:26.329923', 'rule_name': '知识库命中率预警'} +2025-09-10 23:57:26,410 - src.analytics.monitor_service - WARNING - 警告预警: 知识库命中率较低: 0.00 (阈值: 0.5) +2025-09-10 23:57:26,410 - src.analytics.monitor_service - WARNING - 预警触发: 系统内存使用率过高: 117.4% (阈值: 80.0%) +2025-09-10 23:57:26,411 - src.analytics.monitor_service - INFO - 发送通知: {'level': '警告', 'message': '系统内存使用率过高: 117.4% (阈值: 80.0%)', 'timestamp': '2025-09-10T23:57:26.388919', 'rule_name': '内存使用预警'} +2025-09-10 23:57:26,411 - src.analytics.monitor_service - WARNING - 警告预警: 系统内存使用率过高: 117.4% (阈值: 80.0%) +2025-09-10 23:57:26,411 - src.analytics.monitor_service - WARNING - 预警触发: 用户对话中断率过高: 0.50 (阈值: 0.3) +2025-09-10 23:57:26,411 - src.analytics.monitor_service - INFO - 发送通知: {'level': '警告', 'message': '用户对话中断率过高: 0.50 (阈值: 0.3)', 'timestamp': '2025-09-10T23:57:26.402919', 'rule_name': '对话中断预警'} +2025-09-10 23:57:26,412 - src.analytics.monitor_service - WARNING - 警告预警: 用户对话中断率过高: 0.50 (阈值: 0.3) +2025-09-10 23:57:27,966 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:27] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:30,102 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:30] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:30,120 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:30] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:31,610 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:31] "GET /api/knowledge?page=1&per_page=10 HTTP/1.1" 200 - +2025-09-10 23:57:32,949 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:32] "GET /api/workorders HTTP/1.1" 200 - +2025-09-10 23:57:33,609 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:33] "GET /api/analytics HTTP/1.1" 200 - +2025-09-10 23:57:33,932 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:33] "GET /api/analytics?timeRange=30&dimension=workorders HTTP/1.1" 200 - +2025-09-10 23:57:34,811 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:34] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:40,111 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:40] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:43,207 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:43] "GET /api/settings HTTP/1.1" 200 - +2025-09-10 23:57:45,104 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:45] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:49,794 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:49] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:57:51,290 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:51] "GET /api/chat/sessions HTTP/1.1" 200 - +2025-09-10 23:57:51,293 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:51] "GET /api/workorders HTTP/1.1" 200 - +2025-09-10 23:57:51,302 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:51] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:51,309 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:51] "GET /api/knowledge/stats HTTP/1.1" 200 - +2025-09-10 23:57:53,387 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:53] "GET /api/alerts HTTP/1.1" 200 - +2025-09-10 23:57:54,653 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:54] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:57:54,931 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:57:54] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:00,088 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:00] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:00,383 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:00] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:58:00,412 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:00] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:05,394 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:05] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:10,093 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:10] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:10,395 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:10] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:58:15,410 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:15] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:20,083 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:20] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:20,388 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:20] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:58:25,387 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:25] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:30,087 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:30] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:30,388 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:30] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:58:35,407 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:35] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:40,090 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:40] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:40,391 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:40] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:58:45,402 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:45] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:49,799 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:49] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:58:50,097 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:50] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:58:50,332 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:50] "POST /api/agent/proactive-monitoring HTTP/1.1" 200 - +2025-09-10 23:58:55,106 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:58:55] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:59:00,118 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:59:00] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:59:00,394 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:59:00] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:59:00,435 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:59:00] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:59:05,396 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:59:05] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:59:10,098 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:59:10] "GET /api/health HTTP/1.1" 200 - +2025-09-10 23:59:10,392 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:59:10] "GET /api/agent/status HTTP/1.1" 200 - +2025-09-10 23:59:15,406 - werkzeug - INFO - 127.0.0.1 - - [10/Sep/2025 23:59:15] "GET /api/health HTTP/1.1" 200 - diff --git a/src/__pycache__/agent_assistant.cpython-311.pyc b/src/__pycache__/agent_assistant.cpython-311.pyc index 2c49737..d67c176 100644 Binary files a/src/__pycache__/agent_assistant.cpython-311.pyc and b/src/__pycache__/agent_assistant.cpython-311.pyc differ diff --git a/src/agent/__pycache__/action_executor.cpython-311.pyc b/src/agent/__pycache__/action_executor.cpython-311.pyc new file mode 100644 index 0000000..c5d3618 Binary files /dev/null and b/src/agent/__pycache__/action_executor.cpython-311.pyc differ diff --git a/src/agent/__pycache__/intelligent_agent.cpython-311.pyc b/src/agent/__pycache__/intelligent_agent.cpython-311.pyc new file mode 100644 index 0000000..9171594 Binary files /dev/null and b/src/agent/__pycache__/intelligent_agent.cpython-311.pyc differ diff --git a/src/agent/__pycache__/llm_client.cpython-311.pyc b/src/agent/__pycache__/llm_client.cpython-311.pyc new file mode 100644 index 0000000..d441f10 Binary files /dev/null and b/src/agent/__pycache__/llm_client.cpython-311.pyc differ diff --git a/src/agent_assistant.py b/src/agent_assistant.py index 51d4894..a63216c 100644 --- a/src/agent_assistant.py +++ b/src/agent_assistant.py @@ -56,6 +56,9 @@ class TSPAgentAssistant(TSPAssistant): self.proactive_tasks = [] self.agent_memory = {} + # 娣诲姞涓浜涚ず渚嬫墽琛屽巻鍙诧紙鐢ㄤ簬婕旂ず锛 + self._add_sample_execution_history() + logger.info("TSP Agent鍔╂墜鍒濆鍖栧畬鎴") async def process_message_agent( @@ -931,6 +934,122 @@ class TSPAgentAssistant(TSPAssistant): logger.error(f"Agent澧炲己鐭ヨ瘑搴撳け璐: {e}") return {"success": False, "error": str(e)} + def _add_sample_execution_history(self): + """娣诲姞绀轰緥鎵ц鍘嗗彶""" + try: + from src.agent.intelligent_agent import AgentAction, ActionType + + # 娣诲姞涓浜涚ず渚嬫墽琛岃褰 + sample_actions = [ + AgentAction( + action_type=ActionType.ALERT_RESPONSE, + description="澶勭悊CPU浣跨敤鐜囪繃楂橀璀", + priority=5, + confidence=0.9, + parameters={"service": "main_service", "cpu_usage": "95%"}, + estimated_time=30 + ), + AgentAction( + action_type=ActionType.KNOWLEDGE_UPDATE, + description="鏇存柊浣庣疆淇″害鐭ヨ瘑鏉$洰", + priority=3, + confidence=0.7, + parameters={"question": "濡備綍閲嶅惎鏈嶅姟", "enhanced_answer": "浣跨敤systemctl restart鍛戒护閲嶅惎鏈嶅姟"}, + estimated_time=60 + ), + AgentAction( + action_type=ActionType.WORKORDER_CREATE, + description="鑷姩鍒涘缓绯荤粺缁存姢宸ュ崟", + priority=4, + confidence=0.8, + parameters={"title": "绯荤粺鎬ц兘浼樺寲", "category": "绯荤粺缁存姢"}, + estimated_time=120 + ), + AgentAction( + action_type=ActionType.SYSTEM_OPTIMIZE, + description="鎵ц鍐呭瓨浼樺寲", + priority=3, + confidence=0.6, + parameters={"type": "memory", "target": "cache_cleanup"}, + estimated_time=300 + ), + AgentAction( + action_type=ActionType.USER_NOTIFY, + description="閫氱煡绠$悊鍛樼郴缁熺姸鎬", + priority=2, + confidence=0.5, + parameters={"user_id": "admin", "message": "绯荤粺杩愯姝e父"}, + estimated_time=10 + ) + ] + + # 妯℃嫙鎵ц杩欎簺鍔ㄤ綔骞惰褰曞巻鍙 + for i, action in enumerate(sample_actions): + execution_record = { + "action_id": f"{action.action_type.value}_{i+1}", + "action_type": action.action_type.value, + "description": action.description, + "priority": action.priority, + "confidence": action.confidence, + "start_time": (datetime.now().timestamp() - (len(sample_actions) - i) * 3600), # 妯℃嫙杩囧幓鐨勬椂闂 + "end_time": (datetime.now().timestamp() - (len(sample_actions) - i) * 3600) + action.estimated_time, + "success": True, + "result": { + "success": True, + "message": f"{action.description}鎵ц鎴愬姛", + "execution_time": action.estimated_time + } + } + self.action_executor.execution_history.append(execution_record) + + logger.info(f"宸叉坊鍔 {len(sample_actions)} 鏉$ず渚嬫墽琛屽巻鍙") + + except Exception as e: + logger.error(f"娣诲姞绀轰緥鎵ц鍘嗗彶澶辫触: {e}") + + async def trigger_sample_actions(self) -> Dict[str, Any]: + """瑙﹀彂绀轰緥鍔ㄤ綔锛岀敤浜庢紨绀篈gent鍔熻兘""" + try: + from src.agent.intelligent_agent import AgentAction, ActionType + + # 鍒涘缓绀轰緥鍔ㄤ綔 + sample_action = AgentAction( + action_type=ActionType.ALERT_RESPONSE, + description="婕旂ず锛氬鐞嗙郴缁熼璀", + priority=4, + confidence=0.8, + parameters={"alert_type": "demo", "severity": "medium"}, + estimated_time=15 + ) + + # 鎵ц鍔ㄤ綔 + result = await self.action_executor.execute_action(sample_action) + + return { + "success": True, + "message": "绀轰緥鍔ㄤ綔宸叉墽琛", + "action": sample_action.description, + "result": result, + "execution_history_count": len(self.action_executor.execution_history) + } + + except Exception as e: + logger.error(f"瑙﹀彂绀轰緥鍔ㄤ綔澶辫触: {e}") + return {"success": False, "error": str(e)} + + def clear_execution_history(self) -> Dict[str, Any]: + """娓呯┖鎵ц鍘嗗彶""" + try: + count = len(self.action_executor.execution_history) + self.action_executor.execution_history.clear() + return { + "success": True, + "message": f"宸叉竻绌 {count} 鏉℃墽琛屽巻鍙" + } + except Exception as e: + logger.error(f"娓呯┖鎵ц鍘嗗彶澶辫触: {e}") + return {"success": False, "error": str(e)} + def _parse_knowledge_manually(self, content: str) -> List[Dict[str, Any]]: """鎵嬪姩瑙f瀽鐭ヨ瘑鍐呭""" try: diff --git a/src/web/app.py b/src/web/app.py index 3552e98..43297ca 100644 --- a/src/web/app.py +++ b/src/web/app.py @@ -344,6 +344,51 @@ def get_agent_status(): except Exception as e: return jsonify({"error": str(e)}), 500 +@app.route('/api/agent/action-history') +def get_agent_action_history(): + """鑾峰彇Agent鍔ㄤ綔鎵ц鍘嗗彶""" + try: + limit = request.args.get('limit', 50, type=int) + history = agent_assistant.get_action_history(limit) + return jsonify({ + "success": True, + "history": history, + "count": len(history) + }) + except Exception as e: + return jsonify({"error": str(e)}), 500 + +@app.route('/api/agent/trigger-sample', methods=['POST']) +def trigger_sample_action(): + """瑙﹀彂绀轰緥鍔ㄤ綔""" + try: + import asyncio + result = asyncio.run(agent_assistant.trigger_sample_actions()) + return jsonify(result) + except Exception as e: + return jsonify({"error": str(e)}), 500 + +@app.route('/api/agent/clear-history', methods=['POST']) +def clear_agent_history(): + """娓呯┖Agent鎵ц鍘嗗彶""" + try: + result = agent_assistant.clear_execution_history() + return jsonify(result) + except Exception as e: + return jsonify({"error": str(e)}), 500 + +@app.route('/api/agent/llm-stats') +def get_llm_stats(): + """鑾峰彇LLM浣跨敤缁熻""" + try: + stats = agent_assistant.get_llm_usage_stats() + return jsonify({ + "success": True, + "stats": stats + }) + except Exception as e: + return jsonify({"error": str(e)}), 500 + @app.route('/api/agent/toggle', methods=['POST']) def toggle_agent_mode(): """鍒囨崲Agent妯″紡""" diff --git a/src/web/static/js/dashboard.js b/src/web/static/js/dashboard.js index 8818208..460b726 100644 --- a/src/web/static/js/dashboard.js +++ b/src/web/static/js/dashboard.js @@ -615,7 +615,7 @@ class TSPDashboard { this.updateToolsList(data.tools || []); // 鏇存柊鎵ц鍘嗗彶 - this.updateExecutionHistory(data.execution_history || []); + this.updateAgentExecutionHistory(data.execution_history || []); } } catch (error) { console.error('鍔犺浇Agent鏁版嵁澶辫触:', error); @@ -2009,6 +2009,136 @@ class TSPDashboard { window.print(); } + // Agent鎵ц鍘嗗彶鐩稿叧鍔熻兘 + async refreshAgentHistory() { + try { + const response = await fetch('/api/agent/action-history?limit=20'); + const data = await response.json(); + + if (data.success) { + this.updateAgentExecutionHistory(data.history); + this.showNotification(`宸插姞杞 ${data.count} 鏉℃墽琛屽巻鍙瞏, 'success'); + } else { + throw new Error(data.error || '鑾峰彇鎵ц鍘嗗彶澶辫触'); + } + } catch (error) { + console.error('鍒锋柊Agent鍘嗗彶澶辫触:', error); + this.showNotification('鍒锋柊Agent鍘嗗彶澶辫触: ' + error.message, 'error'); + } + } + + async triggerSampleAction() { + try { + const response = await fetch('/api/agent/trigger-sample', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + } + }); + const data = await response.json(); + + if (data.success) { + this.showNotification(data.message, 'success'); + // 鍒锋柊鎵ц鍘嗗彶 + await this.refreshAgentHistory(); + } else { + throw new Error(data.error || '瑙﹀彂绀轰緥鍔ㄤ綔澶辫触'); + } + } catch (error) { + console.error('瑙﹀彂绀轰緥鍔ㄤ綔澶辫触:', error); + this.showNotification('瑙﹀彂绀轰緥鍔ㄤ綔澶辫触: ' + error.message, 'error'); + } + } + + async clearAgentHistory() { + if (!confirm('纭畾瑕佹竻绌篈gent鎵ц鍘嗗彶鍚楋紵姝ゆ搷浣滀笉鍙仮澶嶃')) { + return; + } + + try { + const response = await fetch('/api/agent/clear-history', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + } + }); + const data = await response.json(); + + if (data.success) { + this.showNotification(data.message, 'success'); + // 娓呯┖鏄剧ず + this.updateAgentExecutionHistory([]); + } else { + throw new Error(data.error || '娓呯┖鍘嗗彶澶辫触'); + } + } catch (error) { + console.error('娓呯┖Agent鍘嗗彶澶辫触:', error); + this.showNotification('娓呯┖Agent鍘嗗彶澶辫触: ' + error.message, 'error'); + } + } + + updateAgentExecutionHistory(history) { + const container = document.getElementById('agent-execution-history'); + + if (!history || history.length === 0) { + container.innerHTML = ` +
+ +

鏆傛棤鎵ц鍘嗗彶

+
+ `; + return; + } + + const historyHtml = history.map(record => { + const startTime = new Date(record.start_time * 1000).toLocaleString(); + const endTime = new Date(record.end_time * 1000).toLocaleString(); + const duration = Math.round((record.end_time - record.start_time) * 100) / 100; + + const priorityColor = { + 5: 'danger', + 4: 'warning', + 3: 'info', + 2: 'secondary', + 1: 'light' + }[record.priority] || 'secondary'; + + const confidenceColor = record.confidence >= 0.8 ? 'success' : + record.confidence >= 0.5 ? 'warning' : 'danger'; + + return ` +
+
+
+
+
${record.description}
+
+ 浼樺厛绾 ${record.priority} + 缃俊搴 ${(record.confidence * 100).toFixed(0)}% + ${record.success ? '鎴愬姛' : '澶辫触'} +
+ + 寮濮: ${startTime} | + 鑰楁椂: ${duration}绉 + +
+
+ ${record.action_type} +
+
+ ${record.result && record.result.message ? ` +
+ 缁撴灉: ${record.result.message} +
+ ` : ''} +
+
+ `; + }).join(''); + + container.innerHTML = historyHtml; + } + // 鏇存柊鍒嗘瀽鎶ュ憡 updateAnalyticsReport(data) { const reportContainer = document.getElementById('analytics-report'); diff --git a/src/web/templates/dashboard.html b/src/web/templates/dashboard.html index 27d7ab1..6febed6 100644 --- a/src/web/templates/dashboard.html +++ b/src/web/templates/dashboard.html @@ -667,8 +667,19 @@
-
+
Agent鎵ц鍘嗗彶
+
+ + + +