Python: Fix Azure AI sample errors#4021
Merged
eavanvalkenburg merged 5 commits intomicrosoft:mainfrom Feb 18, 2026
Merged
Conversation
- azure_ai_with_application_endpoint: Add missing name to Agent constructor - azure_ai_with_file_search: Fix resource path (parents[2] -> parents[3]) - azure_ai_with_openapi: Fix resource path (parents[2] -> parents[3]) - azure_ai_with_session: Use get_agent/get_session to reuse existing agent version and preserve conversation context across agent instances
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes broken Azure AI Python samples under python/samples/02-agents/providers/azure_ai so they run successfully with the current Agent Framework Azure AI client/provider APIs.
Changes:
- Add a required agent
namewhen constructingAgent(AzureAIClient(...))so AzureAIClient can resolve/create an agent reference. - Fix sample resource paths to correctly locate
python/samples/shared/resources/*from the provider sample directory. - Correct session/agent rehydration logic to reuse an existing agent version and attach an existing
service_session_id.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/samples/02-agents/providers/azure_ai/azure_ai_with_session.py | Uses get_agent(...) and get_session(service_session_id=...) to correctly continue a server-managed session. |
| python/samples/02-agents/providers/azure_ai/azure_ai_with_openapi.py | Updates resource path resolution to load countries.json from samples/shared/resources. |
| python/samples/02-agents/providers/azure_ai/azure_ai_with_file_search.py | Updates resource path resolution to load employees.pdf from samples/shared/resources. |
| python/samples/02-agents/providers/azure_ai/azure_ai_with_application_endpoint.py | Provides Agent.name so the underlying AzureAIClient has an agent name to operate with. |
- azure_ai_with_file_search: Fix path to employees.pdf (parent.parent -> parents[3]/shared) - azure_ai_with_openapi_tools: Fix path to weather.json/countries.json (parents[2] -> parents[3])
dmytrostruk
approved these changes
Feb 18, 2026
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
…of AgentsClient) The azure_ai/azure_ai_with_file_search.py sample incorrectly used the V1 AgentsClient for file/vector store operations. Replaced with V2 pattern: AIProjectClient + get_openai_client() for file upload and vector store management, matching the official Azure AI Projects SDK samples.
eavanvalkenburg
approved these changes
Feb 18, 2026
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.
Summary
Fixes multiple failing Azure AI samples and a bug where V1 SDK hosted tools (FileSearchTool, CodeInterpreterTool, etc.) were silently dropped during agent
creation.
Sample Fixes
azure_ai_with_application_endpoint.py - Added missing
nametoAgent()constructor. Without it, theAzureAIClienthas noagent_nameand raisesServiceInitializationError.azure_ai_with_file_search.py - Fixed resource path:
Path(__file__).parents[2]resolved tosamples/02-agentsinstead ofsamples/. Changed toparents[3]to correctly reachsamples/shared/resources/employees.pdf.azure_ai_with_openapi.py - Same path fix as above for
countries.json.azure_ai_with_session.py - Two issues:
create_session(service_session_id=...)butcreate_sessiondoes not accept that parameter. Changed toget_session(service_session_id=...).create_agentfor the second agent instance, which creates a new agent version that does not share conversation history. Changed toget_agentto reusethe existing agent version.
azure_ai_agent/azure_ai_with_file_search.py - Fixed resource path to reach
samples/shared/resources/employees.pdf.azure_ai_agent/azure_ai_with_openapi_tools.py - Fixed resource path to reach
samples/shared/resources/weather.json.Bug Fix: V1 SDK hosted tools dropped during agent creation
AzureAIAgentsProvider.create_agentfiltered tools withisinstance(tool, (FunctionTool, MutableMapping)). V1 SDK tool types likeFileSearchToolinheritfrom
Tool(ABC), notMutableMapping, so they were silently dropped. Agents were created on the server without file search or other hosted tools configured.create_agent: Replaced the restrictiveisinstancefilter with a simpleMCPToolexclusion. All non-MCP tools now pass through toto_azure_ai_agent_tools, which already handlesFunctionTool, SDKTooltypes (viahasattr(tool, "definitions")), and dicts._merge_tools: Removed code that re-added hosted tool dicts from the server agent definition to local tools. Hosted tools are already on the server and areread back at run time via
agent_definition.tools. Re-adding them locally caused duplicate tool errors (Unknown parameter: 'tools[1].vector_store_ids').Validation
uv run ruff checkanduv run ruff format --checkpass on all changed filesuv run pytest packages/azure-ai/tests/ -q— all tests pass