agentops icon indicating copy to clipboard operation
agentops copied to clipboard

fix: add None checks for optional tool fields in response attributes

Open fahe1em1 opened this issue 8 months ago • 0 comments

Summary

  • Adds is not None checks before accessing .__dict__ on optional tool fields
  • Fixes AttributeError: 'NoneType' object has no attribute '__dict__' when using OpenAI Agents SDK with web search or file search tools

Problem

WebSearchTool.user_location, FileSearchTool.filters, and FileSearchTool.ranking_options are optional fields that default to None in the OpenAI SDK. The existing hasattr() guards return True even when the attribute value is None, causing the .__dict__ access to crash.

Changes

In agentops/instrumentation/providers/openai/attributes/response.py:

  • get_response_tool_web_search_attributes: Added and tool.user_location is not None
  • get_response_tool_file_search_attributes: Added and tool.filters is not None and and tool.ranking_options is not None

Test plan

  • [ ] Verify web search tool with user_location=None no longer crashes
  • [ ] Verify file search tool with filters=None and ranking_options=None no longer crashes
  • [ ] Verify tools with non-None values still extract attributes correctly

Fixes #1285

https://claude.ai/code/session_011TWMvnjeLgAJg9XtxoLfZT

fahe1em1 avatar Mar 12 '26 22:03 fahe1em1