diff --git a/backend/app/agent/agent_service.py b/backend/app/agent/agent_service.py index f0ffae4..5b31f22 100644 --- a/backend/app/agent/agent_service.py +++ b/backend/app/agent/agent_service.py @@ -302,19 +302,32 @@ class AIAgentService: } elif chunk_type == "custom": - info(f"🎯 处理custom chunk: {chunk['data']}") + info(f"🎯 处理custom chunk, 完整数据: {repr(chunk)}") custom_data = chunk["data"] + info(f"🎯 custom_data 内容: {repr(custom_data)}") + info(f"🎯 custom_data 类型: {type(custom_data)}") # 关键修复:处理我们从 react_reason_node 发送的自定义推理事件 - if isinstance(custom_data, dict) and custom_data.get("type") == "react_reasoning": - info(f"[Agent Service] 收到自定义推理事件") - yield { - "type": "react_reasoning", - "step": custom_data.get("step", 1), - "action": custom_data.get("action", "unknown"), - "confidence": custom_data.get("confidence", 0), - "reasoning": custom_data.get("reasoning", "") - } + # LangGraph 的 adispatch_custom_event 发送的事件格式: + # chunk["data"] 是我们传的第二个参数(dict) + if isinstance(custom_data, dict): + # 检查是否是我们的推理事件 + if "action" in custom_data and "reasoning" in custom_data: + info(f"[Agent Service] 收到自定义推理事件: {custom_data}") + yield { + "type": "react_reasoning", + "step": custom_data.get("step", 1), + "action": custom_data.get("action", "unknown"), + "confidence": custom_data.get("confidence", 0), + "reasoning": custom_data.get("reasoning", "") + } + else: + # 处理其他自定义事件 + serialized_data = self._serialize_value(custom_data) + processed_event = { + "type": "custom", + "data": serialized_data + } else: # 处理其他自定义事件 serialized_data = self._serialize_value(custom_data)