mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-06-29 11:41:52 +08:00
fix: disable notification history saving for agent messages
This commit is contained in:
@@ -1604,6 +1604,7 @@ class MoviePilotAgent:
|
||||
original_chat_id=self.original_chat_id,
|
||||
title=title,
|
||||
text=message,
|
||||
save_history=False,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -536,6 +536,7 @@ class StreamingHandler:
|
||||
original_chat_id=self._original_chat_id,
|
||||
title=self._title,
|
||||
text=current_text,
|
||||
save_history=False,
|
||||
),
|
||||
)
|
||||
if response and response.success and response.message_id:
|
||||
@@ -581,6 +582,7 @@ class StreamingHandler:
|
||||
original_chat_id=self._original_chat_id,
|
||||
title=self._title,
|
||||
text=current_text,
|
||||
save_history=False,
|
||||
),
|
||||
)
|
||||
if response and response.success and response.message_id:
|
||||
|
||||
@@ -649,5 +649,6 @@ class MoviePilotTool(BaseTool, metaclass=ABCMeta):
|
||||
title=title,
|
||||
text=message,
|
||||
image=image,
|
||||
save_history=False,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -105,6 +105,7 @@ class SendLocalFileTool(MoviePilotTool):
|
||||
text=message,
|
||||
file_path=str(resolved_path),
|
||||
file_name=file_name or resolved_path.name,
|
||||
save_history=False,
|
||||
)
|
||||
)
|
||||
return "本地附件已发送"
|
||||
|
||||
@@ -100,6 +100,7 @@ class SendMessageTool(MoviePilotTool):
|
||||
title=title,
|
||||
text=text,
|
||||
image=image_url,
|
||||
save_history=False,
|
||||
)
|
||||
)
|
||||
self._agent_context["user_reply_sent"] = True
|
||||
|
||||
@@ -96,6 +96,7 @@ class SendVoiceMessageTool(MoviePilotTool):
|
||||
if voice_path and settings.AUDIO_OUTPUT_INCLUDE_TEXT
|
||||
else None
|
||||
),
|
||||
save_history=False,
|
||||
)
|
||||
)
|
||||
self._agent_context["user_reply_sent"] = True
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import asyncio
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from app.agent import MoviePilotAgent
|
||||
from app.agent.tools.impl.ask_user_choice import (
|
||||
AskUserChoiceTool,
|
||||
UserChoiceOptionInput,
|
||||
)
|
||||
from app.agent.tools.impl.send_message import SendMessageTool
|
||||
from app.chain.message import MessageChain
|
||||
from app.core.config import settings
|
||||
from app.db import SessionFactory
|
||||
from app.db.message_oper import MessageOper
|
||||
from app.db.models.message import Message
|
||||
from app.helper.interaction import AgentInteractionOption, agent_interaction_manager, media_interaction_manager
|
||||
from app.schemas.types import MessageChannel
|
||||
from app.schemas.types import MessageChannel, NotificationType
|
||||
|
||||
|
||||
def _clear_messages() -> None:
|
||||
@@ -120,6 +122,49 @@ def test_ask_user_choice_message_is_not_recorded_to_message_history():
|
||||
async_send_message.assert_awaited_once()
|
||||
|
||||
|
||||
def test_agent_final_reply_disables_notification_history():
|
||||
"""Agent 最终回复发往渠道时不保存通知历史。"""
|
||||
agent = MoviePilotAgent(
|
||||
session_id="session-agent-reply",
|
||||
user_id="10001",
|
||||
channel=MessageChannel.Telegram.value,
|
||||
source="telegram-test",
|
||||
username="tester",
|
||||
)
|
||||
|
||||
with patch(
|
||||
"app.agent.AgentChain.async_post_message",
|
||||
new_callable=AsyncMock,
|
||||
) as async_post_message:
|
||||
asyncio.run(agent.send_agent_message("已完成处理"))
|
||||
|
||||
notification = async_post_message.await_args.args[0]
|
||||
assert notification.mtype == NotificationType.Agent
|
||||
assert notification.save_history is False
|
||||
|
||||
|
||||
def test_send_message_tool_disables_notification_history():
|
||||
"""Agent 主动发消息工具发送的通知不保存通知历史。"""
|
||||
tool = SendMessageTool(session_id="session-send-message", user_id="10001")
|
||||
tool.set_message_attr(
|
||||
channel=MessageChannel.Telegram.value,
|
||||
source="telegram-test",
|
||||
username="tester",
|
||||
)
|
||||
tool.set_agent_context(agent_context={})
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.base.ToolChain.async_post_message",
|
||||
new_callable=AsyncMock,
|
||||
) as async_post_message:
|
||||
result = asyncio.run(tool.run(message="处理结果", title="MoviePilot助手"))
|
||||
|
||||
notification = async_post_message.await_args.args[0]
|
||||
assert result == "消息已发送"
|
||||
assert notification.text == "处理结果"
|
||||
assert notification.save_history is False
|
||||
|
||||
|
||||
def test_agent_choice_callback_is_not_recorded_to_message_history():
|
||||
"""Agent 按钮选择回传不登记到数据库或实时消息队列。"""
|
||||
chain = MessageChain()
|
||||
|
||||
Reference in New Issue
Block a user