@@ -262,13 +262,11 @@ def _run_single_child(
262262 # Get the progress callback from the child agent
263263 child_progress_cb = getattr (child , 'tool_progress_callback' , None )
264264
265- # Save the parent's resolved tool names before the child agent can
266- # overwrite the process-global via get_tool_definitions().
267- # This must be in _run_single_child (not _build_child_agent) so the
268- # save/restore happens in the same scope as the try/finally.
265+ # Restore parent tool names using the value saved before child construction
266+ # mutated the global. This is the correct parent toolset, not the child's.
269267 import model_tools
270- _saved_tool_names = list ( model_tools . _last_resolved_tool_names )
271- child . _delegate_saved_tool_names = _saved_tool_names
268+ _saved_tool_names = getattr ( child , "_delegate_saved_tool_names" ,
269+ list ( model_tools . _last_resolved_tool_names ))
272270
273271 try :
274272 result = child .run_conversation (user_message = goal )
@@ -465,6 +463,12 @@ def delegate_task(
465463 # Track goal labels for progress display (truncated for readability)
466464 task_labels = [t ["goal" ][:40 ] for t in task_list ]
467465
466+ # Save parent tool names BEFORE any child construction mutates the global.
467+ # _build_child_agent() calls AIAgent() which calls get_tool_definitions(),
468+ # which overwrites model_tools._last_resolved_tool_names with child's toolset.
469+ import model_tools as _model_tools
470+ _parent_tool_names = list (_model_tools ._last_resolved_tool_names )
471+
468472 # Build all child agents on the main thread (thread-safe construction)
469473 children = []
470474 for i , t in enumerate (task_list ):
@@ -476,8 +480,13 @@ def delegate_task(
476480 override_api_key = creds ["api_key" ],
477481 override_api_mode = creds ["api_mode" ],
478482 )
483+ # Override with correct parent tool names (before child construction mutated global)
484+ child ._delegate_saved_tool_names = _parent_tool_names
479485 children .append ((i , t , child ))
480486
487+ # Authoritative restore: reset global to parent's tool names after all children built
488+ _model_tools ._last_resolved_tool_names = _parent_tool_names
489+
481490 if n_tasks == 1 :
482491 # Single task -- run directly (no thread pool overhead)
483492 _i , _t , child = children [0 ]
0 commit comments