Skip to content

Fix: Preserve parent agent's tool list after subagent delegation#1765

Closed
shane9coy wants to merge 1 commit into
NousResearch:mainfrom
shane9coy:fix/subagent-global-tool-names
Closed

Fix: Preserve parent agent's tool list after subagent delegation#1765
shane9coy wants to merge 1 commit into
NousResearch:mainfrom
shane9coy:fix/subagent-global-tool-names

Conversation

@shane9coy

Copy link
Copy Markdown
Contributor

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.


@NousResearch

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant