Skip to content

fix: apply fallback chat models to background wakeups#9094

Open
zzz27578 wants to merge 1 commit into
AstrBotDevs:masterfrom
zzz27578:fix/background-wakeup-fallback-chat-models
Open

fix: apply fallback chat models to background wakeups#9094
zzz27578 wants to merge 1 commit into
AstrBotDevs:masterfrom
zzz27578:fix/background-wakeup-fallback-chat-models

Conversation

@zzz27578

@zzz27578 zzz27578 commented Jun 30, 2026

Copy link
Copy Markdown

Summary

  • Pass provider_settings into MainAgentBuildConfig for background task result wakeups.
  • Keep existing background wakeup streaming behavior while preserving fallback_chat_models and other provider settings.
  • Add a unit test covering provider_settings propagation for background task wakeups.

Why

#9054 already fixed the cron/future-task wakeup path. Background task result wakeups still build MainAgentBuildConfig without the full provider_settings, so fallback_chat_models are not available to the main agent runner after a background task completes.

Tests

  • uv run ruff format --check .
  • uv run ruff check .
  • uv run pytest tests\unit\test_astr_agent_tool_exec.py tests\unit\test_cron_manager.py tests\test_tool_loop_agent_runner.py -q

Summary by Sourcery

Ensure provider settings are propagated to the main agent when handling background task wakeups so fallback chat models and streaming settings are honored.

Bug Fixes:

  • Fix background task wakeup path building MainAgentBuildConfig without provider_settings, enabling fallback_chat_models and other options for the main agent runner.

Tests:

  • Add unit test verifying provider_settings, including streaming and fallback_chat_models, are passed through in background wakeup handling.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels Jun 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the background agent wakeup logic to retrieve and pass provider_settings to MainAgentBuildConfig, along with adding a comprehensive unit test to verify this behavior. Feedback was provided to safeguard against potential AttributeErrors if provider_settings is explicitly configured as None in the configuration.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread astrbot/core/astr_agent_tool_exec.py Outdated
Comment on lines +546 to +547
cfg = ctx.get_config(umo=event.unified_msg_origin) or {}
provider_settings = cfg.get("provider_settings", {})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If provider_settings is explicitly set to null (or None) in the configuration, cfg.get("provider_settings", {}) will return None instead of the default {}. This will lead to an AttributeError when calling provider_settings.get("stream", False) on the next line.

Using cfg.get("provider_settings") or {} ensures that provider_settings is always a dictionary even if the key is explicitly configured as None.

Suggested change
cfg = ctx.get_config(umo=event.unified_msg_origin) or {}
provider_settings = cfg.get("provider_settings", {})
cfg = ctx.get_config(umo=event.unified_msg_origin) or {}
provider_settings = cfg.get("provider_settings") or {}

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In test_background_wakeup_passes_provider_settings_to_main_agent, the assertion config.provider_settings is provider_settings relies on object identity and will break if the implementation ever copies or normalizes the dict; prefer asserting equality (==) instead of identity.
  • In _wake_main_agent_for_background_result, you manually build MainAgentBuildConfig from ctx.get_config; consider reusing the same helper or path used for other wakeups/builds so that any future changes to how provider settings are interpreted stay consistent across all agent startup flows.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `test_background_wakeup_passes_provider_settings_to_main_agent`, the assertion `config.provider_settings is provider_settings` relies on object identity and will break if the implementation ever copies or normalizes the dict; prefer asserting equality (`==`) instead of identity.
- In `_wake_main_agent_for_background_result`, you manually build `MainAgentBuildConfig` from `ctx.get_config`; consider reusing the same helper or path used for other wakeups/builds so that any future changes to how provider settings are interpreted stay consistent across all agent startup flows.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zzz27578 zzz27578 force-pushed the fix/background-wakeup-fallback-chat-models branch from 0e8c7cb to 3ee5da6 Compare June 30, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant