mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-05-13 07:26:45 +00:00
fix(agent): 非流式模式下啰嗦模式仍需发送工具调用中间消息
啰嗦模式+渠道不支持编辑时,虽然 is_streaming 为 False, 但 astream 仍会将 token 写入 buffer,需要在工具调用时 取出 agent 文字与工具消息合并发送
This commit is contained in:
@@ -72,9 +72,20 @@ class MoviePilotTool(BaseTool, metaclass=ABCMeta):
|
||||
# 非VERBOSE,重置缓冲区从头更新,保持消息编辑能力
|
||||
self._stream_handler.reset()
|
||||
else:
|
||||
# 非流式模式(后台任务或渠道不支持消息编辑且啰嗦模式关闭)
|
||||
# 此时使用 ainvoke 执行,无流式 token 产出,不发送任何中间消息
|
||||
pass
|
||||
# 非流式模式(渠道不支持消息编辑,但可能通过 astream 产出了 token 到 buffer)
|
||||
if self._channel and settings.AI_AGENT_VERBOSE:
|
||||
# 啰嗦模式:取出 Agent 文字 + 工具消息合并发送
|
||||
agent_message = (
|
||||
await self._stream_handler.take() if self._stream_handler else ""
|
||||
)
|
||||
messages = []
|
||||
if agent_message:
|
||||
messages.append(agent_message)
|
||||
if tool_message:
|
||||
messages.append(f"⚙️ => {tool_message}")
|
||||
if messages:
|
||||
merged_message = "\n\n".join(messages)
|
||||
await self.send_tool_message(merged_message)
|
||||
|
||||
logger.debug(f"Executing tool {self.name} with args: {kwargs}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user