-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Python: Unify Azure credential handling across all packages #4087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,11 +17,11 @@ | |||||||||
| from agent_framework._mcp import MCPTool | ||||||||||
| from agent_framework._settings import load_settings | ||||||||||
| from agent_framework._tools import ToolTypes | ||||||||||
| from agent_framework.azure._entra_id_authentication import AzureCredentialTypes | ||||||||||
| from agent_framework.exceptions import ServiceInitializationError | ||||||||||
| from azure.ai.agents.aio import AgentsClient | ||||||||||
| from azure.ai.agents.models import Agent as AzureAgent | ||||||||||
| from azure.ai.agents.models import ResponseFormatJsonSchema, ResponseFormatJsonSchemaType | ||||||||||
| from azure.core.credentials_async import AsyncTokenCredential | ||||||||||
| from pydantic import BaseModel | ||||||||||
|
|
||||||||||
| from ._chat_client import AzureAIAgentClient, AzureAIAgentOptions | ||||||||||
|
|
@@ -93,7 +93,7 @@ def __init__( | |||||||||
| agents_client: AgentsClient | None = None, | ||||||||||
| *, | ||||||||||
| project_endpoint: str | None = None, | ||||||||||
| credential: AsyncTokenCredential | None = None, | ||||||||||
| credential: AzureCredentialTypes | None = None, | ||||||||||
| env_file_path: str | None = None, | ||||||||||
| env_file_encoding: str | None = None, | ||||||||||
| ) -> None: | ||||||||||
|
|
@@ -106,7 +106,8 @@ def __init__( | |||||||||
| Keyword Args: | ||||||||||
| project_endpoint: The Azure AI Project endpoint URL. | ||||||||||
| Can also be set via AZURE_AI_PROJECT_ENDPOINT environment variable. | ||||||||||
| credential: Azure async credential for authentication. | ||||||||||
| credential: Azure credential for authentication. Accepts a TokenCredential, | ||||||||||
| AsyncTokenCredential, or a callable token provider. | ||||||||||
|
Comment on lines
+109
to
+110
|
||||||||||
| credential: Azure credential for authentication. Accepts a TokenCredential, | |
| AsyncTokenCredential, or a callable token provider. | |
| credential: Azure credential for authentication. Accepts types compatible with | |
| AzureCredentialTypes (for example, a TokenCredential or AsyncTokenCredential). |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |||||||||
| ) | ||||||||||
| from agent_framework._settings import load_settings | ||||||||||
| from agent_framework._tools import ToolTypes | ||||||||||
| from agent_framework.azure._entra_id_authentication import AzureCredentialTypes | ||||||||||
| from agent_framework.exceptions import ServiceInitializationError, ServiceInvalidRequestError, ServiceResponseException | ||||||||||
| from agent_framework.observability import ChatTelemetryLayer | ||||||||||
| from azure.ai.agents.aio import AgentsClient | ||||||||||
|
|
@@ -84,7 +85,6 @@ | |||||||||
| ToolDefinition, | ||||||||||
| ToolOutput, | ||||||||||
| ) | ||||||||||
| from azure.core.credentials_async import AsyncTokenCredential | ||||||||||
| from pydantic import BaseModel | ||||||||||
|
|
||||||||||
| from ._shared import AzureAISettings, to_azure_ai_agent_tools | ||||||||||
|
|
@@ -415,7 +415,7 @@ def __init__( | |||||||||
| thread_id: str | None = None, | ||||||||||
| project_endpoint: str | None = None, | ||||||||||
| model_deployment_name: str | None = None, | ||||||||||
| credential: AsyncTokenCredential | None = None, | ||||||||||
| credential: AzureCredentialTypes | None = None, | ||||||||||
| should_cleanup_agent: bool = True, | ||||||||||
| middleware: Sequence[ChatAndFunctionMiddlewareTypes] | None = None, | ||||||||||
| function_invocation_configuration: FunctionInvocationConfiguration | None = None, | ||||||||||
|
|
@@ -439,7 +439,8 @@ def __init__( | |||||||||
| Ignored when a agents_client is passed. | ||||||||||
| model_deployment_name: The model deployment name to use for agent creation. | ||||||||||
| Can also be set via environment variable AZURE_AI_MODEL_DEPLOYMENT_NAME. | ||||||||||
| credential: Azure async credential to use for authentication. | ||||||||||
| credential: Azure credential for authentication. Accepts a TokenCredential, | ||||||||||
| AsyncTokenCredential, or a callable token provider. | ||||||||||
|
Comment on lines
+442
to
+443
|
||||||||||
| credential: Azure credential for authentication. Accepts a TokenCredential, | |
| AsyncTokenCredential, or a callable token provider. | |
| credential: Azure credential for authentication. Accepts a TokenCredential | |
| or AsyncTokenCredential. |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |||||||||
| ) | ||||||||||
| from agent_framework._settings import load_settings | ||||||||||
| from agent_framework._tools import ToolTypes | ||||||||||
| from agent_framework.azure._entra_id_authentication import AzureCredentialTypes | ||||||||||
| from agent_framework.exceptions import ServiceInitializationError | ||||||||||
| from agent_framework.observability import ChatTelemetryLayer | ||||||||||
| from agent_framework.openai import OpenAIResponsesOptions | ||||||||||
|
|
@@ -41,7 +42,6 @@ | |||||||||
| WebSearchPreviewTool, | ||||||||||
| ) | ||||||||||
| from azure.ai.projects.models import FileSearchTool as ProjectsFileSearchTool | ||||||||||
| from azure.core.credentials_async import AsyncTokenCredential | ||||||||||
| from azure.core.exceptions import ResourceNotFoundError | ||||||||||
|
|
||||||||||
| from ._shared import AzureAISettings, create_text_format_config | ||||||||||
|
|
@@ -109,7 +109,7 @@ def __init__( | |||||||||
| conversation_id: str | None = None, | ||||||||||
| project_endpoint: str | None = None, | ||||||||||
| model_deployment_name: str | None = None, | ||||||||||
| credential: AsyncTokenCredential | None = None, | ||||||||||
| credential: AzureCredentialTypes | None = None, | ||||||||||
| use_latest_version: bool | None = None, | ||||||||||
| env_file_path: str | None = None, | ||||||||||
| env_file_encoding: str | None = None, | ||||||||||
|
|
@@ -132,7 +132,8 @@ def __init__( | |||||||||
| Ignored when a project_client is passed. | ||||||||||
| model_deployment_name: The model deployment name to use for agent creation. | ||||||||||
| Can also be set via environment variable AZURE_AI_MODEL_DEPLOYMENT_NAME. | ||||||||||
| credential: Azure async credential to use for authentication. | ||||||||||
| credential: Azure credential for authentication. Accepts a TokenCredential, | ||||||||||
| AsyncTokenCredential, or a callable token provider. | ||||||||||
|
Comment on lines
+135
to
+136
|
||||||||||
| credential: Azure credential for authentication. Accepts a TokenCredential, | |
| AsyncTokenCredential, or a callable token provider. | |
| credential: Azure credential for authentication. Accepts an AzureCredentialTypes | |
| instance, such as a TokenCredential or AsyncTokenCredential. |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |||||||||
| from agent_framework._mcp import MCPTool | ||||||||||
| from agent_framework._settings import load_settings | ||||||||||
| from agent_framework._tools import ToolTypes | ||||||||||
| from agent_framework.azure._entra_id_authentication import AzureCredentialTypes | ||||||||||
| from agent_framework.exceptions import ServiceInitializationError | ||||||||||
| from azure.ai.projects.aio import AIProjectClient | ||||||||||
| from azure.ai.projects.models import ( | ||||||||||
|
|
@@ -29,7 +30,6 @@ | |||||||||
| from azure.ai.projects.models import ( | ||||||||||
| FunctionTool as AzureFunctionTool, | ||||||||||
| ) | ||||||||||
| from azure.core.credentials_async import AsyncTokenCredential | ||||||||||
|
|
||||||||||
| from ._client import AzureAIClient, AzureAIProjectAgentOptions | ||||||||||
| from ._shared import AzureAISettings, create_text_format_config, from_azure_ai_tools, to_azure_ai_tools | ||||||||||
|
|
@@ -103,7 +103,7 @@ def __init__( | |||||||||
| *, | ||||||||||
| project_endpoint: str | None = None, | ||||||||||
| model: str | None = None, | ||||||||||
| credential: AsyncTokenCredential | None = None, | ||||||||||
| credential: AzureCredentialTypes | None = None, | ||||||||||
| env_file_path: str | None = None, | ||||||||||
| env_file_encoding: str | None = None, | ||||||||||
| ) -> None: | ||||||||||
|
|
@@ -116,7 +116,8 @@ def __init__( | |||||||||
| Ignored when a project_client is passed. | ||||||||||
| model: The default model deployment name to use for agent creation. | ||||||||||
| Can also be set via environment variable AZURE_AI_MODEL_DEPLOYMENT_NAME. | ||||||||||
| credential: Azure async credential to use for authentication. | ||||||||||
| credential: Azure credential for authentication. Accepts a TokenCredential, | ||||||||||
| AsyncTokenCredential, or a callable token provider. | ||||||||||
|
Comment on lines
+119
to
+120
|
||||||||||
| credential: Azure credential for authentication. Accepts a TokenCredential, | |
| AsyncTokenCredential, or a callable token provider. | |
| credential: Azure credential for authentication. Accepts credentials supported by | |
| AzureCredentialTypes (for example, TokenCredential or AsyncTokenCredential). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AzureAISearchContextProvidernow typescredentialasAzureCredentialTypes(includes sync TokenCredential) and the docstring also mentions callable token providers, but the implementation constructsazure.search.documents.aio.SearchClientand annotatesresolved_credentialasAzureKeyCredential | AsyncTokenCredential. This is internally inconsistent (note the# type: ignore[assignment]) and may allow passing unsupported credential types to the async SearchClient. Recommend (a) removing the “callable token provider” claim, and (b) narrowingcredentialback to the credential type(s) that the async SearchClient actually supports, so thetype: ignoreand mismatched annotations can be removed.