fix: preserve parent agent's tool list after subagent delegation (#1778)

Save and restore the process-global _last_resolved_tool_names in
_run_single_child() so the parent's execute_code sandbox generates
correct tool imports after delegation completes.

The global was already mostly mitigated (run_agent.py passes
enabled_tools via self.valid_tool_names), but the global itself
remained corrupted — a footgun for any code that reads it directly.

Co-authored-by: shane9coy <shane9coy@users.noreply.github.com>
This commit is contained in:
Teknium 2026-03-17 10:31:38 -07:00 committed by GitHub
parent 9a1e971126
commit b5cf0f0aef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 53 additions and 1 deletions

View file

@ -171,6 +171,11 @@ def _build_child_agent(
model on OpenRouter while the parent runs on Nous Portal).
"""
from run_agent import AIAgent
import model_tools
# Save the parent's resolved tool names before the child agent can
# overwrite the process-global via get_tool_definitions().
_saved_tool_names = list(model_tools._last_resolved_tool_names)
# When no explicit toolsets given, inherit from parent's enabled toolsets
# so disabled tools (e.g. web) don't leak to subagents.
@ -365,6 +370,10 @@ def _run_single_child(
}
finally:
# Restore the parent's tool names so the process-global is correct
# for any subsequent execute_code calls or other consumers.
model_tools._last_resolved_tool_names = _saved_tool_names
# Unregister child from interrupt propagation
if hasattr(parent_agent, '_active_children'):
try: