Skip to content

Commit 3fde2a2

Browse files
committed
Fix CI import failures and missing is_dev guard
agent_framework.openai causes a circular-import chain under Python 3.12 on Linux: openai.__getattr__ lazily imports agent_framework_openai, which eventually does `from . import __version__` on the still-initialising agent_framework package. Move OpenAIChatClient under TYPE_CHECKING so the import is never executed at runtime. Also add the missing is_development_environment() guard to the Azure AI Foundry extension's add_tool_servers_to_agent, matching the pattern used by the other three extensions: dev mode skips token exchange and uses "" as the agentic_app_id for manifest-based discovery.
1 parent f2f5f51 commit 3fde2a2

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

libraries/microsoft-agents-a365-tooling-extensions-agentframework/microsoft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
from __future__ import annotations
5+
46
import logging
57
import uuid
68
from datetime import datetime, timezone
7-
from typing import List, Optional, Sequence
9+
from typing import TYPE_CHECKING, List, Optional, Sequence
810

911
from agent_framework import RawAgent, Message, HistoryProvider, MCPStreamableHTTPTool
10-
from agent_framework.openai import OpenAIChatClient
1112
import httpx
1213

14+
if TYPE_CHECKING:
15+
from agent_framework.openai import OpenAIChatClient
16+
1317
from microsoft_agents.hosting.core import Authorization, TurnContext
1418

1519
from microsoft_agents_a365.runtime import OperationResult

libraries/microsoft-agents-a365-tooling-extensions-azureaifoundry/microsoft_agents_a365/tooling/extensions/azureaifoundry/services/mcp_tool_registration_service.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
McpToolServerConfigurationService,
2828
)
2929
from microsoft_agents_a365.tooling.utils.constants import Constants
30-
from microsoft_agents_a365.tooling.utils.utility import get_mcp_platform_authentication_scope
30+
from microsoft_agents_a365.tooling.utils.utility import (
31+
get_mcp_platform_authentication_scope,
32+
is_development_environment,
33+
)
3134

3235

3336
class McpToolRegistrationService:
@@ -99,13 +102,14 @@ async def add_tool_servers_to_agent(
99102
if project_client is None:
100103
raise ValueError("project_client cannot be None")
101104

102-
if not auth_token:
105+
is_dev = is_development_environment()
106+
if not auth_token and not is_dev:
103107
scopes = get_mcp_platform_authentication_scope()
104108
authToken = await auth.exchange_token(context, scopes, auth_handler_name)
105109
auth_token = authToken.token
106110

107111
try:
108-
agentic_app_id = Utility.resolve_agent_identity(context, auth_token)
112+
agentic_app_id = "" if is_dev else Utility.resolve_agent_identity(context, auth_token)
109113
# Get the tool definitions and resources — pass auth context so each server receives
110114
# its own per-audience Authorization token (V1 = shared ATG, V2 = per-GUID).
111115
tool_definitions, tool_resources = await self._get_mcp_tool_definitions_and_resources(

tests/tooling/extensions/azureaifoundry/services/test_mcp_tool_registration_service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ async def test_list_tool_servers_receives_auth_context(
115115

116116
with (
117117
patch(f"{_MODULE}.McpTool", return_value=mock_mcp_tool),
118+
patch(f"{_MODULE}.is_development_environment", return_value=False),
118119
patch(f"{_MODULE}.Utility.resolve_agent_identity", return_value="test-aai"),
119120
patch(f"{_MODULE}.Utility.get_user_agent_header", return_value="AzureAIFoundry/1.0"),
120121
):

0 commit comments

Comments
 (0)