Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def get_response_tool_web_search_attributes(tool: "WebSearchTool", index: int) -
if hasattr(tool, "search_context_size"):
parameters["search_context_size"] = tool.search_context_size

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

tool_data = tool.__dict__
Expand All @@ -521,13 +521,13 @@ def get_response_tool_file_search_attributes(tool: "FileSearchTool", index: int)
if hasattr(tool, "vector_store_ids"):
parameters["vector_store_ids"] = tool.vector_store_ids

if hasattr(tool, "filters"):
if hasattr(tool, "filters") and tool.filters is not None:
parameters["filters"] = tool.filters.__dict__

if hasattr(tool, "max_num_results"):
parameters["max_num_results"] = tool.max_num_results

if hasattr(tool, "ranking_options"):
if hasattr(tool, "ranking_options") and tool.ranking_options is not None:
parameters["ranking_options"] = tool.ranking_options.__dict__

tool_data = tool.__dict__
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/instrumentation/openai_core/test_response_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,22 @@ def test_get_response_tool_web_search_attributes(self):
assert "search_context_size" in result[MessageAttributes.TOOL_CALL_ARGUMENTS.format(i=0)]
assert "user_location" in result[MessageAttributes.TOOL_CALL_ARGUMENTS.format(i=0)]

def test_get_response_tool_web_search_attributes_none_user_location(self):
"""Test web search tool handles None user_location without crashing"""
web_search_tool = MockWebSearchTool(
{"type": "web_search_preview", "search_context_size": "medium", "user_location": None}
)

with patch("agentops.instrumentation.providers.openai.attributes.response.WebSearchTool", MockWebSearchTool):
result = get_response_tool_web_search_attributes(web_search_tool, 0)

assert isinstance(result, dict)
assert MessageAttributes.TOOL_CALL_NAME.format(i=0) in result
assert result[MessageAttributes.TOOL_CALL_NAME.format(i=0)] == "web_search_preview"
# user_location should not appear in parameters since it's None
args = result.get(MessageAttributes.TOOL_CALL_ARGUMENTS.format(i=0), "")
assert "user_location" not in args

def test_get_response_tool_file_search_attributes(self):
"""Test extraction of attributes from file search tool"""
# Create a mock file search tool
Expand Down Expand Up @@ -644,6 +660,29 @@ def test_get_response_tool_file_search_attributes(self):
assert "max_num_results" in result[MessageAttributes.TOOL_CALL_ARGUMENTS.format(i=0)]
assert "ranking_options" in result[MessageAttributes.TOOL_CALL_ARGUMENTS.format(i=0)]

def test_get_response_tool_file_search_attributes_none_filters_and_ranking(self):
"""Test file search tool handles None filters and ranking_options without crashing"""
file_search_tool = MockFileSearchTool(
{
"type": "file_search",
"vector_store_ids": ["store_123"],
"filters": None,
"max_num_results": 5,
"ranking_options": None,
}
)

with patch("agentops.instrumentation.providers.openai.attributes.response.FileSearchTool", MockFileSearchTool):
result = get_response_tool_file_search_attributes(file_search_tool, 0)

assert isinstance(result, dict)
assert MessageAttributes.TOOL_CALL_TYPE.format(i=0) in result
assert result[MessageAttributes.TOOL_CALL_TYPE.format(i=0)] == "file_search"
# filters and ranking_options should not appear in parameters since they're None
args = result.get(MessageAttributes.TOOL_CALL_ARGUMENTS.format(i=0), "")
assert "filters" not in args
assert "ranking_options" not in args

def test_get_response_tool_computer_attributes(self):
"""Test extraction of attributes from computer tool"""
# Create a mock computer tool
Expand Down