Python: fix(foundry): reconcile toolbox hosted-tool payloads with Responses API#5414
Merged
moonbox3 merged 2 commits intomicrosoft:mainfrom Apr 22, 2026
Merged
Conversation
Contributor
Author
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes interoperability issues between Azure AI Foundry toolbox tool payloads and the Foundry /openai/v1/responses proxy by sanitizing/validating hosted-tool payloads before sending them to the Responses API.
Changes:
- Extend hosted-tool sanitization to inject a default
{"type": "auto"}container forcode_interpretertools when absent. - Add fail-fast validation for hosted tool payloads that the Responses API will always reject (e.g.,
file_searchwithoutvector_store_ids,mcpwithoutserver_urlorproject_connection_id) and tighten MCP tool factory behavior. - Update samples/tests to cover toolbox-hosted tool round-trips and the new sanitization behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| python/samples/04-hosting/foundry-hosted-agents/responses/02_local_tools/main.py | Import cleanup to keep the sample consistent. |
| python/samples/02-agents/providers/foundry/foundry_chat_client_with_toolbox.py | Sample toolbox creation now includes web search and code interpreter tools. |
| python/packages/foundry/tests/foundry/test_foundry_chat_client.py | Adds unit tests for new sanitization/validation behavior and MCP tool factory constraints. |
| python/packages/foundry/agent_framework_foundry/_tools.py | Implements hosted-tool payload validation and injects default container for code_interpreter. |
| python/packages/foundry/agent_framework_foundry/_chat_client.py | Updates get_mcp_tool() to avoid fabricating server_url and to raise when missing destination info. |
eavanvalkenburg
approved these changes
Apr 22, 2026
giles17
approved these changes
Apr 22, 2026
This was referenced Apr 24, 2026
Open
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 and Context
Fixes a
400 Missing required parameter: 'tools[N].container'that surfaces when a Foundry toolbox containing acode_interpretertool is loaded viaFoundryChatClient.get_toolbox()and passed to anAgent. Along the way, hardens adjacent hosted-tool payloads that would also fail silently until the Responses API rejects them.The issue:
Three layers disagree about what's required on hosted-tool payloads:
containeroncode_interpreterazure.ai.projects.models.CodeInterpreterTool(SDK type)/openai/v1/responsesproxySo
CodeInterpreterTool(name="code_interpreter")round-trips through a toolbox and lands at/responseswithout acontainer, which is rejected. The existingsanitize_foundry_response_toolalready exists to reconcile the oppositeround-trip mismatch (toolbox reads decorate payloads with
name/descriptionthat/responsesrejects) — this PR extends it to cover the missing-default direction too, and makes adjacent non-defaultable gaps fail fast with a clear error instead of bubbling up as a generic 400.Description
Fixes for toolbox tools.
Contribution Checklist