From aafc4b3a39413499b2299c92bd2ba31b7c5a4767 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 9 Apr 2026 23:19:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(agent):=20start=5Fstreaming=20=E5=A7=8B?= =?UTF-8?q?=E7=BB=88=E6=A0=87=E8=AE=B0=E6=B5=81=E5=BC=8F=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=20buffer=20=E6=94=B6=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 渠道不支持消息编辑时,仍需标记 streaming_enabled 为 True, 以便啰嗦模式下工具调用时能通过 is_streaming 进入流式分支 发送 agent 中间文字和工具消息。只是不启动定时刷新任务。 --- app/agent/callback/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/agent/callback/__init__.py b/app/agent/callback/__init__.py index cba692e9..ce7d04e0 100644 --- a/app/agent/callback/__init__.py +++ b/app/agent/callback/__init__.py @@ -120,7 +120,9 @@ class StreamingHandler: title: str = "", ): """ - 启动流式输出。检查渠道是否支持消息编辑,如果支持则启动定时刷新任务。 + 启动流式输出。 + 始终标记为流式状态(用于 buffer 收集 token), + 但只有渠道支持消息编辑时才启动定时刷新任务(实时推送给用户)。 :param channel: 消息渠道 :param source: 消息来源 :param user_id: 用户ID @@ -133,16 +135,16 @@ class StreamingHandler: self._username = username self._title = title - # 检查渠道是否支持消息编辑 - if not self._can_stream(): - logger.debug(f"渠道 {channel} 不支持消息编辑,不启用流式输出") - return - self._streaming_enabled = True self._sent_text = "" self._message_response = None self._msg_start_offset = 0 + # 检查渠道是否支持消息编辑,不支持则仅收集 token 到 buffer,不实时推送 + if not self._can_stream(): + logger.debug(f"渠道 {channel} 不支持消息编辑,仅启用 buffer 收集模式") + return + # 从渠道能力中获取单条消息最大长度 try: channel_enum = MessageChannel(self._channel)