mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-05-06 20:42:43 +08:00
refine agent subscription defaults and silent tool prompts
This commit is contained in:
29
tests/test_agent_add_subscribe_tool.py
Normal file
29
tests/test_agent_add_subscribe_tool.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import asyncio
|
||||
import unittest
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from app.agent.tools.impl.add_subscribe import AddSubscribeTool
|
||||
|
||||
|
||||
class TestAgentAddSubscribeTool(unittest.TestCase):
|
||||
def test_tv_subscription_without_season_reports_default_first_season(self):
|
||||
tool = AddSubscribeTool(session_id="session-1", user_id="10001")
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.add_subscribe.SubscribeChain.async_add",
|
||||
new=AsyncMock(return_value=(1, "")),
|
||||
):
|
||||
result = asyncio.run(
|
||||
tool.run(
|
||||
title="Breaking Bad",
|
||||
year="2008",
|
||||
media_type="tv",
|
||||
)
|
||||
)
|
||||
|
||||
self.assertIn("第1季", result)
|
||||
self.assertIn("默认按第一季订阅", result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,7 +1,9 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.agent.middleware.memory import MEMORY_ONBOARDING_PROMPT
|
||||
from app.agent.prompt import prompt_manager
|
||||
from app.core.config import settings
|
||||
|
||||
|
||||
class TestAgentPromptStyle(unittest.TestCase):
|
||||
@@ -12,6 +14,44 @@ class TestAgentPromptStyle(unittest.TestCase):
|
||||
self.assertIn("Do NOT flatter the user", prompt)
|
||||
self.assertIn("NO praise, emotional cushioning", prompt)
|
||||
|
||||
def test_agent_prompt_defines_tv_subscription_default_season_rule(self):
|
||||
prompt = prompt_manager.get_agent_prompt()
|
||||
|
||||
self.assertIn(
|
||||
"omitting `season` means subscribe to season 1 only",
|
||||
prompt,
|
||||
)
|
||||
self.assertIn(
|
||||
"call `add_subscribe` separately for each season",
|
||||
prompt,
|
||||
)
|
||||
|
||||
def test_non_verbose_prompt_requires_silence_until_all_tools_finish(self):
|
||||
with patch.object(settings, "AI_AGENT_VERBOSE", False):
|
||||
prompt = prompt_manager.get_agent_prompt()
|
||||
|
||||
self.assertIn(
|
||||
"STRICTLY ENFORCED WHEN VERBOSE MODE IS OFF",
|
||||
prompt,
|
||||
)
|
||||
self.assertIn(
|
||||
"DO NOT output any conversational text, explanations, progress updates, or acknowledgements before the first tool call or between tool calls",
|
||||
prompt,
|
||||
)
|
||||
self.assertIn(
|
||||
"Only then may you send one final user-facing reply",
|
||||
prompt,
|
||||
)
|
||||
|
||||
def test_verbose_prompt_does_not_inject_silence_until_tools_finish_rule(self):
|
||||
with patch.object(settings, "AI_AGENT_VERBOSE", True):
|
||||
prompt = prompt_manager.get_agent_prompt()
|
||||
|
||||
self.assertNotIn(
|
||||
"STRICTLY ENFORCED WHEN VERBOSE MODE IS OFF",
|
||||
prompt,
|
||||
)
|
||||
|
||||
def test_memory_onboarding_does_not_force_warm_intro(self):
|
||||
self.assertIn("Do NOT interrupt the current task", MEMORY_ONBOARDING_PROMPT)
|
||||
self.assertIn("Do NOT proactively greet warmly", MEMORY_ONBOARDING_PROMPT)
|
||||
|
||||
Reference in New Issue
Block a user