Skip to content

feat(models): adding python support for Azure foundry models (OpenAI + Anthropic types) - #2512

Merged
EItanya merged 5 commits into
kagent-dev:mainfrom
marosset:foundry-python
Sep 18, 2026
Merged

EItanya merged 5 commits into
kagent-dev:mainfrom
marosset:foundry-python

Conversation

@marosset

Copy link
Copy Markdown
Contributor

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)

@marosset
marosset requested a review from a team as a code owner August 20, 2026 18:25
Copilot AI lite review requested due to automatic review settings August 20, 2026 18:25
@marosset marosset changed the title feat(models) adding python support for Azure foundry models (OpenAI + Anthropic types) feat(models): adding python support for Azure foundry models (OpenAI + Anthropic types) Aug 20, 2026
@github-actions github-actions Bot added the enhancement New feature or request label Aug 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

response = await client.embeddings.create(
model=self.config.model,
input=texts,
dimensions=self.TARGET_DIMENSION,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@marosset

Copy link
Copy Markdown
Contributor Author

@mesutoezdil, have you had a chance to look at the rest of this PR?
Thanks!

marosset and others added 3 commits September 2, 2026 17:10
… 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>
@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale This issue or PR has become stale label Sep 18, 2026
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 EItanya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

Comment on lines +141 to +145
# 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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Prevent AZURE_OPENAI_AD_TOKEN from 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.

Comment on lines +28 to +32
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.

@EItanya
EItanya added this pull request to the merge queue Sep 18, 2026
Merged via the queue into kagent-dev:main with commit e69e98a Sep 18, 2026
27 checks passed
alexdarbyshire pushed a commit to alexdarbyshire/kagent that referenced this pull request Oct 5, 2026
…+ 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request stale This issue or PR has become stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants