Skip to content

Comments

Python: Fix Azure AI sample errors#4021

Merged
eavanvalkenburg merged 5 commits intomicrosoft:mainfrom
giles17:azure_ai_v2_samples_fix
Feb 18, 2026
Merged

Python: Fix Azure AI sample errors#4021
eavanvalkenburg merged 5 commits intomicrosoft:mainfrom
giles17:azure_ai_v2_samples_fix

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Feb 17, 2026

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

  1. azure_ai_with_application_endpoint.py - Added missing name to Agent() constructor. Without it, the AzureAIClient has no agent_name and raises
    ServiceInitializationError.

  2. azure_ai_with_file_search.py - Fixed resource path: Path(__file__).parents[2] resolved to samples/02-agents instead of samples/. Changed to
    parents[3] to correctly reach samples/shared/resources/employees.pdf.

  3. azure_ai_with_openapi.py - Same path fix as above for countries.json.

  4. azure_ai_with_session.py - Two issues:

    • Used create_session(service_session_id=...) but create_session does not accept that parameter. Changed to get_session(service_session_id=...).
    • Used create_agent for the second agent instance, which creates a new agent version that does not share conversation history. Changed to get_agent to reuse
      the existing agent version.
  5. azure_ai_agent/azure_ai_with_file_search.py - Fixed resource path to reach samples/shared/resources/employees.pdf.

  6. 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_agent filtered tools with isinstance(tool, (FunctionTool, MutableMapping)). V1 SDK tool types like FileSearchTool inherit
from Tool (ABC), not MutableMapping, so they were silently dropped. Agents were created on the server without file search or other hosted tools configured.

  • create_agent: Replaced the restrictive isinstance filter with a simple MCPTool exclusion. All non-MCP tools now pass through to
    to_azure_ai_agent_tools, which already handles FunctionTool, SDK Tool types (via hasattr(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 are
    read 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 check and uv run ruff format --check pass on all changed files
  • uv run pytest packages/azure-ai/tests/ -q — all tests pass

- 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
Copilot AI review requested due to automatic review settings February 17, 2026 23:04
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

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 name when constructing Agent(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])
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 18, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai/agent_framework_azure_ai
   _agent_provider.py110199%249
TOTAL21156332584% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4164 239 💤 0 ❌ 0 🔥 1m 14s ⏱️

…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 eavanvalkenburg added this pull request to the merge queue Feb 18, 2026
Merged via the queue into microsoft:main with commit 28e3fc3 Feb 18, 2026
25 checks passed
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