Skip to content

Comments

Python: Fix sample bugs in file search and web search samples#4049

Merged
giles17 merged 1 commit intomicrosoft:mainfrom
giles17:openai_sample_fixes
Feb 18, 2026
Merged

Python: Fix sample bugs in file search and web search samples#4049
giles17 merged 1 commit intomicrosoft:mainfrom
giles17:openai_sample_fixes

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Feb 18, 2026

Description

Fixes several bugs in Python OpenAI sample scripts that caused runtime errors.

Changes

  • File search samples (Azure + OpenAI Responses): create_vector_store returned a Content object instead of a plain vector_store.id string, causing TypeError: Object of type Content is not JSON serializable when passed to get_file_search_tool(vector_store_ids=...).
  • Web search sample (OpenAI Chat): Used user_location kwarg (Responses API signature) instead of the correct web_search_options parameter for the Chat Completions API.
  • Assistants client: _prepare_options did not extract tool_resources from options, so vector store IDs were never passed to thread creation, causing file search to silently fail.
  • Azure file search sample cleanup: Added contextlib.suppress around cleanup calls to handle cases where resources are already deleted.

Affected files

  • python/packages/core/agent_framework/openai/_assistants_client.py
  • python/samples/02-agents/providers/azure_openai/azure_responses_client_with_file_search.py
  • python/samples/02-agents/providers/openai/openai_chat_client_with_web_search.py
  • python/samples/02-agents/providers/openai/openai_responses_client_with_file_search.py

Testing

Manually verified the Azure file search sample runs successfully end-to-end.

- Fix file search samples: return vector_store.id string instead of
  Content object to avoid JSON serialization error
- Fix web search sample: use correct web_search_options parameter for
  ChatClient instead of ResponsesClient's user_location parameter
- Fix assistants client: pass tool_resources from options to run_options
  so vector store IDs reach thread creation
- Add error handling for cleanup in Azure file search sample

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 18, 2026 19:50
@giles17 giles17 enabled auto-merge February 18, 2026 19:51
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/openai
   _assistants_client.py2763587%408, 410, 412, 415, 419–420, 423, 426, 431–432, 434, 437–439, 444, 455, 480, 482, 484, 486, 488, 493, 496, 499, 503, 514, 599, 685, 688, 717, 754–757, 827
TOTAL21185333184% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4173 239 💤 0 ❌ 0 🔥 1m 13s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes critical bugs in Python OpenAI sample scripts that caused runtime errors when using file search and web search features. The fixes address type mismatches, incorrect API parameter usage, and missing parameter extraction in the Assistants client.

Changes:

  • Fixed file search samples to return vector store IDs as strings instead of Content objects, preventing JSON serialization errors
  • Corrected web search sample to use proper nested parameter structure for Chat Completions API
  • Fixed Assistants client to properly extract and pass tool_resources option for file search functionality

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
python/packages/core/agent_framework/openai/_assistants_client.py Added extraction and passing of tool_resources from options to enable file search in thread creation
python/samples/02-agents/providers/azure_openai/azure_responses_client_with_file_search.py Changed return type from Content to str, added contextlib.suppress for cleanup error handling, and removed unused Content import
python/samples/02-agents/providers/openai/openai_chat_client_with_web_search.py Fixed parameter structure from direct user_location to nested web_search_options with proper type and approximate keys
python/samples/02-agents/providers/openai/openai_responses_client_with_file_search.py Changed return type from Content to str and removed unused Content import

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants