diff --git a/astrbot/core/astr_main_agent.py b/astrbot/core/astr_main_agent.py index 16ebac7a8b..6ed2f4b80f 100644 --- a/astrbot/core/astr_main_agent.py +++ b/astrbot/core/astr_main_agent.py @@ -271,6 +271,8 @@ async def _apply_kb( config: MainAgentBuildConfig, ) -> None: if not config.kb_agentic_mode: + if event.get_platform_name() == "cron": + return if req.prompt is None or not req.prompt.strip(): return try: diff --git a/tests/unit/test_astr_main_agent.py b/tests/unit/test_astr_main_agent.py index 3723ec0d49..3956ed7801 100644 --- a/tests/unit/test_astr_main_agent.py +++ b/tests/unit/test_astr_main_agent.py @@ -391,6 +391,24 @@ async def test_apply_kb_without_agentic_mode(self, mock_event, mock_context): {"role": "user", "content": [{"type": "text", "text": "test question"}]} ] + @pytest.mark.asyncio + async def test_apply_kb_skips_cron_events(self, mock_event, mock_context): + """Test scheduled tasks do not inject KB results as user content.""" + module = ama + mock_event.get_platform_name.return_value = "cron" + req = ProviderRequest(prompt="scheduled task", system_prompt="System prompt") + config = module.MainAgentBuildConfig( + tool_call_timeout=60, kb_agentic_mode=False + ) + retrieve = AsyncMock(return_value="KB result") + + with patch("astrbot.core.astr_main_agent.retrieve_knowledge_base", retrieve): + await module._apply_kb(mock_event, req, mock_context, config) + + retrieve.assert_not_awaited() + assert req.system_prompt == "System prompt" + assert req.extra_user_content_parts == [] + @pytest.mark.asyncio async def test_apply_kb_with_agentic_mode(self, mock_event, mock_context): """Test applying knowledge base in agentic mode."""