@@ -1397,6 +1397,7 @@ async def _run_single_turn_streamed(
13971397 model = cls ._get_model (agent , run_config )
13981398 model_settings = agent .model_settings .resolve (run_config .model_settings )
13991399 model_settings = RunImpl .maybe_reset_tool_choice (agent , tool_use_tracker , model_settings )
1400+ function_map = {tool .name : tool for tool in all_tools if isinstance (tool , FunctionTool )}
14001401
14011402 final_response : ModelResponse | None = None
14021403
@@ -1489,20 +1490,13 @@ async def _run_single_turn_streamed(
14891490 emitted_tool_call_ids .add (call_id )
14901491
14911492 # Try to get origin info if this is a FunctionTool call
1493+ # Use same lookup logic as _run_impl (function_map with last-wins semantics)
14921494 tool_origin = None
14931495 if isinstance (output_item , ResponseFunctionToolCall ):
14941496 tool_name = getattr (output_item , "name" , None )
1495- if tool_name :
1496- function_tool = next (
1497- (
1498- tool
1499- for tool in all_tools
1500- if isinstance (tool , FunctionTool ) and tool .name == tool_name
1501- ),
1502- None ,
1503- )
1504- if function_tool :
1505- tool_origin = _get_tool_origin_info (function_tool )
1497+ if tool_name and tool_name in function_map :
1498+ function_tool = function_map [tool_name ]
1499+ tool_origin = _get_tool_origin_info (function_tool )
15061500
15071501 tool_item = ToolCallItem (
15081502 raw_item = cast (ToolCallItemTypes , output_item ),
0 commit comments