Skip to content

Fix AttributeError when tool fields are None in OpenAI Agents SDK instrumentation (#1285)#2347

Open
YouFoxGirl wants to merge 1 commit intomodelcontextprotocol:mainfrom
YouFoxGirl:fix/1285-none-attribute-crash
Open

Fix AttributeError when tool fields are None in OpenAI Agents SDK instrumentation (#1285)#2347
YouFoxGirl wants to merge 1 commit intomodelcontextprotocol:mainfrom
YouFoxGirl:fix/1285-none-attribute-crash

Conversation

@YouFoxGirl
Copy link

Summary

In get_response_tool_web_search_attributes() and get_response_tool_file_search_attributes(), hasattr() returns True for optional fields set to None, but accessing .__dict__ on None raises AttributeError.

Fix

Added is not None guard for user_location, filters, and ranking_options fields in agentops/instrumentation/providers/openai/attributes/response.py:

# Before (buggy)
if hasattr(tool, "user_location"):
    parameters["user_location"] = tool.user_location.__dict__

# After (fixed)
if hasattr(tool, "user_location") and tool.user_location is not None:
    parameters["user_location"] = tool.user_location.__dict__

Same pattern applied to filters and ranking_options.

Testing

Added regression tests in tests/unit/instrumentation/providers/openai/test_response_issue_1285.py covering all three None-field cases. All 5 tests pass.

Fixes #1285

…trumentation

In get_response_tool_web_search_attributes() and get_response_tool_file_search_attributes(), hasattr() returns True for optional fields set to None, but accessing .__dict__ on None raises AttributeError. Added is not None guard for user_location, filters, and ranking_options fields.

Fixes modelcontextprotocol#1285
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant