diff --git a/app/agent/tools/base.py b/app/agent/tools/base.py index 155a43c8..ac95ce66 100644 --- a/app/agent/tools/base.py +++ b/app/agent/tools/base.py @@ -157,8 +157,8 @@ class MoviePilotTool(BaseTool, metaclass=ABCMeta): if explanation: tool_message = explanation - # 发送工具执行过程消息 - if self._stream_handler and self._stream_handler.is_streaming: + # 发送工具执行过程消息(流式传输且非最后终结工具时) + if self._stream_handler and self._stream_handler.is_streaming and not self.return_direct: if settings.AI_AGENT_VERBOSE: if self._stream_handler.is_auto_flushing: # 渠道支持编辑:工具消息追加到 buffer,由定时刷新推送 diff --git a/app/agent/tools/impl/send_voice_message.py b/app/agent/tools/impl/send_voice_message.py index a07ee8ec..b4f27d15 100644 --- a/app/agent/tools/impl/send_voice_message.py +++ b/app/agent/tools/impl/send_voice_message.py @@ -30,6 +30,7 @@ class SendVoiceMessageTool(MoviePilotTool): name: str = "send_voice_message" sends_message: bool = True + return_direct: bool = True description: str = ( "Send a voice reply to the current user. Use this only when the user explicitly asks for " "a voice reply or when spoken playback is clearly better than plain text. On channels " diff --git a/tests/test_agent_tool_streaming.py b/tests/test_agent_tool_streaming.py index 52021815..db57df2f 100644 --- a/tests/test_agent_tool_streaming.py +++ b/tests/test_agent_tool_streaming.py @@ -406,7 +406,9 @@ class TestAgentToolStreaming(unittest.TestCase): """运行指定渠道的语音发送工具。""" tool = SendVoiceMessageTool(session_id="session-1", user_id="10001") tool.set_message_attr( - channel=channel.value, source=f"{channel.name.lower()}-main", username="tester" + channel=channel.value, + source=f"{channel.name.lower()}-main", + username="tester", ) with ( @@ -429,7 +431,9 @@ class TestAgentToolStreaming(unittest.TestCase): return result, synthesize_speech, async_post_message for channel in (MessageChannel.Telegram, MessageChannel.Feishu): - result, synthesize_speech, async_post_message = asyncio.run(_run(channel)) + result, synthesize_speech, async_post_message = asyncio.run( + _run(channel) + ) notification = async_post_message.await_args.args[0] self.assertEqual(result, "语音回复已发送") @@ -437,6 +441,7 @@ class TestAgentToolStreaming(unittest.TestCase): self.assertEqual(notification.channel, channel) self.assertEqual(notification.voice_path, "/tmp/reply.opus") self.assertEqual(notification.voice_caption, "你好") + self.assertTrue(SendVoiceMessageTool.return_direct) def test_send_voice_message_falls_back_for_unsupported_channels(self): """校验不支持语音输出的渠道继续回退为文字消息。"""