agentops
agentops copied to clipboard
fix: prevent AttributeError when optional fields are None in web_search/file_search tools
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_locationget_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_locationtest_get_response_tool_file_search_attributes_with_none_filters_and_ranking