修复:移除 graph_update 事件避免 JSON 序列化错误
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 6m24s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 6m24s
This commit is contained in:
@@ -138,23 +138,21 @@ class AIAgentService:
|
|||||||
set_stream_queue(queue) # 设置上下文变量
|
set_stream_queue(queue) # 设置上下文变量
|
||||||
|
|
||||||
async def run_graph():
|
async def run_graph():
|
||||||
"""后台任务:运行 graph,只获取 updates,不要用 stream_mode="messages" 避免重复 token!"""
|
"""后台任务:运行 graph,流式事件都从 agent 节点内部发送!"""
|
||||||
try:
|
try:
|
||||||
info(f"📡 开始调用 graph.astream()...")
|
info(f"📡 开始调用 graph.astream()...")
|
||||||
|
|
||||||
# 注意:只用 stream_mode=["updates"],不要 "messages"!避免重复 token!
|
# 注意:只用 stream_mode=["updates"],不要 "messages"!避免重复 token!
|
||||||
async for chunk in self.graph.astream(
|
async for _ in self.graph.astream(
|
||||||
input_state,
|
input_state,
|
||||||
config=config,
|
config=config,
|
||||||
stream_mode=["updates"],
|
stream_mode=["updates"],
|
||||||
version="v2",
|
version="v2",
|
||||||
subgraphs=True
|
subgraphs=True
|
||||||
):
|
):
|
||||||
# 可以处理一些状态更新事件,如 final_result 等
|
# 流式事件都从 agent.py 节点内部通过队列发送了
|
||||||
await queue.put({
|
# 这里不需要再发送任何事件
|
||||||
"type": "graph_update",
|
pass
|
||||||
"data": chunk,
|
|
||||||
})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(f"❌ 执行图时出错: {e}")
|
error(f"❌ 执行图时出错: {e}")
|
||||||
import traceback
|
import traceback
|
||||||
|
|||||||
Reference in New Issue
Block a user