From 7c385da415ed9cf2ed9bffbb1dc087eef8a2e14e Mon Sep 17 00:00:00 2001 From: rootkit Date: Thu, 4 Dec 2025 21:18:01 +0800 Subject: [PATCH] tmp --- .../L3_SOC_Analyst.md | 0 Lib/montior.py | 2 +- PLAYBOOKS/Alert_Analysis_Agent.py | 2 +- PLUGINS/SIRP/message_test.py | 147 ------------------ 4 files changed, 2 insertions(+), 149 deletions(-) rename DATA/{Alert_Suggestion_Gen_By_LLM => Alert_Analysis_Agent}/L3_SOC_Analyst.md (100%) delete mode 100644 PLUGINS/SIRP/message_test.py diff --git a/DATA/Alert_Suggestion_Gen_By_LLM/L3_SOC_Analyst.md b/DATA/Alert_Analysis_Agent/L3_SOC_Analyst.md similarity index 100% rename from DATA/Alert_Suggestion_Gen_By_LLM/L3_SOC_Analyst.md rename to DATA/Alert_Analysis_Agent/L3_SOC_Analyst.md diff --git a/Lib/montior.py b/Lib/montior.py index 07d415b..760f0c0 100644 --- a/Lib/montior.py +++ b/Lib/montior.py @@ -32,7 +32,7 @@ class MainMonitor(object): logger.info("启动后台服务") # add api user - logger.info("写入ASF_TOKEN到缓存") + logger.info("写入ASP_TOKEN到缓存") api_usr = User() api_usr.username = "api_token" api_usr.is_active = True diff --git a/PLAYBOOKS/Alert_Analysis_Agent.py b/PLAYBOOKS/Alert_Analysis_Agent.py index 8b87387..16efe12 100644 --- a/PLAYBOOKS/Alert_Analysis_Agent.py +++ b/PLAYBOOKS/Alert_Analysis_Agent.py @@ -119,7 +119,7 @@ class Playbook(LanggraphPlaybook): if __name__ == "__main__": - params_debug = {'rowid': '113d3844-792d-47f9-b4f5-29e6f9b3c776', 'worksheet': 'alert'} + params_debug = {'rowid': '13782e0a-2423-4fc3-9b16-7f2eb15ae83f', 'worksheet': 'alert'} module = Playbook() module._params = params_debug module.run() diff --git a/PLUGINS/SIRP/message_test.py b/PLUGINS/SIRP/message_test.py deleted file mode 100644 index b329e0b..0000000 --- a/PLUGINS/SIRP/message_test.py +++ /dev/null @@ -1,147 +0,0 @@ -import json -from typing import List, Dict, Any - -from PLUGINS.SIRP.sirpapi import PlaybookMessage - -# 尝试导入 langchain_core,如果未安装则报错提示 -try: - from langchain_core.messages import ( - BaseMessage, - SystemMessage, - HumanMessage, - AIMessage, - ToolMessage - ) -except ImportError: - raise ImportError("请先安装 langchain-core: pip install langchain-core") - - -def parse_langchain_messages(msg: BaseMessage, playbook_rowid=None, node=None) -> List[Dict[str, Any]]: - """ - 将 LangChain 的消息对象列表解析为纯字典列表 (List[Dict])。 - 涵盖 System, Human, AI (含 tool_calls), ToolMessage。 - """ - - # 1. 处理 SystemMessage - if isinstance(msg, SystemMessage): - - fields = [ - {"id": "type", "value": "SystemMessage"}, - {"id": "node", "value": node}, - {"id": "playbook_rowid", "value": playbook_rowid}, - {"id": "content", "value": msg.content}, - {"id": "json", "value": None}, - ] - - - # 2. 处理 HumanMessage - elif isinstance(msg, HumanMessage): - - fields = [ - {"id": "type", "value": "HumanMessage"}, - {"id": "node", "value": node}, - {"id": "playbook_rowid", "value": playbook_rowid}, - {"id": "content", "value": msg.content}, - {"id": "json", "value": None}, - ] - - - # 3. 处理 AIMessage (包含普通回复和工具调用) - elif isinstance(msg, AIMessage): - # 检查是否有 tool_calls - if hasattr(msg, 'tool_calls') and msg.tool_calls: - fields = [ - {"id": "type", "value": "AIMessage"}, - {"id": "node", "value": node}, - {"id": "playbook_rowid", "value": playbook_rowid}, - {"id": "content", "value": msg.content}, - {"id": "json", "value": json.dumps(msg.tool_calls)}, - ] - else: - fields = [ - {"id": "type", "value": "AIMessage"}, - {"id": "node", "value": node}, - {"id": "playbook_rowid", "value": playbook_rowid}, - {"id": "content", "value": msg.content}, - {"id": "json", "value": None}, - ] - # 4. 处理 ToolMessage (工具执行的结果) - elif isinstance(msg, ToolMessage): - - try: - json_data = {"name": msg.name, "tool_call_id": msg.tool_call_id, "result": json.loads(msg.content)} - except json.decoder.JSONDecodeError: - json_data = {"name": msg.name, "tool_call_id": msg.tool_call_id, "result": msg.content} - - fields = [ - {"id": "type", "value": "ToolMessage"}, - {"id": "node", "value": node}, - {"id": "playbook_rowid", "value": playbook_rowid}, - {"id": "json", "value": json.dumps(json_data)}, - ] - # 5. 处理其他未知类型 (兜底) - else: - message_dict = { - "role": "unknown", - "content": msg.content, - "type": msg.type - } - fields = [ - {"id": "role", "value": msg.type}, - {"id": "node", "value": node}, - {"id": "playbook_rowid", "value": playbook_rowid}, - {"id": "content", "value": msg.content}, - {"id": "json", "value": None}, - ] - row_id = PlaybookMessage.create(fields) - return row_id - - -# ========================================== -# 测试代码部分 -# ========================================== -if __name__ == "__main__": - print("-" * 30) - print("开始测试 LangChain Message 解析") - print("-" * 30) - - # 1. 模拟构建 LangChain 的消息列表 - # 场景:用户问天气 -> AI 决定调用工具 -> 工具返回结果 -> AI 总结 - - # 模拟 tool_call 数据 - dummy_tool_call_id = "call_12345xyz" - - test_messages = [ - # System Message - SystemMessage(content="你是一个有用的AI助手。"), - - # Human Message - HumanMessage(content="东京现在的天气怎么样?"), - - # AI Message (决定调用工具) - AIMessage( - content="", # 思维链内容可能为空 - tool_calls=[{ - "name": "get_current_weather", - "args": {"location": "Tokyo", "unit": "celsius"}, - "id": dummy_tool_call_id - }] - ), - - # Tool Message (工具返回的结果) - ToolMessage( - content=json.dumps({"temperature": 22, "description": "Sunny"}), - tool_call_id=dummy_tool_call_id, - name="get_current_weather" - ), - - # AI Message (最终回复) - AIMessage(content="东京现在天气晴朗,气温约为 22 摄氏度。") - ] - - # 2. 执行解析 - try: - for msg in test_messages: - results = parse_langchain_messages(msg) - except Exception as e: - print(f"\n❌ 测试失败: {e}")