Skip to content

Python: Enable tool search in the Foundry Toolbox sample - #9113

Open
Naveen Chatlapalli (1aifanatic) wants to merge 3 commits into
microsoft:mainfrom
1aifanatic:contrib/7489-python-tool-search
Open

Naveen Chatlapalli (1aifanatic) wants to merge 3 commits into
microsoft:mainfrom
1aifanatic:contrib/7489-python-tool-search

Conversation

@1aifanatic

@1aifanatic Naveen Chatlapalli (1aifanatic) commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

The Foundry Toolbox Python sample needs to demonstrate discovering tools on demand through toolbox tool search.

Description & Review Guide

  • What are the major changes? Enable ToolSearchToolboxTool alongside the current SDK MCP toolbox model, connect to the created version, preserve existing versions, and update the sample index. Guard the optional tool-search import with a clear azure-ai-projects>=2.4.0 upgrade message.
  • What is the impact of these changes? The existing MCP integration exposes tool_search and call_tool without adding a framework API or changing the package dependency floor. Older SDK installations receive an actionable sample-specific error before authentication.
  • What do you want reviewers to focus on? Ruff, formatting, and Pyright pass. Mock checks verify actual SDK serialization of both tool kinds, preservation of existing versions, and the missing-symbol upgrade path before authentication. Live Foundry provisioning/model execution was not run.

Related Issue

Addresses the Python portion of #7489. The .NET contribution remains in #9008; the two PRs are separate language implementations, following the maintainer's request there.

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 is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

Copilot AI balanced review requested due to automatic review settings October 6, 2026 11:53
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Oct 6, 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.

Copilot review overview

🟢 Approval recommended

The focused sample changes consistently implement version-pinned toolbox tool search without introducing unresolved issues.

Review effort: Balanced
Findings: None

What changed in this PR

Enables on-demand tool discovery in the Python Foundry Toolbox sample while preserving existing toolbox versions.

Changes:

  • Adds ToolSearchToolboxTool alongside the MCP toolbox tool.
  • Connects the agent to the newly created version-specific MCP endpoint.
  • Updates the sample index and query to demonstrate tool discovery.
File Description
python/​samples/​02-agents/​providers/​foundry/​README.md Updates the toolbox sample description.
python/​samples/​02-agents/​providers/​foundry/​foundry_chat_client_with_toolbox.py Provisions tool search and uses the exact created toolbox version.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The sample correctly gates the stable toolbox-search model to azure-ai-projects 2.4+, preserves existing toolbox versions, connects to the exact created version endpoint, and uses a query that exercises tool discovery.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Naveen Chatlapalli (@1aifanatic) One material compatibility issue remains in python/samples/02-agents/providers/foundry/foundry_chat_client_with_toolbox.py:48. MCPToolboxTool and ToolboxTool are imported before the new guarded import, but neither name exists in azure-ai-projects==2.2.0, which is still permitted by the package dependency floor. Those installations therefore fail with a raw ImportError instead of the actionable azure-ai-projects>=2.4.0 upgrade message. Please move all three toolbox-model imports into the existing guard and add a regression covering the real 2.2 export surface.

MCPToolboxTool and ToolboxTool are missing from azure-ai-projects 2.2.0,
which the foundry package still allows, so importing them outside the
guard raised a raw ImportError instead of the upgrade message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@1aifanatic

Copy link
Copy Markdown
Contributor Author

Eduard van Valkenburg (@eavanvalkenburg) Thanks, you're right. I checked the exports of each release:

azure-ai-projects MCPToolboxTool ToolboxTool ToolSearchToolboxTool
2.2.0 no no no
2.3.0 yes yes no
2.4.0+ yes yes yes

ac26635 moves all three imports into the guard, so 2.2.0 and 2.3.0 both get the azure-ai-projects>=2.4.0 upgrade message.

It also adds python/tests/samples/agents/test_foundry_toolbox_sample.py. The test loads the sample and swaps in a azure.ai.projects.models module that exposes exactly the 2.2.0 or 2.3.0 toolbox names. It asserts the upgrade ImportError and checks that no credential is created. A third case with the 2.4.0 names checks that the guard lets it through. The 2.2.0 case fails on the previous head with cannot import name 'MCPToolboxTool'.

I also ran create_sample_toolbox() against the real packages: with azure-ai-projects==2.2.0 it raises the upgrade message, and with 2.4.0 it gets past the guard to AzureCliCredential.

This branch was previously deployed

1 inactive deployment
github-app-auth — ac266356 Deployed Oct 27, 2026 by 1aifanatic via team_check #7756
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.

3 participants