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