Skip to content

Python: Honor injected Foundry embedding clients without endpoint settings - #9991

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
ZedingZhang:cursor/foundry-injected-embedding-client-f900
Nov 4, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
ZedingZhang:cursor/foundry-injected-embedding-client-f900

Conversation

@ZedingZhang

Copy link
Copy Markdown
Contributor

Motivation & Context

RawFoundryEmbeddingClient and FoundryEmbeddingClient rejected a caller-supplied embeddings SDK client unless a Foundry project or Models endpoint was also configured. Construction raised ValueError: Either 'project_endpoint', 'project_client', or 'endpoint' is required... even when text_client or image_client was already a working transport. Ambient FOUNDRY_MODELS_ENDPOINT could also become the wrapper service URL while requests still went to the injected client.

Callers who already own a configured EmbeddingsClient or ImageEmbeddingsClient should be able to embed with that client without also supplying an endpoint, API key, credential, dotenv file, or Foundry environment variables.

Description & Review Guide

An injected text or image SDK client is the transport for that modality. It takes precedence over constructor connection settings, environment settings, and framework defaults, so those settings are not required and are not used to replace the injected client. model and image_model keep the existing explicit-argument, environment, then default resolution.

When one modality is injected, the other is created only if a later request needs it and endpoint plus credential settings are available. Client factories are not called for a transport the caller already supplied. A missing modality with insufficient settings raises a focused ValueError at request time, before any partial request is sent. service_url() reads the endpoint stored on an injected Azure AI Inference client when that value is a string. Otherwise it uses an explicit endpoint argument, or reports an empty URL instead of substituting an ambient endpoint.

Caller-owned client cleanup is unchanged and remains covered by #9627.

  • What are the major changes? Injected text_client / image_client values are sufficient transports in RawFoundryEmbeddingClient (and therefore FoundryEmbeddingClient). Connection settings are required only when a requested modality still has to be created.
  • What is the impact of these changes? Callers that previously failed construction with only an injected client can now embed with that client. Existing project-client and Models-endpoint construction is unchanged when no SDK client is injected.
  • What do you want reviewers to focus on? Precedence between an injected client, an explicit endpoint, and ambient Foundry endpoint settings, including service_url() when the SDK client does not expose a string endpoint.

Related Issue

Fixes #9950. The issue has the ready-for-implementation label; no competing open PR was found before submission.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution.

AI assistance details: Cursor's coding agent assisted with the implementation, regression tests, documentation updates, and this PR description. I reviewed the change and accept responsibility for it.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

…tings

An injected text or image SDK client is the transport for that modality, so
construction no longer requires a Foundry endpoint, API key, or credential.
Ambient endpoint settings cannot replace or block that client. The other
modality is created only when a request needs it and connection settings exist.

Co-authored-by: ZedingZhang <me@zedingzhang.com>

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.

🟡 Changes recommended

Injected text or image clients still trigger a configuration-conflict ValueError when combined with explicit project settings, violating documented precedence and requiring a fix with regression tests.

1 open issue
What changed in this PR

Updates Python’s Foundry embedding integration so caller-supplied SDK clients can work without separate endpoint or credential settings, addressing #9950.

Changes:

  • Accepts injected text or image transports and creates missing clients on demand.
  • Derives service URLs from injected clients without substituting ambient endpoints.
  • Adds regression tests and usage documentation; resource cleanup remains outside this PR’s scope.
File Description
python/​packages/​foundry/​tests/​foundry/​test_foundry_embedding_client.py Tests injected transports, endpoint precedence, lazy creation, and missing-modality errors.
python/​packages/​foundry/​README.md Documents injected-client configuration and on-demand creation.
python/​packages/​foundry/​agent_framework_foundry/​_embedding_client.py Implements injected transport handling, service URL resolution, and deferred client creation.

Review effort: Balanced

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.

🟡 Changes recommended

Injecting only an image client incorrectly disables project-backed text embeddings, causing text requests to fail despite a configured project client.

1 open issue
1 resolved since last review

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues remain to block the injected-client support changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Merged via the queue into microsoft:main with commit 9fa9e9b Nov 4, 2026
51 checks passed
@ZedingZhang
ZedingZhang (ZedingZhang) deleted the cursor/foundry-injected-embedding-client-f900 branch November 4, 2026 11:02

This branch was previously deployed

1 inactive deployment
github-app-auth — 6d11349a Deployed Nov 3, 2026 by ZedingZhang via add_label #26930
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Foundry embedding clients require endpoint settings even when SDK clients are injected

3 participants