Uh oh!
There was an error while loading. Please reload this page.
Python: Add Foundry-Features header to toolbox requests - #7696
Python: Add Foundry-Features header to toolbox requests#7696Willow Lopez (Oxygen56) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for sending a mandatory Foundry toolbox preview feature flag via a Foundry-Features request header, optionally merged with platform-provided feature flags from an environment variable.
Changes:
- Add
_build_toolbox_features_header()to mergeToolboxes=V1PreviewwithFOUNDRY_AGENT_TOOLSET_FEATURES. - Update
_ToolboxAuthto inject theFoundry-Featuresheader on every request. - Add async auth-flow tests covering header composition behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
python/packages/foundry_hosting/agent_framework_foundry_hosting/_toolbox.py | Builds and injects the mandatory preview feature header into toolbox requests. |
python/packages/foundry_hosting/tests/test_toolbox.py | Adds parameterized tests validating Foundry-Features header behavior in async auth flow. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| self._features_header = _build_toolbox_features_header(os.environ.get("FOUNDRY_AGENT_TOOLSET_FEATURES")) | ||
| def _apply_headers(self, request: httpx.Request, token: AccessToken) -> None: | ||
| request.headers["Authorization"] = f"Bearer {token.token}" | ||
| for key, value in get_request_context().platform_headers().items(): | ||
| request.headers[key] = value | ||
| request.headers["Foundry-Features"] = self._features_header |
| def __init__(self, credential: AzureCredentialTypes, scope: str) -> None: | ||
| self._credential = credential | ||
| self._scope = scope | ||
| self._features_header = _build_toolbox_features_header(os.environ.get("FOUNDRY_AGENT_TOOLSET_FEATURES")) |
| def _apply_headers(self, request: httpx.Request, token: AccessToken) -> None: | ||
| request.headers["Authorization"] = f"Bearer {token.token}" | ||
| for key, value in get_request_context().platform_headers().items(): | ||
| request.headers[key] = value | ||
| request.headers["Foundry-Features"] = self._features_header |
| # Environment variable used to inject platform-provided toolbox feature flags. | ||
| _TOOLSET_FEATURES_ENV_VAR = "FOUNDRY_AGENT_TOOLSET_FEATURES" | ||
| # Mandatory preview feature flag for Foundry toolbox requests. | ||
| _MANDATORY_TOOLBOX_FEATURE = "Toolboxes=V1Preview" |
There was a problem hiding this comment.
I believe the preview flag is obsolete. Where did you see it's still required?
Python Test Coverage Report •
Python Unit Test Overview
| ||||||||||||||||||||||||||||||
| self._credential = credential | ||
| self._scope = scope | ||
| # Feature flags are startup configuration, matching the .NET toolbox service. | ||
| self._features_header = _build_toolbox_features_header(os.environ.get(_TOOLSET_FEATURES_ENV_VAR)) |
There was a problem hiding this comment.
Could we capture this value once in FoundryToolbox.__init__ and pass it into each _ToolboxAuth instance? Currently _ToolboxAuth.__init__ reads FOUNDRY_AGENT_TOOLSET_FEATURES, and reconnecting after close() creates a new _ToolboxAuth. Consequently, the same FoundryToolbox instance can silently change feature flags across connections. Holding the merged value on FoundryToolbox would preserve the stated startup-configuration semantics and match the .NET service's lifetime behavior.
Motivation & Context
Python
FoundryToolboxrequests currently omit the mandatoryFoundry-Features: Toolboxes=V1Previewheader and ignoreFOUNDRY_AGENT_TOOLSET_FEATURES. This can prevent platform-provided feature flags from reaching the toolbox service and leaves Python behavior inconsistent with .NET.Description & Review Guide
FoundryToolboxrequest now carries the expected feature header without changing the public API.Related Issue
Fixes#7689
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.