From c5ea93b7544b830835438d1686587e964fe77540 Mon Sep 17 00:00:00 2001 From: root <953994191@qq.com> Date: Thu, 7 May 2026 01:58:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8A=8A=E5=AE=8C=E6=95=B4=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8B=86=E6=88=90=E5=8D=95=E4=B8=AA=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E6=B5=81=E5=BC=8F=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/agent/agent_service.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/backend/app/agent/agent_service.py b/backend/app/agent/agent_service.py index 6c1d2ca..2180909 100644 --- a/backend/app/agent/agent_service.py +++ b/backend/app/agent/agent_service.py @@ -189,12 +189,26 @@ class AIAgentService: } # 处理普通 token elif token_content: - yield { - "type": "llm_token", - "node": node_name, - "token": token_content, - "reasoning_token": reasoning_token - } + # 如果内容较长,拆成单个字符模拟流式效果 + if len(token_content) > 1: + import asyncio + for char in token_content: + yield { + "type": "llm_token", + "node": node_name, + "token": char, + "reasoning_token": reasoning_token + } + # 短暂暂停,模拟打字效果 + await asyncio.sleep(0.01) + else: + # 内容较短,直接发送 + yield { + "type": "llm_token", + "node": node_name, + "token": token_content, + "reasoning_token": reasoning_token + } # 返回更新后的 current_node yield {"type": "_update_state", "current_node": new_current_node}