Fix: Preserve parent agent's tool list after subagent delegation#1765
Closed
shane9coy wants to merge 1 commit into
Closed
Fix: Preserve parent agent's tool list after subagent delegation#1765shane9coy wants to merge 1 commit into
shane9coy wants to merge 1 commit into
Conversation
Problem: _last_resolved_tool_names in model_tools.py is a process-global variable. When a subagent runs via delegate_task, it calls get_tool_definitions() which overwrites this global with the subagent's restricted tool list. After the subagent completes, the parent agent's tool list is lost, causing execute_code to generate sandbox code with missing tool imports. Solution: Save and restore _last_resolved_tool_names around subagent execution in delegate_tool.py. The save/restore is wrapped in try/except and guarded in the finally block to handle edge cases. Concurrency note: This fix assumes delegation runs sequentially. Each subagent in batch mode runs in its own _run_single_child() call with its own save/restore, so the pattern works correctly.
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.
Problem
_last_resolved_tool_namesin model_tools.py is a process-global variable. When a subagent runs viadelegate_task, it callsget_tool_definitions()which overwrites this global with the subagent's restricted tool list. After the subagent completes, the parent agent's tool list is lost, causingexecute_codeto generate sandbox code with missing tool imports.Solution
Save and restore
_last_resolved_tool_namesaround subagent execution indelegate_tool.py. The save/restore is wrapped in try/except and guarded in the finally block to handle edge cases.Concurrency Note
This fix assumes delegation runs sequentially. Each subagent in batch mode runs in its own
_run_single_child()call with its own save/restore, so the pattern works correctly.@NousResearch