agentops icon indicating copy to clipboard operation
agentops copied to clipboard

fix: prevent AttributeError when optional fields are None in web_search/file_search tools

Open Oxygen56 opened this issue 6 months ago • 0 comments

Description

Fixes #1285

When using the OpenAI Agents SDK with file search or web search tools, on_span_end raises:

AttributeError: 'NoneType' object has no attribute '__dict__'

Root Cause

In get_response_tool_web_search_attributes and get_response_tool_file_search_attributes, hasattr() guards check for the presence of optional fields (user_location, filters, ranking_options), but hasattr() returns True even when the attribute value is None. Accessing .__dict__ on None then raises AttributeError.

Fix

Added and <attr> is not None checks alongside each hasattr() guard:

  • get_response_tool_web_search_attributes: tool.user_location
  • get_response_tool_file_search_attributes: tool.filters, tool.ranking_options

Testing

Added two new test cases verifying that web search and file search tools work correctly when optional fields are None. All 15 tests pass.

  • test_get_response_tool_web_search_attributes_with_none_user_location
  • test_get_response_tool_file_search_attributes_with_none_filters_and_ranking

Oxygen56 avatar May 31 '26 10:05 Oxygen56