From 5f53f80d1f9345c4f95f7842202e91cc7448a44c Mon Sep 17 00:00:00 2001 From: root <953994191@qq.com> Date: Sat, 2 May 2026 00:59:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=BB=E5=BA=95=E7=BB=9F=E4=B8=80:=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=85=BC=E5=AE=B9=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E6=8E=A5=E5=8F=97=20MainGraphState?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/utils/logging.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/backend/app/utils/logging.py b/backend/app/utils/logging.py index c3137fc..7802895 100644 --- a/backend/app/utils/logging.py +++ b/backend/app/utils/logging.py @@ -5,37 +5,27 @@ LangGraph 节点日志工具模块 from app.config import ENABLE_GRAPH_TRACE from app.logger import debug, info +from app.main_graph.state import MainGraphState -def log_state_change(node_name: str, state, prefix: str = "进入"): +def log_state_change(node_name: str, state: MainGraphState, prefix: str = "进入"): """ 记录状态变化日志 - + Args: node_name: 节点名称 - state: 当前状态(兼容 dict 和 dataclass) + state: 当前状态 prefix: 日志前缀("进入" 或 "离开") """ from app.logger import info - - # 获取 messages - messages = [] - if isinstance(state, dict): - messages = state.get("messages", []) - else: - messages = getattr(state, "messages", []) - + + messages = state.messages msg_count = len(messages) last_msg = messages[-1] if messages else None last_info = "" if last_msg: - # 兼容 dict 和对象两种格式 - if isinstance(last_msg, dict): - content_preview = str(last_msg.get("content", ""))[:10].replace("\n", " ") - msg_type = last_msg.get("type", "unknown") - else: - content_preview = str(last_msg.content)[:10].replace("\n", " ") - msg_type = getattr(last_msg, 'type', 'unknown') + content_preview = str(last_msg.content)[:10].replace("\n", " ") + msg_type = getattr(last_msg, 'type', 'unknown') last_info = f"{msg_type.upper()}: {content_preview}" info(f"🔄 [{node_name}] {prefix} | 消息数:{msg_count} | 最后一条:{last_info}")