fix: apply max_agent_step config to cron and background task agents - #9801
Open
Shaofei215 wants to merge 3 commits into
Open
fix: apply max_agent_step config to cron and background task agents#9801Shaofei215 wants to merge 3 commits into
Shaofei215 wants to merge 3 commits into
Conversation
The cron (scheduled task) and background task wake-up paths hardcoded step_until_done(30) since the "extract main agent" refactor (0c5308a), ignoring provider_settings.max_agent_step. Read the value via coerce_int_config so invalid values fall back to the default with a warning instead of crashing or silently degrading. Fixes AstrBotDevs#9800
Add parametrized tests asserting step_until_done receives the configured max_agent_step on both the cron and background task agent paths, with fallback coverage for missing, boolean-polluted, and numeric-string config values.
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/astr_agent_tool_exec.py" line_range="556" />
<code_context>
cron_event.role = event.role
cfg = ctx.get_config(umo=event.unified_msg_origin) or {}
provider_settings = cfg.get("provider_settings") or {}
+ agent_max_step = coerce_int_config(
+ provider_settings.get("max_agent_step", 30),
+ default=30,
+ field_name="provider_settings.max_agent_step",
+ )
config = MainAgentBuildConfig(
</code_context>
<issue_to_address>
**issue (bug_risk):** Non-positive `max_agent_step` values are accepted because these calls omit `min_value`. The local runner skips all normal steps and immediately forces a final response for zero or negative values, while the DeerFlow runner raises `ValueError`, so an invalid configured value breaks or truncates both wake-up paths instead of falling back to a usable default.
**Triggers:** When `provider_settings.max_agent_step` is configured as zero or a negative integer.
**Suggested fix:** Pass `min_value=1` to `coerce_int_config` so non-positive values fall back to the default or minimum instead of reaching `step_until_done`.
```suggestion
min_value=1,
field_name="provider_settings.max_agent_step",
```
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the configured limit is wrong, cron or background agents may perform extra model/tool steps, increasing compute and potentially triggering additional tool side effects before the run stops. Reverting restores the fixed 30-step behavior, but any messages or other actions already taken during an overlong run would not be undone.
Blocking findings: astrbot/core/astr_agent_tool_exec.py:556
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…ke-ups Non-positive provider_settings.max_agent_step values previously reached step_until_done as-is: the local runner skipped all steps and forced a final response, while the DeerFlow runner raised ValueError. Pass min_value=1 to coerce_int_config so zero/negative values are clamped to a usable minimum, and cover the zero case in both unit test suites.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9800
修复了 #9800
Modifications / 改动点
Read
provider_settings.max_agent_stepin the cron (future task) wake-up path (astrbot/core/cron/manager.py) and the background task result wake-up path (astrbot/core/astr_agent_tool_exec.py), and pass it torunner.step_until_done()instead of the hardcoded30.在 Cron 未来任务唤醒路径(
astrbot/core/cron/manager.py)与后台任务结果唤醒路径(astrbot/core/astr_agent_tool_exec.py)中读取provider_settings.max_agent_step,传入runner.step_until_done(),替换写死的30。Parse the value with the existing
coerce_int_configutility: bool / non-numeric string /Nonefalls back to the default30with a warning. This is consistent with the main pipeline's [Bug] 更新4.0前如果更改过唤醒词,发出的任何请求不会有回应 #2622 bool workaround and the existing usage in the deerflow runner / request retry logic. Behavior is unchanged for users who have not customized this setting.使用既有的
coerce_int_config工具解析取值:布尔 / 非数字字符串 /None回退到默认值30并输出警告。与主管线的 [Bug] 更新4.0前如果更改过唤醒词,发出的任何请求不会有回应 #2622 布尔 workaround 及 deerflow runner / 请求重试逻辑的既有用法保持一致。未自定义该项配置的用户行为不变。Add 8 parametrized unit tests (4 cases × 2 paths) covering: configured value propagation, missing-key fallback, boolean pollution fallback, and numeric string coercion.
新增 8 个参数化单元测试(4 种用例 × 2 条路径),覆盖:配置值传播、缺省回退、布尔污染回退、数字字符串转换。
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Lint and unit tests (all executed locally on the PR branch) / 代码检查与单元测试(均在 PR 分支本地执行):
Regression guard verification: with the fix reverted (
git checkout master -- astrbot/core/cron/manager.py astrbot/core/astr_agent_tool_exec.py), the new value-propagation test cases fail as expected (4 failed, 4 passed), proving the tests actually protect against the regression.回归防护验证:将修复还原后(
git checkout master -- astrbot/core/cron/manager.py astrbot/core/astr_agent_tool_exec.py),新增的取值传播测试用例如预期失败(4 failed, 4 passed),证明测试确实能防护该回归。Checklist / 检查清单
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
(Bug fix only, no new features — the fix targets the behavior reported in [Bug] 未来任务被写死只能调用30次工具 #9800. / 仅为缺陷修复,无新增功能,修复对象即 [Bug] 未来任务被写死只能调用30次工具 #9800 所报告的行为。)
/ 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。/ 我的更改没有引入恶意代码。
Summary by Sourcery
Honor
max_agent_stepconfiguration for cron and background-task agent execution while retaining safe fallback behavior.Bug Fixes:
provider_settings.max_agent_steplimit to cron-triggered and background-task agent wake-ups instead of always using the default limit.Enhancements:
Tests: