Skip to content

Commit c1cc74b

Browse files
catDforDGargantua
andauthored
fix: preserve fallback models for future tasks (#9054)
* fix: preserve fallback models for future tasks * chore: remove local test markdown ignore --------- Co-authored-by: Gargantua <22532097@zju.edu.cn>
1 parent a619988 commit c1cc74b

2 files changed

Lines changed: 69 additions & 3 deletions

File tree

astrbot/core/cron/manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,13 @@ async def _woke_main_agent(
416416
if cron_payload.get("origin", "tool") == "api":
417417
cron_event.role = "admin"
418418

419-
tool_call_timeout = cfg.get("provider_settings", {}).get(
420-
"tool_call_timeout", 120
421-
)
419+
provider_settings = cfg.get("provider_settings", {}) or {}
420+
tool_call_timeout = provider_settings.get("tool_call_timeout", 120)
422421
config = MainAgentBuildConfig(
423422
tool_call_timeout=tool_call_timeout,
424423
llm_safety_mode=False,
425424
streaming_response=False,
425+
provider_settings=provider_settings,
426426
)
427427
req = ProviderRequest()
428428
conv = await _get_session_conv(event=cron_event, plugin_context=self.ctx)

tests/unit/test_cron_manager.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,72 @@ async def test_run_basic_job_no_handler(self, cron_manager, sample_cron_job):
534534
await cron_manager._run_basic_job(sample_cron_job)
535535

536536

537+
class TestRunActiveAgentJob:
538+
"""Tests for active agent cron job execution."""
539+
540+
@pytest.mark.asyncio
541+
async def test_woke_main_agent_passes_provider_settings(self, cron_manager):
542+
"""Test active cron agent keeps fallback chat model settings."""
543+
provider_settings = {
544+
"tool_call_timeout": 77,
545+
"fallback_chat_models": ["fallback-provider"],
546+
}
547+
ctx = MagicMock()
548+
ctx.get_config.return_value = {
549+
"admins_id": [],
550+
"provider_settings": provider_settings,
551+
}
552+
cron_manager.ctx = ctx
553+
554+
conv = MagicMock()
555+
conv.history = "[]"
556+
557+
class FakeRunner:
558+
def step_until_done(self, max_step):
559+
async def gen():
560+
if False:
561+
yield None
562+
563+
return gen()
564+
565+
def get_final_llm_resp(self):
566+
return None
567+
568+
captured = {}
569+
570+
async def fake_build_main_agent(*, event, plugin_context, config, req):
571+
captured["config"] = config
572+
return MagicMock(agent_runner=FakeRunner())
573+
574+
async def fake_persist_agent_history(*args, **kwargs):
575+
return None
576+
577+
with (
578+
patch(
579+
"astrbot.core.astr_main_agent._get_session_conv",
580+
AsyncMock(return_value=conv),
581+
),
582+
patch(
583+
"astrbot.core.astr_main_agent.build_main_agent",
584+
side_effect=fake_build_main_agent,
585+
),
586+
patch(
587+
"astrbot.core.cron.manager.persist_agent_history",
588+
side_effect=fake_persist_agent_history,
589+
),
590+
):
591+
await cron_manager._woke_main_agent(
592+
message="run scheduled task",
593+
session_str="test:FriendMessage:user123",
594+
extras={"cron_job": {"id": "job-1"}, "cron_payload": {}},
595+
)
596+
597+
config = captured["config"]
598+
assert config.tool_call_timeout == 77
599+
assert config.provider_settings is provider_settings
600+
assert config.provider_settings["fallback_chat_models"] == ["fallback-provider"]
601+
602+
537603
class TestGetNextRunTime:
538604
"""Tests for _get_next_run_time method."""
539605

0 commit comments

Comments
 (0)