feat(agent): set return_direct for SendVoiceMessageTool to prevent streaming tool messages

This commit is contained in:
jxxghp
2026-05-31 17:35:10 +08:00
parent a5c44a5097
commit 5d3c262e60
3 changed files with 10 additions and 4 deletions

View File

@@ -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由定时刷新推送

View File

@@ -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 "

View File

@@ -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):
"""校验不支持语音输出的渠道继续回退为文字消息。"""