@@ -2252,9 +2252,12 @@ def _add_conversation_item_event( # pylint: disable=too-many-branches
22522252 # Create event body - format depends on item type
22532253 event_body : Dict [str , Any ] = {}
22542254
2255+ # Declare tool_call variable with type for use across branches
2256+ tool_call : Dict [str , Any ]
2257+
22552258 # Handle different item types
22562259 if item_type == "function_call_output" :
2257- # Tool output - use tool_call_outputs format
2260+ # Function tool output - use tool_call_outputs format
22582261 role = "tool" # Override role for tool outputs
22592262 if _trace_responses_content :
22602263 tool_output : Dict [str , Any ] = {
@@ -2283,10 +2286,10 @@ def _add_conversation_item_event( # pylint: disable=too-many-branches
22832286 event_name = "gen_ai.tool.message"
22842287
22852288 elif item_type == "function_call" :
2286- # Tool call - use tool_calls format
2289+ # Function tool call - use tool_calls format
22872290 role = "assistant" # Override role for function calls
22882291 if _trace_responses_content :
2289- tool_call : Dict [ str , Any ] = {
2292+ tool_call = {
22902293 "type" : "function" ,
22912294 }
22922295
@@ -2318,6 +2321,130 @@ def _add_conversation_item_event( # pylint: disable=too-many-branches
23182321
23192322 event_name = "gen_ai.assistant.message"
23202323
2324+ elif item_type == "file_search_call" :
2325+ # File search tool call
2326+ role = "assistant" # Override role for file search calls
2327+ if _trace_responses_content :
2328+ tool_call = {
2329+ "type" : "file_search" ,
2330+ }
2331+
2332+ # Add call_id as "id"
2333+ if hasattr (item , "call_id" ):
2334+ tool_call ["id" ] = item .call_id
2335+ elif hasattr (item , "id" ):
2336+ tool_call ["id" ] = item .id
2337+
2338+ # Add file search details
2339+ file_search_details : Dict [str , Any ] = {}
2340+
2341+ if hasattr (item , "queries" ) and item .queries :
2342+ file_search_details ["queries" ] = item .queries
2343+
2344+ if hasattr (item , "status" ):
2345+ file_search_details ["status" ] = item .status
2346+
2347+ if hasattr (item , "results" ) and item .results :
2348+ file_search_details ["results" ] = [
2349+ {
2350+ "file_id" : getattr (result , "file_id" , None ),
2351+ "file_name" : getattr (result , "file_name" , None ),
2352+ "score" : getattr (result , "score" , None ),
2353+ }
2354+ for result in item .results
2355+ ]
2356+
2357+ if file_search_details :
2358+ tool_call ["file_search" ] = file_search_details
2359+
2360+ event_body ["tool_calls" ] = [tool_call ]
2361+
2362+ event_name = "gen_ai.assistant.message"
2363+
2364+ elif item_type == "code_interpreter_call" :
2365+ # Code interpreter tool call
2366+ role = "assistant" # Override role for code interpreter calls
2367+ if _trace_responses_content :
2368+ tool_call = {
2369+ "type" : "code_interpreter" ,
2370+ }
2371+
2372+ # Add call_id as "id"
2373+ if hasattr (item , "call_id" ):
2374+ tool_call ["id" ] = item .call_id
2375+ elif hasattr (item , "id" ):
2376+ tool_call ["id" ] = item .id
2377+
2378+ # Add code interpreter details
2379+ code_interpreter_details : Dict [str , Any ] = {}
2380+
2381+ if hasattr (item , "code" ) and item .code :
2382+ code_interpreter_details ["code" ] = item .code
2383+
2384+ if hasattr (item , "status" ):
2385+ code_interpreter_details ["status" ] = item .status
2386+
2387+ if hasattr (item , "outputs" ) and item .outputs :
2388+ outputs_list = []
2389+ for output in item .outputs :
2390+ output_type = getattr (output , "type" , None )
2391+ if output_type == "logs" :
2392+ outputs_list .append ({"type" : "logs" , "logs" : getattr (output , "logs" , None )})
2393+ elif output_type == "image" :
2394+ outputs_list .append (
2395+ {
2396+ "type" : "image" ,
2397+ "image" : {"file_id" : getattr (getattr (output , "image" , None ), "file_id" , None )},
2398+ }
2399+ )
2400+ if outputs_list :
2401+ code_interpreter_details ["outputs" ] = outputs_list
2402+
2403+ if code_interpreter_details :
2404+ tool_call ["code_interpreter" ] = code_interpreter_details
2405+
2406+ event_body ["tool_calls" ] = [tool_call ]
2407+
2408+ event_name = "gen_ai.assistant.message"
2409+
2410+ elif item_type == "web_search_call" :
2411+ # Web search tool call
2412+ role = "assistant" # Override role for web search calls
2413+ if _trace_responses_content :
2414+ tool_call = {
2415+ "type" : "web_search" ,
2416+ }
2417+
2418+ # Add call_id as "id"
2419+ if hasattr (item , "call_id" ):
2420+ tool_call ["id" ] = item .call_id
2421+ elif hasattr (item , "id" ):
2422+ tool_call ["id" ] = item .id
2423+
2424+ # Add web search details
2425+ web_search_details : Dict [str , Any ] = {}
2426+
2427+ if hasattr (item , "status" ):
2428+ web_search_details ["status" ] = item .status
2429+
2430+ if hasattr (item , "action" ) and item .action :
2431+ action_type = getattr (item .action , "type" , None )
2432+ web_search_details ["action_type" ] = action_type
2433+
2434+ if action_type == "search" and hasattr (item .action , "query" ):
2435+ web_search_details ["query" ] = item .action .query
2436+ elif action_type == "open_page" and hasattr (item .action , "url" ):
2437+ web_search_details ["url" ] = item .action .url
2438+ elif action_type == "find" and hasattr (item .action , "query" ):
2439+ web_search_details ["find_query" ] = item .action .query
2440+
2441+ if web_search_details :
2442+ tool_call ["web_search" ] = web_search_details
2443+
2444+ event_body ["tool_calls" ] = [tool_call ]
2445+
2446+ event_name = "gen_ai.assistant.message"
2447+
23212448 elif item_type == "message" :
23222449 # Regular message - use text format
23232450 if _trace_responses_content and hasattr (item , "content" ) and item .content :
0 commit comments