Repository navigation
Conversation
Use the in-process SDK singleton and catalog model APIs with the existing OpenAI transport. Require Python 3.11 and document the breaking migration. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
Follow the existing OpenAI test pattern so transport coverage works with both OpenAI 2.x and locked OpenAI 3.x/httpx2. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Python 3.15 compatibility declarations and CI gating are inconsistent, and singleton construction has a concurrency race.
5 open findings
What changed in this PR
Migrates the Python Foundry Local integration to SDK 2.1, addressing #9321 while retaining Agent Framework’s OpenAI transport.
Changes:
- Adopts the SDK singleton, catalog/model lifecycle, and built-in web service.
- Raises support to Python 3.11+ and updates dependencies and CI.
- Expands migration documentation and regression tests.
| File | Description |
|---|---|
.github/workflows/python-tests.yml |
Updates Python-version exclusions. |
python/packages/core/pyproject.toml |
Gates the Foundry Local extra. |
python/packages/foundry_local/AGENTS.md |
Updates package guidance. |
python/packages/foundry_local/README.md |
Documents usage and migration. |
python/packages/foundry_local/agent_framework_foundry_local/_foundry_local_client.py |
Implements SDK 2.1 integration. |
python/packages/foundry_local/pyproject.toml |
Updates Python and SDK requirements. |
python/packages/foundry_local/tests/conftest.py |
Adds SDK-aware fixtures. |
python/packages/foundry_local/tests/test_foundry_local_client.py |
Expands lifecycle and transport tests. |
python/samples/02-agents/providers/foundry/foundry_local_agent.py |
Updates sample APIs and cleanup. |
python/uv.lock |
Resolves SDK 2.1 dependencies. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
SDK 2.1 pins ONNX Runtime 1.30.0, which has no Python 3.15 wheels. Exclude Foundry Local from the 3.15 workspace job and align package and extra metadata with Python 3.11-3.14. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
Hold the adapter setup lock through singleton initialization, web-service startup, model preparation, and failure rollback. Add concurrent success/failure regressions and keep invalid-input and transport tests compatible with all CI type checkers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
Avoid passing an unspecialized generic constructor to Executor.submit, and isolate the concurrency regressions from real HTTP client initialization. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
Normalize native token limits and response schemas, preserve required tool invocation before structured replies, expose download controls, and roll back services started during failed client setup. Expand transport and agent regressions and document public-catalog-only scope. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
The Foundry Local checks passed. The first full matrix failed in the existing declarative MCP approval/checkpoint regression and cancelled other matrix rows. GitHub requires repository-admin rights for a rerun, so trigger a fresh check run without changing unrelated code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
Forward streaming and non-streaming requests through checked overloads, declare the function layer's supported Foundry options explicitly, and narrow the required model setting with an explicit error guard. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
SDK 2.1 supports registered local models through /catalogs/local/v1. Keep local-catalog selection intentionally outside this adapter, rather than incorrectly describing it as a backend limitation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
Add explicit public/local catalog selection for model lookup and inference, retaining the public default and catalog isolation. Cover selection, invalid input, preparation, rollback, and streamed/non-streamed model overrides, and document SDK-owned registration. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8ebdb3c-28b8-4fa1-830d-3fa7d6333d9e
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Motivation & Context
The Python Foundry Local adapter pins
foundry-local-sdk>=0.5.1,<0.5.2and imports the retiredfoundry_localAPI. Installing a current SDK therefore conflicts with the dependency declaration and breaks the adapter import. This updates the integration to the current SDK rather than only relaxing the version pin.This PR is intentionally draft, pending maintainer agreement on the linked issue and human contributor review. The submitter explicitly chose a current-SDK-only migration instead of maintaining a dual-version adapter.
Description & Review Guide
foundry-local-sdk>=2.1.0,<3; usefoundry_local_sdk.Configuration, the shared SDK manager, catalog/model lifecycle APIs, and its built-in web service. Keep the existing Agent Framework OpenAI transport, middleware, sessions, and function-invocation layers. Refresh the lockfile, gate the meta-package extra on Python 3.11-3.14, and exclude this package from Python 3.10/3.15 workspace CI. SDK 2.1 pins ONNX Runtime 1.30.0, which has no Python 3.15 wheels.bootstrap=Falserequires a manager and web service already running in the same process.prepare_model=Falserequires an already loaded variant or manual preparation; the HTTP service does not load models on the first request.timeoutapplies to HTTP inference, not native preparation. Model IDs remain exact and device selection does not mutate the shared alias. Expose download progress/cancellation, nativetop_k/do_sample/early_stopping, existing SDK configuration, andcatalog_type="local"(orCatalogType.LOCAL) for SDK-registered BYOM. Public catalog selection remains the default; both model lookup and HTTP inference use the selected catalog without cross-catalog fallback. Normalize token limits and structured-output schemas to the native HTTP contract, merge decoder metadata without mutating caller options, and use tool grammar before final-response schema grammar for required tool calls.The affected package now has 118 passing regression cases, covering lifecycle/concurrency/rollback, configuration, download controls, generation options and metadata precedence, streaming/usage, model overrides, structured output, automatic tool execution enabled/disabled, required tools combined with structured output in both response modes, middleware, session history, image serialization, HTTP errors, and cancellation/reuse. Local-catalog coverage adds alias/exact-ID selection, string/SDK-enum selectors, invalid-input rejection before setup, catalog isolation, manual preparation, download controls, device mismatch, service rollback, and HTTP routing/model overrides in both response modes. Repository-pinned Ruff, strict source Pyright, all five CI-profile test type checkers, and the existing Markdown code-block validator pass locally. No type-checker profile or Python target was weakened. Follow-up commit
bc01d20removes both adapter casts: request forwarding uses checked streaming/non-streaming overloads, the function layer explicitly accepts the advertised Foundry options, and the required model setting is narrowed with an explicit error guard.Real SDK 2.1 inference was exercised on Windows/Python 3.13, separately from mocked transport coverage: 16 CPU feature cases pass, using
qwen3-0.6b-generic-cpu:4andqwen3.5-0.8b-generic-cpu:3. These cover text/streaming/usage, history, Pydantic output in both modes, JSON-object grammar, tools in both modes, native decoder settings and rejected invalid settings, early stream close/reuse, an exact eight-token output cap, model override, deterministic seeded sampling, and required tools followed by structured output in both modes. An additional real-native failed-construction probe confirms web-service rollback, manager reuse, and subsequent successful inference.Real accelerated text and streaming inference also pass with
qwen3-0.6b-cuda-gpu:2andCUDAExecutionProvider. GPU observations reached 1,236 MiB VRAM and 45% utilization, rather than relying on provider metadata alone. A cancelled uncached download failed explicitly, then subsequent preparation succeeded with 255 progress observations including 0 and 100.BYOM/local-catalog selection is exposed in
fcfa815, after successful real SDK 2.1 validation. Local clients use/catalogs/local/v1; public clients retain/v1. Eight real BYOM-adapter feature cases pass using two SDK-local registrations of cached Qwen3 CPU assets: text/usage, Pydantic structured output, required tools followed by structured output, and exact model overrides, each in streaming and non-streaming modes. Alias resolution and native preparation also succeed, including a 100% local download-progress callback. The public catalog cannot resolve the local registration, and a failed public lookup leaves the existing local model/service intact. Applications own registration, assets, and shutdown; the adapter does not convert arbitrary model files. The local HTTP route exists in bothv2.1.0and current main; the earlier claim of a backend limitation was incorrect. Vision remains not verified: paired red/blue image probes did not distinguish the images, including a direct HTTP request with combined image/text content. The README does not claim vision support from image serialization or the presence of vision assets. Audio, embeddings, and native-session-only APIs are outside this chat adapter.Upstream CI for prior head
bc01d20is green: 29 checks pass and 18 are skipped, with no failures or pending checks. Earlier runs encountered the unrelated Windows/Python 3.11 declarative approval/checkpoint assertion inTestApprovalFlow.test_auth_context_binding_survives_workflow_resume[True-True]; it passed on that run without modifying the declarative implementation or test. Fresh upstream CI for BYOM support atfcfa815is pending.Related Issue
Fixes #9321.
Original report: microsoft/homebrew-foundrylocal#31.
Maintainer agreement /
ready-for-implementationapproval has not yet been obtained. This draft is provided for discussion at the submitter's request; it does not claim to satisfy that approval requirement. The open .NET integration PR #5170 is separate from this Python SDK migration.AI Assistance
AI assistance details: GitHub Copilot assisted with investigation, implementation, regression tests, documentation, dependency-lock refresh, native CPU/GPU validation, and this description. Validation helper workflows and downloaded artifacts are not part of this PR.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) -- a workflow keeps the label and title prefix in sync automatically.