Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions python/packages/core/agent_framework/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2871,12 +2871,7 @@ class _ChatOptionsBase(TypedDict, total=False):
presence_penalty: float

# Tool configuration (forward reference to avoid circular import)
tools: (
ToolTypes
| Callable[..., Any]
| Sequence[ToolTypes | Callable[..., Any]]
| None
)
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None
tool_choice: ToolMode | Literal["auto", "required", "none"]
allow_multiple_tool_calls: bool

Expand Down
6 changes: 3 additions & 3 deletions python/packages/core/agent_framework/azure/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from typing import Any, ClassVar, Final

from azure.core.credentials import TokenCredential
from azure.identity import get_bearer_token_provider
from openai import AsyncOpenAI
from openai.lib.azure import AsyncAzureOpenAI

from .._settings import SecretString
from .._telemetry import APP_INFO, prepend_agent_framework_to_user_agent
from ..exceptions import ServiceInitializationError
from ..openai._shared import OpenAIBase
from ._entra_id_authentication import get_entra_auth_token

logger: logging.Logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -174,10 +174,10 @@ def __init__(
merged_headers = prepend_agent_framework_to_user_agent(merged_headers)
if not client:
# If the client is None, the api_key is none, the ad_token is none, and the ad_token_provider is none,
# then we will attempt to get the ad_token using the default endpoint specified in the Azure OpenAI
# then we will set the ad_token_provider using the default endpoint specified in the Azure OpenAI
# settings.
if not api_key and not ad_token_provider and not ad_token and token_endpoint and credential:
ad_token = get_entra_auth_token(credential, token_endpoint)
ad_token_provider = get_bearer_token_provider(credential, token_endpoint)

if not api_key and not ad_token and not ad_token_provider:
raise ServiceInitializationError(
Expand Down
12 changes: 12 additions & 0 deletions python/packages/core/tests/azure/test_azure_responses_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ def test_init_with_project_endpoint(azure_openai_unit_test_env: dict[str, str])
assert isinstance(azure_responses_client, SupportsChatGetResponse)


@pytest.mark.parametrize("exclude_list", [["AZURE_OPENAI_API_KEY"]], indirect=True)
def test_init_with_credential(azure_openai_unit_test_env: dict[str, str]) -> None:
from unittest.mock import patch

credential = AzureCliCredential()
with patch("agent_framework.azure._shared.get_bearer_token_provider") as mock_get_bearer_token_provider:
azure_responses_client = AzureOpenAIResponsesClient(credential=credential)

assert azure_responses_client.model_id == "test_chat_deployment"
mock_get_bearer_token_provider.assert_called_once_with(credential, "https://test-token-endpoint.com")


def test_create_client_from_project_with_project_client() -> None:
"""Test _create_client_from_project with an existing project client."""
from openai import AsyncOpenAI
Expand Down
Loading