添加调试日志,排查Task was destroyed问题
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 6m41s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 6m41s
This commit is contained in:
@@ -151,9 +151,13 @@ class AIAgentService:
|
||||
# ========================================
|
||||
|
||||
# ========== React 循环路径 ==========
|
||||
info(f"🚀 开始执行 React 图,模型: {model_name}")
|
||||
current_node = None
|
||||
tool_calls_in_progress = {}
|
||||
|
||||
try:
|
||||
info(f"📡 开始调用 graph.astream()...")
|
||||
chunk_count = 0
|
||||
async for chunk in graph.astream(
|
||||
input_state,
|
||||
config=config,
|
||||
@@ -161,12 +165,15 @@ class AIAgentService:
|
||||
version="v2",
|
||||
subgraphs=True
|
||||
):
|
||||
chunk_count += 1
|
||||
chunk_type = chunk["type"]
|
||||
info(f"📦 收到第 {chunk_count} 个chunk, type: {chunk_type}")
|
||||
processed_event = {}
|
||||
|
||||
if chunk_type == "messages":
|
||||
message_chunk, metadata = chunk["data"]
|
||||
node_name = metadata.get("langgraph_node", "unknown")
|
||||
info(f"📨 处理消息chunk, node: {node_name}")
|
||||
|
||||
# 检测节点变化,发送节点开始事件
|
||||
if node_name != current_node:
|
||||
@@ -223,6 +230,7 @@ class AIAgentService:
|
||||
}
|
||||
|
||||
elif chunk_type == "updates":
|
||||
info(f"🔄 处理updates chunk")
|
||||
updates_data = chunk["data"]
|
||||
serialized_data = self._serialize_value(updates_data)
|
||||
|
||||
@@ -260,6 +268,7 @@ class AIAgentService:
|
||||
}
|
||||
|
||||
elif chunk_type == "custom":
|
||||
info(f"🎯 处理custom chunk")
|
||||
serialized_data = self._serialize_value(chunk["data"])
|
||||
processed_event = {
|
||||
"type": "custom",
|
||||
@@ -269,6 +278,14 @@ class AIAgentService:
|
||||
if processed_event:
|
||||
yield processed_event
|
||||
|
||||
info(f"✅ graph.astream() 完成,共 {chunk_count} 个chunks")
|
||||
|
||||
except Exception as e:
|
||||
error(f"❌ 执行 React 图时出错: {e}")
|
||||
import traceback
|
||||
error(f"📋 堆栈: {traceback.format_exc()}")
|
||||
raise
|
||||
|
||||
# 发送结束事件
|
||||
if current_node:
|
||||
yield {
|
||||
|
||||
Reference in New Issue
Block a user