彻底统一: 移除兼容代码,只接受 MainGraphState
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m40s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m40s
This commit is contained in:
@@ -5,35 +5,25 @@ 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 和对象两种格式
|
|
||||||
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", " ")
|
content_preview = str(last_msg.content)[:10].replace("\n", " ")
|
||||||
msg_type = getattr(last_msg, 'type', 'unknown')
|
msg_type = getattr(last_msg, 'type', 'unknown')
|
||||||
last_info = f"{msg_type.upper()}: {content_preview}"
|
last_info = f"{msg_type.upper()}: {content_preview}"
|
||||||
|
|||||||
Reference in New Issue
Block a user