-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Python: [BREAKING] Replace Hosted*Tool classes with tool methods #3634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a breaking change that refactors hosted tool support from standalone Hosted*Tool classes to static factory methods on chat clients. This improves API discoverability by making tool support explicit per client type.
Changes:
- Removed
HostedCodeInterpreterTool,HostedWebSearchTool,HostedFileSearchTool,HostedImageGenerationTool, andHostedMCPToolclasses - Added static factory methods (
get_code_interpreter_tool(),get_web_search_tool(), etc.) to relevant client classes - Introduced protocol classes (
SupportsCodeInterpreterTool,SupportsWebSearchTool, etc.) for runtime checking of tool support - Updated all samples, tests, and documentation to use the new API
Reviewed changes
Copilot reviewed 119 out of 119 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/agent_framework/_clients.py |
Added tool support protocol definitions |
python/packages/core/agent_framework/openai/_chat_client.py |
Added get_web_search_tool() static method |
python/packages/core/agent_framework/openai/_assistants_client.py |
Added get_code_interpreter_tool() and get_file_search_tool() static methods |
python/packages/core/agent_framework/openai/_responses_client.py |
Added static methods for all hosted tools (code interpreter, web search, file search, image generation, MCP) |
python/packages/azure-ai/agent_framework_azure_ai/_client.py |
Added Azure-specific get_mcp_tool() implementation |
python/packages/anthropic/agent_framework_anthropic/_chat_client.py |
Added static methods for Anthropic-supported tools |
| Multiple sample files | Updated to use new static factory methods instead of Hosted*Tool classes |
| Multiple test files | Updated test assertions to check for dict-based tools instead of class instances |
python/packages/declarative/agent_framework_declarative/_loader.py |
Updated to create dict-based tools directly |
eavanvalkenburg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of notes, overall I think we will have to move to remove some additional pieces of from tools and streamline things even more, I would expect only the functionTool to be handled in the each clients prepare code, everything else should already be setup correctly.
python/packages/anthropic/agent_framework_anthropic/_chat_client.py
Outdated
Show resolved
Hide resolved
python/packages/anthropic/agent_framework_anthropic/_chat_client.py
Outdated
Show resolved
Hide resolved
| "description": tool.description, | ||
| "input_schema": tool.parameters(), | ||
| }) | ||
| elif isinstance(tool, MutableMapping): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this goal is to not have to do anything here, just get FunctionTool and the rest is pass through
python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/openai/_responses_client.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/agents/anthropic/anthropic_skills.py
Outdated
Show resolved
Hide resolved
| @@ -189,8 +182,7 @@ def __str__(self) -> str: | |||
| class BaseTool(SerializationMixin): | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think now only FunctionTool derives from this, so let's fold them together and remove this basetool. The same for the ToolProtocol I don't think we need that anymore
Motivation and Context
This PR refactors hosted tool support from standalone
Hosted*Toolclasses to@staticmethodfactory methods on the chat clients that support them. This is a breaking change that improves API discoverability and makes tool support explicit per clientBreaking Changes
Removed classes:
HostedCodeInterpreterToolHostedWebSearchToolHostedImageGenerationToolHostedFileSearchToolHostedMCPToolMigration:
#3586
Description
Contribution Checklist