Repository navigation
feat(models): adding python support for Azure foundry models (OpenAI + Anthropic types) - #2512
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Azure AI Foundry provider support to the Python ADK runtime, including OpenAI-compatible chat/embeddings and an Anthropic-format client path, while unifying Azure authentication to support API-key-less Azure Workload Identity via azure-identity.
Changes:
- Introduces shared Azure helpers (
_azure.py) for endpoint/deployment resolution, auth header sanitization, and implicit Workload Identity token providers. - Adds Foundry support to OpenAI chat and embeddings flows, plus Foundry Anthropic client support for Claude-on-Foundry.
- Expands unit test coverage for Azure OpenAI + Foundry auth modes (API key, passthrough, Workload Identity) and wiring.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| python/uv.lock | Adds Azure Identity dependency closure (azure-core, azure-identity, msal, msal-extensions). |
| python/packages/kagent-adk/pyproject.toml | Declares azure-identity as a runtime dependency for Workload Identity support. |
| python/packages/kagent-adk/src/kagent/adk/models/_azure.py | New shared Azure auth/config helpers and client builders for OpenAI + Anthropic surfaces. |
| python/packages/kagent-adk/src/kagent/adk/models/_openai.py | Refactors Azure OpenAI client creation to use unified Azure auth; adds Foundry OpenAI model support. |
| python/packages/kagent-adk/src/kagent/adk/models/_embedding.py | Adds Foundry embeddings provider path and unifies Azure embeddings client construction. |
| python/packages/kagent-adk/src/kagent/adk/models/_anthropic.py | Adds Foundry Anthropic implementation and improves passthrough client caching behavior. |
| python/packages/kagent-adk/src/kagent/adk/models/init.py | Exposes Foundry OpenAI model via public kagent.adk.models exports. |
| python/packages/kagent-adk/src/kagent/adk/types.py | Adds Foundry model config and wires provider dispatch (openai vs anthropic format). |
| python/packages/kagent-adk/tests/unittests/test_embedding.py | Adds Foundry embeddings tests for API key + Workload Identity + passthrough semantics. |
| python/packages/kagent-adk/tests/unittests/models/test_openai.py | Updates patch targets for Azure client construction; adds an import. |
| python/packages/kagent-adk/tests/unittests/models/test_azure.py | New tests validating Azure OpenAI/Foundry auth behavior and header sanitization. |
| python/packages/kagent-adk/tests/unittests/models/test_anthropic.py | Adds Foundry Anthropic tests (format dispatch, auth modes, request headers). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
8bc387d to
6c00760
Compare
| response = await client.embeddings.create( | ||
| model=self.config.model, | ||
| input=texts, | ||
| dimensions=self.TARGET_DIMENSION, |
|
@mesutoezdil, have you had a chance to look at the rest of this PR? |
2aec47a to
34d594a
Compare
… anthropic types) Signed-off-by: Mark Rossetti <marosset@microsoft.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mark Rossetti <marosset@microsoft.com>
Signed-off-by: Mark Rossetti <marosset@microsoft.com>
34d594a to
b6d5704
Compare
|
This pull request has been marked as stale because of no activity in the last 15 days. It will be closed in the next 5 days unless it is tagged "no stalebot" or other activity occurs. |
Merge current main, preserve Responses API logging and the shared Azure helpers, and normalize the merged model imports. Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
EItanya
left a comment
There was a problem hiding this comment.
🤖 AI-generated review.
Reviewed the merged result at 5bfc27a878d39e943c0a1642cd0750ebc93d6b98. The conflict resolution preserves main's Responses API support and the PR's Azure helpers, and fixes the merged import ordering.
I found two credential-handling issues, detailed inline. Both are reproduced with the locked SDKs and mocked HTTP/token boundaries.
Validation: uv lock --check, Ruff lint/format on the affected model/config/test files, and the PR diff whitespace check passed. The model/embedding suite had 249 passes and nine TLS failures caused by missing test certificates; after make generate-test-certs, the TLS suite passed (11 passed, 1 existing skip). Four separate, intentionally failing review probes reproduced the two findings. No live Azure or Kubernetes validation.
| # The sentinel prevents environment-key fallback while the token | ||
| # provider authenticates each request. | ||
| api_key=API_KEY_SENTINEL if token_provider is not None else api_key, | ||
| azure_ad_token_provider=token_provider, | ||
| api_version=api_version, |
There was a problem hiding this comment.
- Prevent
AZURE_OPENAI_AD_TOKENfrom overriding Foundry's selected credential.
API_KEY_SENTINEL suppresses the SDK's API-key fallback, but AsyncAzureOpenAI still reads AZURE_OPENAI_AD_TOKEN and gives that value precedence over both the explicit API key and azure_ad_token_provider. With that variable set, I reproduced a Foundry passthrough request sending Authorization: Bearer unrelated-env-token and no caller api-key; the workload-identity case also sent the environment token instead of calling the selected provider. This can authenticate as the wrong identity or fail against a different Foundry account.
Make the selected authentication mode authoritative by preventing the SDK's AD-token environment fallback, and add real-SDK request tests with AZURE_OPENAI_AD_TOKEN populated for passthrough and workload identity.
| def azure_ad_token_provider(scope: str = COGNITIVE_SERVICES_SCOPE) -> AsyncTokenProvider: | ||
| """Return an async bearer-token provider backed by ``DefaultAzureCredential``.""" | ||
| from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider | ||
|
|
||
| return get_bearer_token_provider(DefaultAzureCredential(), scope) |
There was a problem hiding this comment.
- Retain and close the async Azure credential.
This creates DefaultAzureCredential inside the token-provider closure without exposing ownership to the caller. Both Azure embedding paths construct a new provider per call and then only await client.close(), which closes OpenAI's HTTP client, not Azure Identity's separate HTTP transport. With workload identity or managed identity, repeated memory embeddings therefore leave Azure sessions/connectors unclosed and recreate the token cache each time.
I reproduced this for both foundry and azure_openai using the real OpenAI client and Azure bearer-token provider with an injected credential: token acquisition ran and the OpenAI HTTP client closed, but credential.close() was never awaited. Keep an explicit credential lifecycle and close it when its owning client/operation ends, including failures; cover that alongside the existing client-close tests.
…+ Anthropic types) (kagent-dev#2512) Part of kagent-dev#2072 kagent-dev#2091 added foundry support for the Go runtime. This PR does the same for python. As part of this change the AzureOpenAI model auth is moved to use unified Azure auth mechanisms (including API_KEY-less / workload identity support) --------- Signed-off-by: Mark Rossetti <marosset@microsoft.com> Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Eitan Yarmush <eitan.yarmush@solo.io>
Part of #2072
#2091 added foundry support for the Go runtime. This PR does the same for python.
As part of this change the AzureOpenAI model auth is moved to use unified Azure auth mechanisms (including API_KEY-less / workload identity support)