彻底统一: 移除兼容代码,只接受 MainGraphState
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m40s

This commit is contained in:
2026-05-02 00:59:25 +08:00
parent a3e2a5aea4
commit 5f53f80d1f

View File

@@ -5,37 +5,27 @@ LangGraph 节点日志工具模块
from app.config import ENABLE_GRAPH_TRACE from app.config import ENABLE_GRAPH_TRACE
from app.logger import debug, info 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: Args:
node_name: 节点名称 node_name: 节点名称
state: 当前状态(兼容 dict 和 dataclass state: 当前状态
prefix: 日志前缀("进入""离开" prefix: 日志前缀("进入""离开"
""" """
from app.logger import info from app.logger import info
# 获取 messages messages = state.messages
messages = []
if isinstance(state, dict):
messages = state.get("messages", [])
else:
messages = getattr(state, "messages", [])
msg_count = len(messages) msg_count = len(messages)
last_msg = messages[-1] if messages else None last_msg = messages[-1] if messages else None
last_info = "" last_info = ""
if last_msg: if last_msg:
# 兼容 dict 和对象两种格式 content_preview = str(last_msg.content)[:10].replace("\n", " ")
if isinstance(last_msg, dict): msg_type = getattr(last_msg, 'type', 'unknown')
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')
last_info = f"{msg_type.upper()}: {content_preview}" last_info = f"{msg_type.upper()}: {content_preview}"
info(f"🔄 [{node_name}] {prefix} | 消息数:{msg_count} | 最后一条:{last_info}") info(f"🔄 [{node_name}] {prefix} | 消息数:{msg_count} | 最后一条:{last_info}")