diff --git a/python/packages/azure/agent_framework_azure/_assistants_client.py b/python/packages/azure/agent_framework_azure/_assistants_client.py index b0d0c95bed..796ceba330 100644 --- a/python/packages/azure/agent_framework_azure/_assistants_client.py +++ b/python/packages/azure/agent_framework_azure/_assistants_client.py @@ -12,7 +12,7 @@ from pydantic.networks import AnyUrl from ._shared import AzureOpenAISettings if TYPE_CHECKING: - from azure.identity import ChainedTokenCredential + from azure.core.credentials import TokenCredential __all__ = ["AzureAssistantsClient"] @@ -35,7 +35,7 @@ class AzureAssistantsClient(OpenAIAssistantsClient): ad_token: str | None = None, ad_token_provider: AsyncAzureADTokenProvider | None = None, token_endpoint: str | None = None, - ad_credential: "ChainedTokenCredential | None" = None, + credential: "TokenCredential | None" = None, default_headers: Mapping[str, str] | None = None, async_client: AsyncAzureOpenAI | None = None, env_file_path: str | None = None, @@ -62,7 +62,7 @@ class AzureAssistantsClient(OpenAIAssistantsClient): ad_token: The Azure Active Directory token. (Optional) ad_token_provider: The Azure Active Directory token provider. (Optional) token_endpoint: The token endpoint to request an Azure token. (Optional) - ad_credential: The Azure AD credential to use for authentication. (Optional) + credential: The Azure credential to use for authentication. (Optional) default_headers: The default headers mapping of string keys to string values for HTTP requests. (Optional) async_client: An existing client to use. (Optional) @@ -95,9 +95,9 @@ class AzureAssistantsClient(OpenAIAssistantsClient): and not ad_token and not ad_token_provider and azure_openai_settings.token_endpoint - and ad_credential + and credential ): - ad_token = azure_openai_settings.get_azure_auth_token(ad_credential) + ad_token = azure_openai_settings.get_azure_auth_token(credential) if not async_client and not azure_openai_settings.api_key and not ad_token and not ad_token_provider: raise ServiceInitializationError("The Azure OpenAI API key, ad_token, or ad_token_provider is required.") diff --git a/python/packages/azure/agent_framework_azure/_chat_client.py b/python/packages/azure/agent_framework_azure/_chat_client.py index 3238fc7719..be87b9626c 100644 --- a/python/packages/azure/agent_framework_azure/_chat_client.py +++ b/python/packages/azure/agent_framework_azure/_chat_client.py @@ -14,7 +14,7 @@ from agent_framework import ( ) from agent_framework.exceptions import ServiceInitializationError from agent_framework.openai._chat_client import OpenAIChatClientBase -from azure.identity import ChainedTokenCredential +from azure.core.credentials import TokenCredential from openai.lib.azure import AsyncAzureADTokenProvider, AsyncAzureOpenAI from openai.types.chat.chat_completion import Choice from openai.types.chat.chat_completion_chunk import Choice as ChunkChoice @@ -50,7 +50,7 @@ class AzureChatClient(AzureOpenAIConfigBase, OpenAIChatClientBase): ad_token: str | None = None, ad_token_provider: AsyncAzureADTokenProvider | None = None, token_endpoint: str | None = None, - ad_credential: ChainedTokenCredential | None = None, + credential: TokenCredential | None = None, default_headers: Mapping[str, str] | None = None, async_client: AsyncAzureOpenAI | None = None, env_file_path: str | None = None, @@ -73,7 +73,7 @@ class AzureChatClient(AzureOpenAIConfigBase, OpenAIChatClientBase): ad_token: The Azure Active Directory token. (Optional) ad_token_provider: The Azure Active Directory token provider. (Optional) token_endpoint: The token endpoint to request an Azure token. (Optional) - ad_credential: The Azure Active Directory credential. (Optional) + credential: The Azure credential for authentication. (Optional) default_headers: The default headers mapping of string keys to string values for HTTP requests. (Optional) async_client: An existing client to use. (Optional) @@ -111,7 +111,7 @@ class AzureChatClient(AzureOpenAIConfigBase, OpenAIChatClientBase): ad_token=ad_token, ad_token_provider=ad_token_provider, token_endpoint=azure_openai_settings.token_endpoint, - ad_credential=ad_credential, + credential=credential, default_headers=default_headers, client=async_client, instruction_role=instruction_role, diff --git a/python/packages/azure/agent_framework_azure/_entra_id_authentication.py b/python/packages/azure/agent_framework_azure/_entra_id_authentication.py index 52423ed61c..638047608b 100644 --- a/python/packages/azure/agent_framework_azure/_entra_id_authentication.py +++ b/python/packages/azure/agent_framework_azure/_entra_id_authentication.py @@ -7,14 +7,14 @@ from agent_framework.exceptions import ServiceInvalidAuthError from azure.core.exceptions import ClientAuthenticationError if TYPE_CHECKING: - from azure.identity import ChainedTokenCredential - from azure.identity.aio import ChainedTokenCredential as AsyncChainedTokenCredential + from azure.core.credentials import TokenCredential + from azure.core.credentials_async import AsyncTokenCredential logger: logging.Logger = logging.getLogger(__name__) def get_entra_auth_token( - credential: "ChainedTokenCredential", + credential: "TokenCredential", token_endpoint: str, **kwargs: Any, ) -> str | None: @@ -25,7 +25,6 @@ def get_entra_auth_token( Args: credential: The Azure credential to use for authentication. - for dev, you can use `DefaultAzureCredential`, but this is not recommended for production. token_endpoint: The token endpoint to use to retrieve the authentication token. **kwargs: Additional keyword arguments to pass to the token retrieval method. @@ -47,7 +46,7 @@ def get_entra_auth_token( async def get_entra_auth_token_async( - credential: "AsyncChainedTokenCredential", token_endpoint: str, **kwargs: Any + credential: "AsyncTokenCredential", token_endpoint: str, **kwargs: Any ) -> str | None: """Retrieve a async Microsoft Entra Auth Token for a given token endpoint. @@ -56,7 +55,6 @@ async def get_entra_auth_token_async( Args: credential: The async Azure credential to use for authentication. - for dev, you can use `DefaultAzureCredential`, but this is not recommended for production. token_endpoint: The token endpoint to use to retrieve the authentication token. **kwargs: Additional keyword arguments to pass to the token retrieval method. diff --git a/python/packages/azure/agent_framework_azure/_responses_client.py b/python/packages/azure/agent_framework_azure/_responses_client.py index 0aec8fbc19..4131a1153b 100644 --- a/python/packages/azure/agent_framework_azure/_responses_client.py +++ b/python/packages/azure/agent_framework_azure/_responses_client.py @@ -8,7 +8,7 @@ from agent_framework import use_tool_calling from agent_framework.exceptions import ServiceInitializationError from agent_framework.openai._responses_client import OpenAIResponsesClientBase from agent_framework.telemetry import use_telemetry -from azure.identity import ChainedTokenCredential +from azure.core.credentials import TokenCredential from openai.lib.azure import AsyncAzureADTokenProvider, AsyncAzureOpenAI from pydantic import SecretStr, ValidationError from pydantic.networks import AnyUrl @@ -36,7 +36,7 @@ class AzureResponsesClient(AzureOpenAIConfigBase, OpenAIResponsesClientBase): ad_token: str | None = None, ad_token_provider: AsyncAzureADTokenProvider | None = None, token_endpoint: str | None = None, - ad_credential: ChainedTokenCredential | None = None, + credential: TokenCredential | None = None, default_headers: Mapping[str, str] | None = None, async_client: AsyncAzureOpenAI | None = None, env_file_path: str | None = None, @@ -59,7 +59,7 @@ class AzureResponsesClient(AzureOpenAIConfigBase, OpenAIResponsesClientBase): ad_token: The Azure Active Directory token. (Optional) ad_token_provider: The Azure Active Directory token provider. (Optional) token_endpoint: The token endpoint to request an Azure token. (Optional) - ad_credential: The Azure Active Directory credential. (Optional) + credential: The Azure credential for authentication. (Optional) default_headers: The default headers mapping of string keys to string values for HTTP requests. (Optional) async_client: An existing client to use. (Optional) @@ -107,7 +107,7 @@ class AzureResponsesClient(AzureOpenAIConfigBase, OpenAIResponsesClientBase): ad_token=ad_token, ad_token_provider=ad_token_provider, token_endpoint=azure_openai_settings.token_endpoint, - ad_credential=ad_credential, + credential=credential, default_headers=default_headers, client=async_client, instruction_role=instruction_role, diff --git a/python/packages/azure/agent_framework_azure/_shared.py b/python/packages/azure/agent_framework_azure/_shared.py index 05e9e01920..f5326b2bad 100644 --- a/python/packages/azure/agent_framework_azure/_shared.py +++ b/python/packages/azure/agent_framework_azure/_shared.py @@ -10,7 +10,7 @@ from agent_framework._pydantic import AFBaseSettings, HttpsUrl from agent_framework.exceptions import ServiceInitializationError from agent_framework.openai._shared import OpenAIHandler from agent_framework.telemetry import USER_AGENT_KEY -from azure.identity import ChainedTokenCredential +from azure.core.credentials import TokenCredential from openai.lib.azure import AsyncAzureOpenAI from pydantic import ConfigDict, SecretStr, model_validator, validate_call @@ -135,7 +135,7 @@ class AzureOpenAISettings(AFBaseSettings): default_token_endpoint: str = DEFAULT_AZURE_TOKEN_ENDPOINT def get_azure_auth_token( - self, credential: "ChainedTokenCredential", token_endpoint: str | None = None, **kwargs: Any + self, credential: "TokenCredential", token_endpoint: str | None = None, **kwargs: Any ) -> str | None: """Retrieve a Microsoft Entra Auth Token for a given token endpoint for the use with Azure OpenAI. @@ -181,7 +181,7 @@ class AzureOpenAIConfigBase(OpenAIHandler): ad_token: str | None = None, ad_token_provider: Callable[[], str | Awaitable[str]] | None = None, token_endpoint: str | None = None, - ad_credential: ChainedTokenCredential | None = None, + credential: TokenCredential | None = None, default_headers: Mapping[str, str] | None = None, client: AsyncAzureOpenAI | None = None, instruction_role: str | None = None, @@ -202,7 +202,7 @@ class AzureOpenAIConfigBase(OpenAIHandler): ad_token: Azure AD token for authentication. ad_token_provider: A callable or coroutine function providing Azure AD tokens. token_endpoint: Azure AD token endpoint use to get the token. - ad_credential: Azure AD credential for authentication. + credential: Azure credential for authentication. default_headers: Default headers for HTTP requests. client: An existing client to use. instruction_role: The role to use for 'instruction' messages, for example, summarization @@ -217,8 +217,8 @@ class AzureOpenAIConfigBase(OpenAIHandler): # 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 # settings. - if not api_key and not ad_token_provider and not ad_token and token_endpoint and ad_credential: - ad_token = get_entra_auth_token(ad_credential, token_endpoint) + 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) if not api_key and not ad_token and not ad_token_provider: raise ServiceInitializationError( diff --git a/python/packages/azure/tests/test_azure_assistants_client.py b/python/packages/azure/tests/test_azure_assistants_client.py index 45372664b0..d4867abaf6 100644 --- a/python/packages/azure/tests/test_azure_assistants_client.py +++ b/python/packages/azure/tests/test_azure_assistants_client.py @@ -13,7 +13,7 @@ from agent_framework import ( TextContent, ) from agent_framework.exceptions import ServiceInitializationError -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field from agent_framework_azure import AzureAssistantsClient @@ -260,7 +260,7 @@ def get_weather( @skip_if_azure_integration_tests_disabled async def test_azure_assistants_client_get_response() -> None: """Test Azure Assistants Client response.""" - async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as azure_assistants_client: + async with AzureAssistantsClient(credential=AzureCliCredential()) as azure_assistants_client: assert isinstance(azure_assistants_client, ChatClient) messages: list[ChatMessage] = [] @@ -284,7 +284,7 @@ async def test_azure_assistants_client_get_response() -> None: @skip_if_azure_integration_tests_disabled async def test_azure_assistants_client_get_response_tools() -> None: """Test Azure Assistants Client response with tools.""" - async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as azure_assistants_client: + async with AzureAssistantsClient(credential=AzureCliCredential()) as azure_assistants_client: assert isinstance(azure_assistants_client, ChatClient) messages: list[ChatMessage] = [] @@ -305,7 +305,7 @@ async def test_azure_assistants_client_get_response_tools() -> None: @skip_if_azure_integration_tests_disabled async def test_azure_assistants_client_streaming() -> None: """Test Azure Assistants Client streaming response.""" - async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as azure_assistants_client: + async with AzureAssistantsClient(credential=AzureCliCredential()) as azure_assistants_client: assert isinstance(azure_assistants_client, ChatClient) messages: list[ChatMessage] = [] @@ -335,7 +335,7 @@ async def test_azure_assistants_client_streaming() -> None: @skip_if_azure_integration_tests_disabled async def test_azure_assistants_client_streaming_tools() -> None: """Test Azure Assistants Client streaming response with tools.""" - async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as azure_assistants_client: + async with AzureAssistantsClient(credential=AzureCliCredential()) as azure_assistants_client: assert isinstance(azure_assistants_client, ChatClient) messages: list[ChatMessage] = [] @@ -362,7 +362,7 @@ async def test_azure_assistants_client_streaming_tools() -> None: async def test_azure_assistants_client_with_existing_assistant() -> None: """Test Azure Assistants Client with existing assistant ID.""" # First create an assistant to use in the test - async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as temp_client: + async with AzureAssistantsClient(credential=AzureCliCredential()) as temp_client: # Get the assistant ID by triggering assistant creation messages = [ChatMessage(role="user", text="Hello")] await temp_client.get_response(messages=messages) @@ -370,7 +370,7 @@ async def test_azure_assistants_client_with_existing_assistant() -> None: # Now test using the existing assistant async with AzureAssistantsClient( - assistant_id=assistant_id, ad_credential=DefaultAzureCredential() + assistant_id=assistant_id, credential=AzureCliCredential() ) as azure_assistants_client: assert isinstance(azure_assistants_client, ChatClient) assert azure_assistants_client.assistant_id == assistant_id @@ -386,7 +386,7 @@ async def test_azure_assistants_client_with_existing_assistant() -> None: def test_azure_assistants_client_entra_id_authentication() -> None: - """Test Entra ID authentication path with ad_credential.""" + """Test Entra ID authentication path with credential.""" mock_credential = MagicMock() with ( @@ -408,7 +408,7 @@ def test_azure_assistants_client_entra_id_authentication() -> None: deployment_name="test-deployment", api_key="placeholder-key", endpoint="https://test-endpoint.openai.azure.com", - ad_credential=mock_credential, + credential=mock_credential, token_endpoint="https://login.microsoftonline.com/test", ) diff --git a/python/packages/azure/tests/test_azure_chat_client.py b/python/packages/azure/tests/test_azure_chat_client.py index f4d30972e1..e75b401eaf 100644 --- a/python/packages/azure/tests/test_azure_chat_client.py +++ b/python/packages/azure/tests/test_azure_chat_client.py @@ -21,7 +21,7 @@ from agent_framework.openai import ( OpenAIContentFilterException, ) from agent_framework.telemetry import USER_AGENT_KEY -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from httpx import Request, Response from openai import AsyncAzureOpenAI, AsyncStream from openai.resources.chat.completions import AsyncCompletions as AsyncChatCompletions @@ -601,7 +601,7 @@ def get_story_text() -> str: @skip_if_azure_integration_tests_disabled async def test_azure_openai_chat_client_response() -> None: """Test Azure OpenAI chat completion responses.""" - azure_chat_client = AzureChatClient(ad_credential=DefaultAzureCredential()) + azure_chat_client = AzureChatClient(credential=AzureCliCredential()) assert isinstance(azure_chat_client, ChatClient) messages: list[ChatMessage] = [] @@ -627,7 +627,7 @@ async def test_azure_openai_chat_client_response() -> None: @skip_if_azure_integration_tests_disabled async def test_azure_openai_chat_client_response_tools() -> None: """Test AzureOpenAI chat completion responses.""" - azure_chat_client = AzureChatClient(ad_credential=DefaultAzureCredential()) + azure_chat_client = AzureChatClient(credential=AzureCliCredential()) assert isinstance(azure_chat_client, ChatClient) messages: list[ChatMessage] = [] @@ -648,7 +648,7 @@ async def test_azure_openai_chat_client_response_tools() -> None: @skip_if_azure_integration_tests_disabled async def test_azure_openai_chat_client_streaming() -> None: """Test Azure OpenAI chat completion responses.""" - azure_chat_client = AzureChatClient(ad_credential=DefaultAzureCredential()) + azure_chat_client = AzureChatClient(credential=AzureCliCredential()) assert isinstance(azure_chat_client, ChatClient) messages: list[ChatMessage] = [] @@ -680,7 +680,7 @@ async def test_azure_openai_chat_client_streaming() -> None: @skip_if_azure_integration_tests_disabled async def test_azure_openai_chat_client_streaming_tools() -> None: """Test AzureOpenAI chat completion responses.""" - azure_chat_client = AzureChatClient(ad_credential=DefaultAzureCredential()) + azure_chat_client = AzureChatClient(credential=AzureCliCredential()) assert isinstance(azure_chat_client, ChatClient) messages: list[ChatMessage] = [] diff --git a/python/packages/azure/tests/test_azure_responses_client.py b/python/packages/azure/tests/test_azure_responses_client.py index acd37b4a61..2ac4897da8 100644 --- a/python/packages/azure/tests/test_azure_responses_client.py +++ b/python/packages/azure/tests/test_azure_responses_client.py @@ -14,7 +14,7 @@ from agent_framework import ( ) from agent_framework.azure import AzureResponsesClient from agent_framework.exceptions import ServiceInitializationError -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import BaseModel skip_if_azure_integration_tests_disabled = pytest.mark.skipif( @@ -112,7 +112,7 @@ def test_serialize(azure_openai_unit_test_env: dict[str, str]) -> None: @skip_if_azure_integration_tests_disabled async def test_azure_responses_client_response() -> None: """Test azure responses client responses.""" - azure_responses_client = AzureResponsesClient(ad_credential=DefaultAzureCredential()) + azure_responses_client = AzureResponsesClient(credential=AzureCliCredential()) assert isinstance(azure_responses_client, ChatClient) @@ -155,7 +155,7 @@ async def test_azure_responses_client_response() -> None: @skip_if_azure_integration_tests_disabled async def test_azure_responses_client_response_tools() -> None: """Test azure responses client tools.""" - azure_responses_client = AzureResponsesClient(ad_credential=DefaultAzureCredential()) + azure_responses_client = AzureResponsesClient(credential=AzureCliCredential()) assert isinstance(azure_responses_client, ChatClient) @@ -194,7 +194,7 @@ async def test_azure_responses_client_response_tools() -> None: @skip_if_azure_integration_tests_disabled async def test_azure_responses_client_streaming() -> None: """Test Azure azure responses client streaming responses.""" - azure_responses_client = AzureResponsesClient(ad_credential=DefaultAzureCredential()) + azure_responses_client = AzureResponsesClient(credential=AzureCliCredential()) assert isinstance(azure_responses_client, ChatClient) @@ -244,7 +244,7 @@ async def test_azure_responses_client_streaming() -> None: @skip_if_azure_integration_tests_disabled async def test_azure_responses_client_streaming_tools() -> None: """Test azure responses client streaming tools.""" - azure_responses_client = AzureResponsesClient(ad_credential=DefaultAzureCredential()) + azure_responses_client = AzureResponsesClient(credential=AzureCliCredential()) assert isinstance(azure_responses_client, ChatClient) diff --git a/python/packages/azure/tests/test_entra_id_authentication.py b/python/packages/azure/tests/test_entra_id_authentication.py index 5b894fce06..949e2a70be 100644 --- a/python/packages/azure/tests/test_entra_id_authentication.py +++ b/python/packages/azure/tests/test_entra_id_authentication.py @@ -14,7 +14,7 @@ from agent_framework_azure._entra_id_authentication import ( @pytest.fixture def mock_credential() -> MagicMock: - """Mock synchronous ChainedTokenCredential.""" + """Mock synchronous TokenCredential.""" mock_cred = MagicMock() # Create a mock token object with a .token attribute mock_token = MagicMock() @@ -25,7 +25,7 @@ def mock_credential() -> MagicMock: @pytest.fixture def mock_async_credential() -> MagicMock: - """Mock asynchronous ChainedTokenCredential.""" + """Mock asynchronous AsyncTokenCredential.""" mock_cred = MagicMock() # Create a mock token object with a .token attribute mock_token = MagicMock() diff --git a/python/packages/foundry/agent_framework_foundry/_chat_client.py b/python/packages/foundry/agent_framework_foundry/_chat_client.py index 9c7739ff86..a3e55be440 100644 --- a/python/packages/foundry/agent_framework_foundry/_chat_client.py +++ b/python/packages/foundry/agent_framework_foundry/_chat_client.py @@ -120,7 +120,7 @@ class FoundryChatClient(ChatClientBase): thread_id: str | None = None, project_endpoint: str | None = None, model_deployment_name: str | None = None, - async_ad_credential: AsyncTokenCredential | None = None, + async_credential: AsyncTokenCredential | None = None, env_file_path: str | None = None, env_file_encoding: str | None = None, **kwargs: Any, @@ -137,7 +137,7 @@ class FoundryChatClient(ChatClientBase): conversation_id property, when making a request. project_endpoint: The Azure AI Foundry project endpoint URL. Used if client is not provided. model_deployment_name: The model deployment name to use for agent creation. - async_ad_credential: Azure async credential to use for authentication. + async_credential: Azure async credential to use for authentication. env_file_path: Path to environment file for loading settings. env_file_encoding: Encoding of the environment file. **kwargs: Additional keyword arguments passed to the parent class. @@ -162,15 +162,15 @@ class FoundryChatClient(ChatClientBase): if agent_id is None and not foundry_settings.model_deployment_name: raise ServiceInitializationError("Model deployment name is required for agent creation.") - # Use provided credential or fallback to DefaultAzureCredential - if not async_ad_credential: + # Use provided credential + if not async_credential: raise ServiceInitializationError("Azure AD credential is required when client is not provided.") - client = AIProjectClient(endpoint=foundry_settings.project_endpoint, credential=async_ad_credential) + client = AIProjectClient(endpoint=foundry_settings.project_endpoint, credential=async_credential) should_close_client = True super().__init__( client=client, # type: ignore[reportCallIssue] - credential=async_ad_credential, # type: ignore[reportCallIssue] + credential=async_credential, # type: ignore[reportCallIssue] agent_id=agent_id, # type: ignore[reportCallIssue] thread_id=thread_id, # type: ignore[reportCallIssue] agent_name=foundry_settings.agent_name, # type: ignore[reportCallIssue] diff --git a/python/packages/foundry/tests/test_foundry_chat_client.py b/python/packages/foundry/tests/test_foundry_chat_client.py index 5f04b48caf..02cca83960 100644 --- a/python/packages/foundry/tests/test_foundry_chat_client.py +++ b/python/packages/foundry/tests/test_foundry_chat_client.py @@ -24,7 +24,7 @@ from azure.ai.agents.models import ( ThreadRun, ) from azure.core.credentials_async import AsyncTokenCredential -from azure.identity.aio import DefaultAzureCredential +from azure.identity.aio import AzureCliCredential from pydantic import Field, ValidationError from agent_framework_foundry import FoundryChatClient, FoundrySettings @@ -133,7 +133,7 @@ def test_foundry_chat_client_init_missing_project_endpoint() -> None: agent_id=None, project_endpoint=None, # Missing endpoint model_deployment_name="test-model", - async_ad_credential=AsyncMock(spec=AsyncTokenCredential), + async_credential=AsyncMock(spec=AsyncTokenCredential), ) @@ -153,7 +153,7 @@ def test_foundry_chat_client_init_missing_model_deployment_for_agent_creation() agent_id=None, # No existing agent project_endpoint="https://test.com", model_deployment_name=None, # Missing for agent creation - async_ad_credential=AsyncMock(spec=AsyncTokenCredential), + async_credential=AsyncMock(spec=AsyncTokenCredential), ) @@ -187,14 +187,14 @@ def test_foundry_chat_client_from_dict(mock_ai_project_client: MagicMock) -> Non def test_foundry_chat_client_init_missing_credential(foundry_unit_test_env: dict[str, str]) -> None: - """Test FoundryChatClient.__init__ when async_ad_credential is missing and no client provided.""" + """Test FoundryChatClient.__init__ when async_credential is missing and no client provided.""" with pytest.raises(ServiceInitializationError, match="Azure AD credential is required when client is not provided"): FoundryChatClient( client=None, agent_id="existing-agent", project_endpoint=foundry_unit_test_env["FOUNDRY_PROJECT_ENDPOINT"], model_deployment_name=foundry_unit_test_env["FOUNDRY_MODEL_DEPLOYMENT_NAME"], - async_ad_credential=None, # Missing credential + async_credential=None, # Missing credential ) @@ -208,7 +208,7 @@ def test_foundry_chat_client_init_validation_error(mock_azure_credential: MagicM FoundryChatClient( project_endpoint="https://test.com", model_deployment_name="test-model", - async_ad_credential=mock_azure_credential, + async_credential=mock_azure_credential, ) @@ -662,7 +662,7 @@ def get_weather( @skip_if_foundry_integration_tests_disabled async def test_foundry_chat_client_get_response() -> None: """Test Foundry Chat Client response.""" - async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as foundry_chat_client: + async with FoundryChatClient(async_credential=AzureCliCredential()) as foundry_chat_client: assert isinstance(foundry_chat_client, ChatClient) messages: list[ChatMessage] = [] @@ -686,7 +686,7 @@ async def test_foundry_chat_client_get_response() -> None: @skip_if_foundry_integration_tests_disabled async def test_foundry_chat_client_get_response_tools() -> None: """Test Foundry Chat Client response with tools.""" - async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as foundry_chat_client: + async with FoundryChatClient(async_credential=AzureCliCredential()) as foundry_chat_client: assert isinstance(foundry_chat_client, ChatClient) messages: list[ChatMessage] = [] @@ -707,7 +707,7 @@ async def test_foundry_chat_client_get_response_tools() -> None: @skip_if_foundry_integration_tests_disabled async def test_foundry_chat_client_streaming() -> None: """Test Foundry Chat Client streaming response.""" - async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as foundry_chat_client: + async with FoundryChatClient(async_credential=AzureCliCredential()) as foundry_chat_client: assert isinstance(foundry_chat_client, ChatClient) messages: list[ChatMessage] = [] @@ -737,7 +737,7 @@ async def test_foundry_chat_client_streaming() -> None: @skip_if_foundry_integration_tests_disabled async def test_foundry_chat_client_streaming_tools() -> None: """Test Foundry Chat Client streaming response with tools.""" - async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as foundry_chat_client: + async with FoundryChatClient(async_credential=AzureCliCredential()) as foundry_chat_client: assert isinstance(foundry_chat_client, ChatClient) messages: list[ChatMessage] = [] diff --git a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_basic.py b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_basic.py index 1c5cc77630..cf60658490 100644 --- a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_basic.py +++ b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_basic.py @@ -5,7 +5,7 @@ from random import randint from typing import Annotated from agent_framework.azure import AzureAssistantsClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -23,7 +23,9 @@ async def non_streaming_example() -> None: # Since no assistant ID is provided, the assistant will be automatically created # and deleted after getting a response - async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()).create_agent( + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + async with AzureAssistantsClient(credential=AzureCliCredential()).create_agent( instructions="You are a helpful weather agent.", tools=get_weather, ) as agent: @@ -39,7 +41,7 @@ async def streaming_example() -> None: # Since no assistant ID is provided, the assistant will be automatically created # and deleted after getting a response - async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()).create_agent( + async with AzureAssistantsClient(credential=AzureCliCredential()).create_agent( instructions="You are a helpful weather agent.", tools=get_weather, ) as agent: diff --git a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_code_interpreter.py b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_code_interpreter.py index 6f75436f5c..2a5def83d2 100644 --- a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_code_interpreter.py +++ b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_code_interpreter.py @@ -4,7 +4,7 @@ import asyncio from agent_framework import AgentRunResponseUpdate, ChatClientAgent, ChatResponseUpdate, HostedCodeInterpreterTool from agent_framework.azure import AzureAssistantsClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from openai.types.beta.threads.runs import ( CodeInterpreterToolCallDelta, RunStepDelta, @@ -37,8 +37,10 @@ async def main() -> None: """Example showing how to use the HostedCodeInterpreterTool with Azure OpenAI Assistants.""" print("=== Azure OpenAI Assistants Agent with Code Interpreter Example ===") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ChatClientAgent( - chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureAssistantsClient(credential=AzureCliCredential()), instructions="You are a helpful assistant that can write and execute Python code to solve problems.", tools=HostedCodeInterpreterTool(), ) as agent: diff --git a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_existing_assistant.py b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_existing_assistant.py index 4dc6ab6261..a5d0fb79c9 100644 --- a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_existing_assistant.py +++ b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_existing_assistant.py @@ -7,7 +7,7 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.azure import AzureAssistantsClient -from azure.identity import DefaultAzureCredential, get_bearer_token_provider +from azure.identity import AzureCliCredential, get_bearer_token_provider from openai import AsyncAzureOpenAI from pydantic import Field @@ -23,7 +23,7 @@ def get_weather( async def main() -> None: print("=== Azure OpenAI Assistants Chat Client with Existing Assistant ===") - token_provider = get_bearer_token_provider(DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default") + token_provider = get_bearer_token_provider(AzureCliCredential(), "https://cognitiveservices.azure.com/.default") client = AsyncAzureOpenAI( azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"], diff --git a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_function_tools.py b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_function_tools.py index 25c4308b16..b71d351472 100644 --- a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_function_tools.py +++ b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_function_tools.py @@ -7,7 +7,7 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.azure import AzureAssistantsClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -31,8 +31,10 @@ async def tools_on_agent_level() -> None: # Tools are provided when creating the agent # The agent can use these tools for any query during its lifetime + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ChatClientAgent( - chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureAssistantsClient(credential=AzureCliCredential()), instructions="You are a helpful assistant that can provide weather and time information.", tools=[get_weather, get_time], # Tools defined at agent creation ) as agent: @@ -60,8 +62,10 @@ async def tools_on_run_level() -> None: print("=== Tools Passed to Run Method ===") # Agent created without tools + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ChatClientAgent( - chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureAssistantsClient(credential=AzureCliCredential()), instructions="You are a helpful assistant.", # No tools defined here ) as agent: @@ -89,8 +93,10 @@ async def mixed_tools_example() -> None: print("=== Mixed Tools Example (Agent + Run Method) ===") # Agent created with some base tools + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ChatClientAgent( - chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureAssistantsClient(credential=AzureCliCredential()), instructions="You are a comprehensive assistant that can help with various information requests.", tools=[get_weather], # Base tool available for all queries ) as agent: diff --git a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_thread.py b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_thread.py index 2f79c007e2..a984e4aaf4 100644 --- a/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_thread.py +++ b/python/samples/getting_started/agents/azure_assistants_client/azure_assistants_with_thread.py @@ -6,7 +6,7 @@ from typing import Annotated from agent_framework import AgentThread, ChatClientAgent from agent_framework.azure import AzureAssistantsClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -22,8 +22,10 @@ async def example_with_automatic_thread_creation() -> None: """Example showing automatic thread creation (service-managed thread).""" print("=== Automatic Thread Creation Example ===") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ChatClientAgent( - chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureAssistantsClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent: @@ -46,8 +48,10 @@ async def example_with_thread_persistence() -> None: print("=== Thread Persistence Example ===") print("Using the same thread across multiple conversations to maintain context.\n") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ChatClientAgent( - chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureAssistantsClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent: @@ -82,8 +86,10 @@ async def example_with_existing_thread_id() -> None: # First, create a conversation and capture the thread ID existing_thread_id = None + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ChatClientAgent( - chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureAssistantsClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent: @@ -103,7 +109,7 @@ async def example_with_existing_thread_id() -> None: # Create a new agent instance but use the existing thread ID async with ChatClientAgent( - chat_client=AzureAssistantsClient(thread_id=existing_thread_id, ad_credential=DefaultAzureCredential()), + chat_client=AzureAssistantsClient(thread_id=existing_thread_id, credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent: diff --git a/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_basic.py b/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_basic.py index e607bb5c35..0ed2301d40 100644 --- a/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_basic.py +++ b/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_basic.py @@ -5,7 +5,7 @@ from random import randint from typing import Annotated from agent_framework.azure import AzureChatClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -22,7 +22,9 @@ async def non_streaming_example() -> None: print("=== Non-streaming Response Example ===") # Create agent with Azure Chat Client - agent = AzureChatClient(ad_credential=DefaultAzureCredential()).create_agent( + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + agent = AzureChatClient(credential=AzureCliCredential()).create_agent( instructions="You are a helpful weather agent.", tools=get_weather, ) @@ -38,7 +40,9 @@ async def streaming_example() -> None: print("=== Streaming Response Example ===") # Create agent with Azure Chat Client - agent = AzureChatClient(ad_credential=DefaultAzureCredential()).create_agent( + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + agent = AzureChatClient(credential=AzureCliCredential()).create_agent( instructions="You are a helpful weather agent.", tools=get_weather, ) diff --git a/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_with_function_tools.py b/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_with_function_tools.py index a5fcdbb852..25e0c8785b 100644 --- a/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_with_function_tools.py +++ b/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_with_function_tools.py @@ -7,7 +7,7 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.azure import AzureChatClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -31,8 +31,10 @@ async def tools_on_agent_level() -> None: # Tools are provided when creating the agent # The agent can use these tools for any query during its lifetime + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureChatClient(credential=AzureCliCredential()), instructions="You are a helpful assistant that can provide weather and time information.", tools=[get_weather, get_time], # Tools defined at agent creation ) @@ -61,8 +63,10 @@ async def tools_on_run_level() -> None: print("=== Tools Passed to Run Method ===") # Agent created without tools + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureChatClient(credential=AzureCliCredential()), instructions="You are a helpful assistant.", # No tools defined here ) @@ -91,8 +95,10 @@ async def mixed_tools_example() -> None: print("=== Mixed Tools Example (Agent + Run Method) ===") # Agent created with some base tools + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureChatClient(credential=AzureCliCredential()), instructions="You are a comprehensive assistant that can help with various information requests.", tools=[get_weather], # Base tool available for all queries ) diff --git a/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_with_thread.py b/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_with_thread.py index e9f26a820b..9bd3a96b5e 100644 --- a/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_with_thread.py +++ b/python/samples/getting_started/agents/azure_chat_client/azure_chat_client_with_thread.py @@ -6,7 +6,7 @@ from typing import Annotated from agent_framework import AgentThread, ChatClientAgent, ChatMessageList from agent_framework.azure import AzureChatClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -22,8 +22,10 @@ async def example_with_automatic_thread_creation() -> None: """Example showing automatic thread creation (service-managed thread).""" print("=== Automatic Thread Creation Example ===") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureChatClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) @@ -47,8 +49,10 @@ async def example_with_thread_persistence() -> None: print("=== Thread Persistence Example ===") print("Using the same thread across multiple conversations to maintain context.\n") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureChatClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) @@ -80,8 +84,10 @@ async def example_with_existing_thread_messages() -> None: """Example showing how to work with existing thread messages for Azure.""" print("=== Existing Thread Messages Example ===") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureChatClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) @@ -104,7 +110,7 @@ async def example_with_existing_thread_messages() -> None: # Create a new agent instance but use the existing thread with its message history new_agent = ChatClientAgent( - chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureChatClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) diff --git a/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_basic.py b/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_basic.py index 9520e56498..41a9eb89ff 100644 --- a/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_basic.py +++ b/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_basic.py @@ -5,7 +5,7 @@ from random import randint from typing import Annotated from agent_framework.azure import AzureResponsesClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -21,7 +21,9 @@ async def non_streaming_example() -> None: """Example of non-streaming response (get the complete result at once).""" print("=== Non-streaming Response Example ===") - agent = AzureResponsesClient(ad_credential=DefaultAzureCredential()).create_agent( + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + agent = AzureResponsesClient(credential=AzureCliCredential()).create_agent( instructions="You are a helpful weather agent.", tools=get_weather, ) @@ -36,7 +38,9 @@ async def streaming_example() -> None: """Example of streaming response (get results as they are generated).""" print("=== Streaming Response Example ===") - agent = AzureResponsesClient(ad_credential=DefaultAzureCredential()).create_agent( + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + agent = AzureResponsesClient(credential=AzureCliCredential()).create_agent( instructions="You are a helpful weather agent.", tools=get_weather, ) diff --git a/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_code_interpreter.py b/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_code_interpreter.py index 6ea16bbb71..4a9a709418 100644 --- a/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_code_interpreter.py +++ b/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_code_interpreter.py @@ -4,7 +4,7 @@ import asyncio from agent_framework import ChatClientAgent, ChatResponse, HostedCodeInterpreterTool from agent_framework.azure import AzureResponsesClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from openai.types.responses.response import Response as OpenAIResponse from openai.types.responses.response_code_interpreter_tool_call import ResponseCodeInterpreterToolCall @@ -13,8 +13,10 @@ async def main() -> None: """Example showing how to use the HostedCodeInterpreterTool with Azure OpenAI Responses.""" print("=== Azure OpenAI Responses Agent with Code Interpreter Example ===") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureResponsesClient(credential=AzureCliCredential()), instructions="You are a helpful assistant that can write and execute Python code to solve problems.", tools=HostedCodeInterpreterTool(), ) diff --git a/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_function_tools.py b/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_function_tools.py index d0739dbfae..e7f4847d90 100644 --- a/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_function_tools.py +++ b/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_function_tools.py @@ -7,7 +7,7 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.azure import AzureResponsesClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -31,8 +31,10 @@ async def tools_on_agent_level() -> None: # Tools are provided when creating the agent # The agent can use these tools for any query during its lifetime + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureResponsesClient(credential=AzureCliCredential()), instructions="You are a helpful assistant that can provide weather and time information.", tools=[get_weather, get_time], # Tools defined at agent creation ) @@ -61,8 +63,10 @@ async def tools_on_run_level() -> None: print("=== Tools Passed to Run Method ===") # Agent created without tools + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureResponsesClient(credential=AzureCliCredential()), instructions="You are a helpful assistant.", # No tools defined here ) @@ -91,8 +95,10 @@ async def mixed_tools_example() -> None: print("=== Mixed Tools Example (Agent + Run Method) ===") # Agent created with some base tools + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureResponsesClient(credential=AzureCliCredential()), instructions="You are a comprehensive assistant that can help with various information requests.", tools=[get_weather], # Base tool available for all queries ) diff --git a/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_thread.py b/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_thread.py index e8ae1aa3d4..c16ce497a0 100644 --- a/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_thread.py +++ b/python/samples/getting_started/agents/azure_responses_client/azure_responses_client_with_thread.py @@ -6,7 +6,7 @@ from typing import Annotated from agent_framework import AgentThread, ChatClientAgent from agent_framework.azure import AzureResponsesClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -22,8 +22,10 @@ async def example_with_automatic_thread_creation() -> None: """Example showing automatic thread creation.""" print("=== Automatic Thread Creation Example ===") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureResponsesClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) @@ -49,8 +51,10 @@ async def example_with_thread_persistence_in_memory() -> None: """ print("=== Thread Persistence Example (In-Memory) ===") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureResponsesClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) @@ -91,8 +95,10 @@ async def example_with_existing_thread_id() -> None: # First, create a conversation and capture the thread ID existing_thread_id = None + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. agent = ChatClientAgent( - chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureResponsesClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) @@ -115,7 +121,7 @@ async def example_with_existing_thread_id() -> None: print("\n--- Continuing with the same thread ID in a new agent instance ---") agent = ChatClientAgent( - chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()), + chat_client=AzureResponsesClient(credential=AzureCliCredential()), instructions="You are a helpful weather agent.", tools=get_weather, ) diff --git a/python/samples/getting_started/agents/foundry/foundry_basic.py b/python/samples/getting_started/agents/foundry/foundry_basic.py index ef3d28e0de..cbb9b1a603 100644 --- a/python/samples/getting_started/agents/foundry/foundry_basic.py +++ b/python/samples/getting_started/agents/foundry/foundry_basic.py @@ -5,7 +5,7 @@ from random import randint from typing import Annotated from agent_framework.foundry import FoundryChatClient -from azure.identity.aio import DefaultAzureCredential +from azure.identity.aio import AzureCliCredential from pydantic import Field @@ -23,9 +23,11 @@ async def non_streaming_example() -> None: # Since no Agent ID is provided, the agent will be automatically created # and deleted after getting a response + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, - FoundryChatClient(async_ad_credential=credential).create_agent( + AzureCliCredential() as credential, + FoundryChatClient(async_credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, @@ -43,9 +45,11 @@ async def streaming_example() -> None: # Since no Agent ID is provided, the agent will be automatically created # and deleted after getting a response + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, - FoundryChatClient(async_ad_credential=credential).create_agent( + AzureCliCredential() as credential, + FoundryChatClient(async_credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, diff --git a/python/samples/getting_started/agents/foundry/foundry_with_code_interpreter.py b/python/samples/getting_started/agents/foundry/foundry_with_code_interpreter.py index 869d7fe153..6cf447ed14 100644 --- a/python/samples/getting_started/agents/foundry/foundry_with_code_interpreter.py +++ b/python/samples/getting_started/agents/foundry/foundry_with_code_interpreter.py @@ -11,7 +11,7 @@ from azure.ai.agents.models import ( RunStepDeltaCodeInterpreterToolCall, RunStepDeltaToolCallObject, ) -from azure.identity.aio import DefaultAzureCredential +from azure.identity.aio import AzureCliCredential def get_code_interpreter_chunk(chunk: AgentRunResponseUpdate) -> str | None: @@ -37,10 +37,12 @@ async def main() -> None: """Example showing how to use the HostedCodeInterpreterTool with Foundry.""" print("=== Foundry Agent with Code Interpreter Example ===") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, ChatClientAgent( - chat_client=FoundryChatClient(async_ad_credential=credential), + chat_client=FoundryChatClient(async_credential=credential), instructions="You are a helpful assistant that can write and execute Python code to solve problems.", tools=HostedCodeInterpreterTool(), ) as agent, diff --git a/python/samples/getting_started/agents/foundry/foundry_with_existing_agent.py b/python/samples/getting_started/agents/foundry/foundry_with_existing_agent.py index dce617e113..fa33c61abe 100644 --- a/python/samples/getting_started/agents/foundry/foundry_with_existing_agent.py +++ b/python/samples/getting_started/agents/foundry/foundry_with_existing_agent.py @@ -8,7 +8,7 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.foundry import FoundryChatClient from azure.ai.projects.aio import AIProjectClient -from azure.identity.aio import DefaultAzureCredential +from azure.identity.aio import AzureCliCredential from pydantic import Field @@ -25,7 +25,7 @@ async def main() -> None: # Create the client async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as client, ): # Create an agent that will persist diff --git a/python/samples/getting_started/agents/foundry/foundry_with_explicit_settings.py b/python/samples/getting_started/agents/foundry/foundry_with_explicit_settings.py index 18dc87d8b1..12cf6c797c 100644 --- a/python/samples/getting_started/agents/foundry/foundry_with_explicit_settings.py +++ b/python/samples/getting_started/agents/foundry/foundry_with_explicit_settings.py @@ -7,7 +7,7 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.foundry import FoundryChatClient -from azure.identity.aio import DefaultAzureCredential +from azure.identity.aio import AzureCliCredential from pydantic import Field @@ -24,13 +24,15 @@ async def main() -> None: # Since no Agent ID is provided, the agent will be automatically created # and deleted after getting a response + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, ChatClientAgent( chat_client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], model_deployment_name=os.environ["FOUNDRY_MODEL_DEPLOYMENT_NAME"], - async_ad_credential=credential, + async_credential=credential, agent_name="WeatherAgent", ), instructions="You are a helpful weather agent.", diff --git a/python/samples/getting_started/agents/foundry/foundry_with_function_tools.py b/python/samples/getting_started/agents/foundry/foundry_with_function_tools.py index ac7a7d26cd..c8f52c8911 100644 --- a/python/samples/getting_started/agents/foundry/foundry_with_function_tools.py +++ b/python/samples/getting_started/agents/foundry/foundry_with_function_tools.py @@ -7,7 +7,7 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.foundry import FoundryChatClient -from azure.identity.aio import DefaultAzureCredential +from azure.identity.aio import AzureCliCredential from pydantic import Field @@ -31,10 +31,12 @@ async def tools_on_agent_level() -> None: # Tools are provided when creating the agent # The agent can use these tools for any query during its lifetime + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, ChatClientAgent( - chat_client=FoundryChatClient(async_ad_credential=credential), + chat_client=FoundryChatClient(async_credential=credential), instructions="You are a helpful assistant that can provide weather and time information.", tools=[get_weather, get_time], # Tools defined at agent creation ) as agent, @@ -63,10 +65,12 @@ async def tools_on_run_level() -> None: print("=== Tools Passed to Run Method ===") # Agent created without tools + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, ChatClientAgent( - chat_client=FoundryChatClient(async_ad_credential=credential), + chat_client=FoundryChatClient(async_credential=credential), instructions="You are a helpful assistant.", # No tools defined here ) as agent, @@ -95,10 +99,12 @@ async def mixed_tools_example() -> None: print("=== Mixed Tools Example (Agent + Run Method) ===") # Agent created with some base tools + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, ChatClientAgent( - chat_client=FoundryChatClient(async_ad_credential=credential), + chat_client=FoundryChatClient(async_credential=credential), instructions="You are a comprehensive assistant that can help with various information requests.", tools=[get_weather], # Base tool available for all queries ) as agent, diff --git a/python/samples/getting_started/agents/foundry/foundry_with_thread.py b/python/samples/getting_started/agents/foundry/foundry_with_thread.py index 6a4d9a046f..eac31909cb 100644 --- a/python/samples/getting_started/agents/foundry/foundry_with_thread.py +++ b/python/samples/getting_started/agents/foundry/foundry_with_thread.py @@ -6,7 +6,7 @@ from typing import Annotated from agent_framework import AgentThread, ChatClientAgent from agent_framework.foundry import FoundryChatClient -from azure.identity.aio import DefaultAzureCredential +from azure.identity.aio import AzureCliCredential from pydantic import Field @@ -22,10 +22,12 @@ async def example_with_automatic_thread_creation() -> None: """Example showing automatic thread creation (service-managed thread).""" print("=== Automatic Thread Creation Example ===") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, ChatClientAgent( - chat_client=FoundryChatClient(async_ad_credential=credential), + chat_client=FoundryChatClient(async_credential=credential), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent, @@ -49,10 +51,12 @@ async def example_with_thread_persistence() -> None: print("=== Thread Persistence Example ===") print("Using the same thread across multiple conversations to maintain context.\n") + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, ChatClientAgent( - chat_client=FoundryChatClient(async_ad_credential=credential), + chat_client=FoundryChatClient(async_credential=credential), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent, @@ -88,10 +92,12 @@ async def example_with_existing_thread_id() -> None: # First, create a conversation and capture the thread ID existing_thread_id = None + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, ChatClientAgent( - chat_client=FoundryChatClient(async_ad_credential=credential), + chat_client=FoundryChatClient(async_credential=credential), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent, @@ -112,9 +118,9 @@ async def example_with_existing_thread_id() -> None: # Create a new agent instance but use the existing thread ID async with ( - DefaultAzureCredential() as credential, + AzureCliCredential() as credential, ChatClientAgent( - chat_client=FoundryChatClient(thread_id=existing_thread_id, async_ad_credential=credential), + chat_client=FoundryChatClient(thread_id=existing_thread_id, async_credential=credential), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent, diff --git a/python/samples/getting_started/chat_client/azure_assistants_client.py b/python/samples/getting_started/chat_client/azure_assistants_client.py index 59f9e7d4de..96aef39bea 100644 --- a/python/samples/getting_started/chat_client/azure_assistants_client.py +++ b/python/samples/getting_started/chat_client/azure_assistants_client.py @@ -5,7 +5,7 @@ from random import randint from typing import Annotated from agent_framework.azure import AzureAssistantsClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -18,7 +18,9 @@ def get_weather( async def main() -> None: - async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as client: + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + async with AzureAssistantsClient(credential=AzureCliCredential()) as client: message = "What's the weather in Amsterdam and in Paris?" stream = False print(f"User: {message}") diff --git a/python/samples/getting_started/chat_client/azure_chat_client.py b/python/samples/getting_started/chat_client/azure_chat_client.py index 3f63677bd7..919c3cea14 100644 --- a/python/samples/getting_started/chat_client/azure_chat_client.py +++ b/python/samples/getting_started/chat_client/azure_chat_client.py @@ -5,7 +5,7 @@ from random import randint from typing import Annotated from agent_framework.azure import AzureChatClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import Field @@ -18,7 +18,9 @@ def get_weather( async def main() -> None: - client = AzureChatClient(ad_credential=DefaultAzureCredential()) + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + client = AzureChatClient(credential=AzureCliCredential()) message = "What's the weather in Amsterdam and in Paris?" stream = False print(f"User: {message}") diff --git a/python/samples/getting_started/chat_client/azure_responses_client.py b/python/samples/getting_started/chat_client/azure_responses_client.py index 08df71c48b..46413a1ba1 100644 --- a/python/samples/getting_started/chat_client/azure_responses_client.py +++ b/python/samples/getting_started/chat_client/azure_responses_client.py @@ -6,7 +6,7 @@ from typing import Annotated from agent_framework import ChatResponse from agent_framework.azure import AzureResponsesClient -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential from pydantic import BaseModel, Field @@ -26,7 +26,9 @@ class OutputStruct(BaseModel): async def main() -> None: - client = AzureResponsesClient(ad_credential=DefaultAzureCredential()) + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + client = AzureResponsesClient(credential=AzureCliCredential()) message = "What's the weather in Amsterdam and in Paris?" stream = True print(f"User: {message}") diff --git a/python/samples/getting_started/chat_client/foundry_chat_client.py b/python/samples/getting_started/chat_client/foundry_chat_client.py index a26d91f998..72d1f04c42 100644 --- a/python/samples/getting_started/chat_client/foundry_chat_client.py +++ b/python/samples/getting_started/chat_client/foundry_chat_client.py @@ -5,7 +5,7 @@ from random import randint from typing import Annotated from agent_framework.foundry import FoundryChatClient -from azure.identity.aio import DefaultAzureCredential +from azure.identity.aio import AzureCliCredential from pydantic import Field @@ -18,7 +18,9 @@ def get_weather( async def main() -> None: - async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as client: + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + async with FoundryChatClient(async_credential=AzureCliCredential()) as client: message = "What's the weather in Amsterdam and in Paris?" stream = False print(f"User: {message}") diff --git a/python/samples/getting_started/threads/suspend_resume_thread.py b/python/samples/getting_started/threads/suspend_resume_thread.py index cbb8a9b953..28f445816e 100644 --- a/python/samples/getting_started/threads/suspend_resume_thread.py +++ b/python/samples/getting_started/threads/suspend_resume_thread.py @@ -4,7 +4,7 @@ import asyncio from agent_framework.foundry import FoundryChatClient from agent_framework.openai import OpenAIChatClient -from azure.identity.aio import DefaultAzureCredential +from azure.identity.aio import AzureCliCredential async def suspend_resume_service_managed_thread() -> None: @@ -13,9 +13,11 @@ async def suspend_resume_service_managed_thread() -> None: # Foundry Chat Client is used as an example here, # other chat clients can be used as well. + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. async with ( - DefaultAzureCredential() as credential, - FoundryChatClient(async_ad_credential=credential).create_agent( + AzureCliCredential() as credential, + FoundryChatClient(async_credential=credential).create_agent( name="Joker", instructions="You are good at telling jokes." ) as agent, ): diff --git a/python/samples/getting_started/workflow/step_04_simple_group_chat.py b/python/samples/getting_started/workflow/step_04_simple_group_chat.py index c2e5b29e1a..caa56dec92 100644 --- a/python/samples/getting_started/workflow/step_04_simple_group_chat.py +++ b/python/samples/getting_started/workflow/step_04_simple_group_chat.py @@ -15,7 +15,7 @@ from agent_framework.workflow import ( WorkflowContext, handler, ) -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential """ The following sample demonstrates a basic workflow that simulates @@ -93,7 +93,9 @@ async def main(): """Main function to run the group chat workflow.""" # Step 1: Create the executors. - chat_client = AzureChatClient(ad_credential=DefaultAzureCredential()) + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + chat_client = AzureChatClient(credential=AzureCliCredential()) writer = AgentExecutor( chat_client.create_agent( instructions=( diff --git a/python/samples/getting_started/workflow/step_05_simple_group_chat_with_hil.py b/python/samples/getting_started/workflow/step_05_simple_group_chat_with_hil.py index 5db132a8e0..f6a47dbc23 100644 --- a/python/samples/getting_started/workflow/step_05_simple_group_chat_with_hil.py +++ b/python/samples/getting_started/workflow/step_05_simple_group_chat_with_hil.py @@ -18,7 +18,7 @@ from agent_framework.workflow import ( WorkflowContext, handler, ) -from azure.identity import DefaultAzureCredential +from azure.identity import AzureCliCredential """ The following sample demonstrates a basic workflow that simulates @@ -150,7 +150,9 @@ class CriticGroupChatManager(Executor): async def main(): """Main function to run the group chat workflow.""" # Step 1: Create the executors. - chat_client = AzureChatClient(ad_credential=DefaultAzureCredential()) + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. + chat_client = AzureChatClient(credential=AzureCliCredential()) writer = AgentExecutor( chat_client.create_agent( instructions=(