@@ -1777,41 +1777,38 @@ async def _try_execute_function_call_groups(
17771777 )
17781778 declaration_only_tool_names = {tool_name for tool_name , tool in tool_map .items () if tool .declaration_only }
17791779 additional_tool_names = {tool .name for tool in config .get ("additional_tools" ) or []}
1780- actionable_calls = [
1781- function_call for function_call in function_calls if _is_actionable_function_call (function_call )
1782- ]
1783-
17841780 # Classify the entire batch first: any required user interaction pauses the batch before execution.
17851781 # Scan every call before deciding so classification travels with each call, not with its position in
17861782 # the batch. Priority (highest first): approval pause > declaration-only user-input > unknown-call
17871783 # termination. A user-input pause therefore takes precedence over unknown-call termination in mixed batches.
17881784 requires_approval = False
17891785 has_declaration_only_call = False
1786+ unknown_call_found = False
17901787 unknown_call_name : str | None = None
1791- for function_call in actionable_calls :
1792- function_name = function_call .name
1788+ for function_call in function_calls :
1789+ source_function_call = _underlying_function_call (function_call )
1790+ function_name = source_function_call .name
17931791 logger .debug (
17941792 "Checking function call: type=%s, name=%s, in approval_tools=%s" ,
17951793 function_call .type ,
17961794 function_name ,
17971795 function_name in approval_tool_names ,
17981796 )
1799- if function_name in approval_tool_names :
1797+ if _is_actionable_function_call ( function_call ) and function_name in approval_tool_names :
18001798 logger .debug ("Approval needed for function: %s" , function_name )
18011799 requires_approval = True
18021800 continue
1803- if function_name in declaration_only_tool_names or function_name in additional_tool_names :
1801+ if _is_actionable_function_call (function_call ) and (
1802+ function_name in declaration_only_tool_names or function_name in additional_tool_names
1803+ ):
18041804 has_declaration_only_call = True
18051805 continue
1806- if (
1807- unknown_call_name is None
1808- and config .get ("terminate_on_unknown_calls" , False )
1809- and function_name not in tool_map
1810- ):
1806+ if not unknown_call_found and config .get ("terminate_on_unknown_calls" , False ) and function_name not in tool_map :
1807+ unknown_call_found = True
18111808 unknown_call_name = function_name
18121809 # Defer unknown-call termination until the whole batch is classified so a higher-priority approval or
18131810 # declaration-only pause anywhere in the batch is not skipped by an earlier unknown call.
1814- if not requires_approval and not has_declaration_only_call and unknown_call_name is not None :
1811+ if not requires_approval and not has_declaration_only_call and unknown_call_found :
18151812 raise KeyError (f'Error: Requested function "{ unknown_call_name } " not found.' )
18161813 if requires_approval :
18171814 # Surface only the approvals the host must decide; session-backed safe siblings wait for that resume.
0 commit comments