mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-07-17 10:42:17 +08:00
feat(agent): set return_direct for SendVoiceMessageTool to prevent streaming tool messages
This commit is contained in:
@@ -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,由定时刷新推送
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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):
|
||||
"""校验不支持语音输出的渠道继续回退为文字消息。"""
|
||||
|
||||
Reference in New Issue
Block a user