From 19bccc194121907efab1add302c705c3db4294e6 Mon Sep 17 00:00:00 2001 From: root <953994191@qq.com> Date: Thu, 7 May 2026 03:06:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=20graph=5Fupdate=20=E4=BA=8B=E4=BB=B6=E9=81=BF=E5=85=8D=20JSON?= =?UTF-8?q?=20=E5=BA=8F=E5=88=97=E5=8C=96=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/agent/agent_service.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/backend/app/agent/agent_service.py b/backend/app/agent/agent_service.py index 59c9bcf..dc03e74 100644 --- a/backend/app/agent/agent_service.py +++ b/backend/app/agent/agent_service.py @@ -138,23 +138,21 @@ class AIAgentService: set_stream_queue(queue) # 设置上下文变量 async def run_graph(): - """后台任务:运行 graph,只获取 updates,不要用 stream_mode="messages" 避免重复 token!""" + """后台任务:运行 graph,流式事件都从 agent 节点内部发送!""" try: info(f"📡 开始调用 graph.astream()...") # 注意:只用 stream_mode=["updates"],不要 "messages"!避免重复 token! - async for chunk in self.graph.astream( + async for _ in self.graph.astream( input_state, config=config, stream_mode=["updates"], version="v2", subgraphs=True ): - # 可以处理一些状态更新事件,如 final_result 等 - await queue.put({ - "type": "graph_update", - "data": chunk, - }) + # 流式事件都从 agent.py 节点内部通过队列发送了 + # 这里不需要再发送任何事件 + pass except Exception as e: error(f"❌ 执行图时出错: {e}") import traceback