Python: Fix sample bugs in file search and web search samples#4049
Merged
giles17 merged 1 commit intomicrosoft:mainfrom Feb 18, 2026
Merged
Python: Fix sample bugs in file search and web search samples#4049giles17 merged 1 commit intomicrosoft:mainfrom
giles17 merged 1 commit intomicrosoft:mainfrom
Conversation
- 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>
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
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 |
dmytrostruk
approved these changes
Feb 18, 2026
eavanvalkenburg
approved these changes
Feb 18, 2026
This was referenced Feb 18, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes several bugs in Python OpenAI sample scripts that caused runtime errors.
Changes
create_vector_storereturned aContentobject instead of a plainvector_store.idstring, causingTypeError: Object of type Content is not JSON serializablewhen passed toget_file_search_tool(vector_store_ids=...).user_locationkwarg (Responses API signature) instead of the correctweb_search_optionsparameter for the Chat Completions API._prepare_optionsdid not extracttool_resourcesfrom options, so vector store IDs were never passed to thread creation, causing file search to silently fail.contextlib.suppressaround cleanup calls to handle cases where resources are already deleted.Affected files
python/packages/core/agent_framework/openai/_assistants_client.pypython/samples/02-agents/providers/azure_openai/azure_responses_client_with_file_search.pypython/samples/02-agents/providers/openai/openai_chat_client_with_web_search.pypython/samples/02-agents/providers/openai/openai_responses_client_with_file_search.pyTesting
Manually verified the Azure file search sample runs successfully end-to-end.