Repository navigation
fix(agent): respect configured max iterations for subagents - #3532
Merged
Re-bin merged 1 commit intoApr 30, 2026
Merged
Conversation
This was referenced Apr 30, 2026
Re-bin
approved these changes
Apr 30, 2026
Re-bin
left a comment
Collaborator
There was a problem hiding this comment.
This is the right fix.
The bug was that the parent agent already respected agents.defaults.maxToolIterations, but subagents still used a hardcoded max_iterations=15. This PR wires the configured limit into SubagentManager, uses it for subagent AgentRunSpec, and keeps it synced when max_iterations changes at runtime through the my tool.
I merged latest origin/main locally and reran the relevant tests:
python -m pytest tests/agent/tools/test_subagent_tools.py tests/agent/tools/test_self_tool_runtime_sync.py tests/agent/test_runner.py::test_subagent_max_iterations_announces_existing_fallback -q→ 10 passedpython -m ruff check nanobot/agent/subagent.py nanobot/agent/loop.py nanobot/agent/tools/self.py tests/agent/tools/test_subagent_tools.py tests/agent/tools/test_self_tool_runtime_sync.py→ passed
The scope is narrow, the tests cover direct construction, AgentLoop wiring, runtime sync, and MyTool updates.
From my side, this is ready to merge.
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.
Summary
max_iterationsintoSubagentManagerAgentRunSpecinstead of the old hardcoded15SubagentManagerinstances toAgentDefaults().max_tool_iterationsAgentLoop.max_iterationschanges at runtime, including updates made throughmy(action="set", key="max_iterations", ...)AgentLoopwiring, runtime synchronization, andMyToolupdatesRoot Cause
The main agent loop already reads
agents.defaults.maxToolIterationsand stores it asself.max_iterations, but subagents did not use that setting.SubagentManager._run_subagent()always passedmax_iterations=15toAgentRunSpec, so long-running subagent work could stop early even when users configured a higher iteration budget.Fix
This changes subagent iteration budgeting to follow the same runtime limit as the parent agent:
AgentLooppasses its configuredmax_iterationsintoSubagentManagerSubagentManagerstores the value and passes it through toAgentRunSpecSubagentManagerconstruction falls back toAgentDefaults().max_tool_iterationsAgentLoop._sync_subagent_runtime_limits()keeps the subagent manager aligned before each agent loop runMyToolcalls the same sync helper after changingmax_iterationsImpact
Users who increase
maxToolIterationsnow get the same budget for spawned subagents. This avoids premature subagent termination for longer research, polling, or multi-step background tasks while keeping the change scoped to the existing runtime limit.Fixes #970.
Validation
uv run --extra dev pytest tests/agent/tools/test_subagent_tools.py tests/agent/tools/test_self_tool_runtime_sync.py tests/agent/test_runner.py::test_subagent_max_iterations_announces_existing_fallback -quv run --extra dev ruff check nanobot/agent/subagent.py nanobot/agent/loop.py nanobot/agent/tools/self.py tests/agent/tools/test_subagent_tools.py tests/agent/tools/test_self_tool_runtime_sync.pyNote: the targeted pytest run passes with one existing async queue warning from
tests/agent/test_runner.py::test_subagent_max_iterations_announces_existing_fallback.