@@ -78,10 +78,12 @@ def get_ai_metrics_from_response(response: Any) -> LDAIMetrics:
7878 return LDAIMetrics (success = True , usage = get_ai_usage_from_response (response ))
7979
8080
81- # Tool ``name`` values that map to OpenAI hosted-tool ``type`` (same string as ``name``).
82- _NATIVE_API_TOOL_NAMES = frozenset ({
81+ # Canonical names for OpenAI hosted tools (LD config / Chat Completions ``type``).
82+ # Agent run items use ``raw_item.type`` with a ``_call`` suffix (e.g. ``web_search_call``).
83+ _OPENAI_HOSTED_TOOL_NAMES = frozenset ({
8384 'web_search' ,
8485 'file_search' ,
86+ 'code_interpreter' ,
8587 'tool_search' ,
8688})
8789
@@ -103,7 +105,7 @@ def normalize_tool_types(tool_definitions: List[Any]) -> List[Dict[str, Any]]:
103105 if not isinstance (td , dict ):
104106 continue
105107 name = td .get ('name' , '' )
106- if name in _NATIVE_API_TOOL_NAMES :
108+ if name in _OPENAI_HOSTED_TOOL_NAMES :
107109 result .append ({** td , 'type' : name })
108110 else :
109111 result .append (td )
@@ -135,19 +137,9 @@ def registry_value_to_agent_tool(value: Any) -> Any:
135137 return function_tool (value )
136138
137139
138- # Native tool response types do not match the SDK or LD tool name; this map aligns them.
139- # Function tools are omitted—they already arrive as ``ResponseFunctionToolCall.name``.
140- _RESPONSE_TYPE_TO_TOOL_NAME : Dict [str , str ] = {
141- 'web_search_call' : 'web_search' ,
142- 'file_search_call' : 'file_search' ,
143- 'code_interpreter_call' : 'code_interpreter' ,
144- }
145-
146-
147140def get_tool_calls_from_run_items (new_items : List [Any ]) -> List [Tuple [str , str ]]:
148141 """
149142 Extract (agent_name, tool_name) pairs from RunResult.new_items.
150-
151143 Covers both custom FunctionTools (tracked by their config key) and native
152144 hosted tools (web search, file search, code interpreter, image generation).
153145
@@ -174,7 +166,11 @@ def get_tool_calls_from_run_items(new_items: List[Any]) -> List[Tuple[str, str]]
174166 raw_type = getattr (raw , 'type' , None ) or (raw .get ('type' ) if isinstance (raw , dict ) else None )
175167 if not isinstance (raw_type , str ):
176168 continue
177- tool_name = _RESPONSE_TYPE_TO_TOOL_NAME .get (raw_type , raw_type )
169+ if raw_type .endswith ('_call' ):
170+ base = raw_type .removesuffix ('_call' )
171+ tool_name = base if base in _OPENAI_HOSTED_TOOL_NAMES else raw_type
172+ else :
173+ tool_name = raw_type
178174 if tool_name :
179175 result .append ((agent_name , tool_name ))
180176 return result
0 commit comments