Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions astrbot/core/astr_main_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_astr_main_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading