Skip to content

Python: [BREAKING] Replace Hosted*Tool classes with tool methods#3634

Open
giles17 wants to merge 12 commits intomicrosoft:mainfrom
giles17:refactor-hosted-tools
Open

Python: [BREAKING] Replace Hosted*Tool classes with tool methods#3634
giles17 wants to merge 12 commits intomicrosoft:mainfrom
giles17:refactor-hosted-tools

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Feb 3, 2026

Motivation and Context

This PR refactors hosted tool support from standalone Hosted*Tool classes to @staticmethod factory methods on the chat clients that support them. This is a breaking change that improves API discoverability and makes tool support explicit per client

Breaking Changes

Removed classes:

  • HostedCodeInterpreterTool
  • HostedWebSearchTool
  • HostedImageGenerationTool
  • HostedFileSearchTool
  • HostedMCPTool

Migration:

# BEFORE (old API - removed)
from agent_framework import HostedCodeInterpreterTool, HostedWebSearchTool
tool = HostedCodeInterpreterTool()
search = HostedWebSearchTool(additional_properties={"user_location": {...}})

# AFTER (new API)
from agent_framework.openai import OpenAIResponsesClient

tool = OpenAIResponsesClient.get_code_interpreter_tool()
search = OpenAIResponsesClient.get_web_search_tool(user_location={"city": "Seattle"})

#3586

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings February 3, 2026 04:29
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python lab Agent Framework Lab labels Feb 3, 2026
@github-actions github-actions bot changed the title [BREAKING] Replace Hosted*Tool classes with client static factory methods Python: [BREAKING] Replace Hosted*Tool classes with client static factory methods Feb 3, 2026
Copy link
Contributor

Copilot AI left a 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, and HostedMCPTool classes
  • 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

@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 3, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _utils.py99198%72
packages/anthropic/agent_framework_anthropic
   _chat_client.py36814959%425, 465, 488, 490, 505, 527–530, 539, 541, 572–576, 578, 580–581, 583, 588–589, 591, 624–625, 634, 636–637, 642, 659–660, 705, 715, 731, 740, 742, 746–747, 790–792, 794, 807–808, 815–817, 821–823, 827–830, 841, 843, 865, 875, 897–903, 910–911, 919–920, 928–931, 938–939, 945–946, 952–953, 959, 967–969, 973, 980–981, 987–988, 994–995, 1001, 1009–1012, 1019–1020, 1039, 1046–1047, 1066, 1088, 1090, 1099–1100, 1106, 1128–1129, 1135–1136, 1145–1155, 1162–1168, 1175–1181, 1188–1197, 1204–1207
packages/azure-ai/agent_framework_azure_ai
   _agent_provider.py115397%121–122, 250
   _chat_client.py5018183%317, 375, 378, 381, 384–385, 387–393, 566, 827–828, 830, 833, 836, 839–844, 847, 849, 857, 869–871, 875, 878–879, 887–890, 900, 908–911, 913–914, 916–917, 924, 932–933, 941–942, 947–948, 952–959, 964, 967, 975, 981, 989–991, 994, 1016–1017, 1150, 1178, 1193, 1227, 1316, 1332, 1340, 1354, 1474
   _client.py1943283%344, 346, 395, 424–429, 472, 509, 511, 571, 573–574, 576–577, 579–582, 584–585, 587–589, 591–594, 596, 643
   _project_provider.py115694%131–132, 210, 308, 352, 385
   _shared.py2822491%112, 153, 157, 165, 179, 251, 294, 306–308, 337, 339, 341, 345, 421, 437–438, 451, 453, 481, 522, 529, 541, 560
packages/core/agent_framework
   _agents.py3104087%456, 855, 858–860, 985–987, 992–994, 1093, 1134, 1136, 1145–1150, 1156, 1158, 1168–1169, 1176, 1178–1179, 1187–1191, 1199–1200, 1202, 1207, 1209, 1243, 1283, 1303
   _clients.py77494%291, 335, 483, 485
   _mcp.py3915386%125, 187, 196, 259, 267, 288, 378, 445, 480, 482, 486–487, 489–490, 544, 559, 577, 618, 724, 737–742, 764, 785, 788–790, 805–806, 812–814, 833, 842, 845–847, 862–863, 867–871, 888–892, 1032
   _memory.py26196%152
   _tools.py6948288%170–171, 285, 287, 304–306, 313, 331, 345, 357, 362, 364, 371, 404, 475–477, 518, 540–568, 603, 611, 852, 1189, 1276–1280, 1302–1303, 1419, 1421, 1486, 1578, 1584, 1625–1626, 1639–1640, 1683, 1767, 1805–1806, 1844–1846, 1884–1885, 1895, 1952–1953, 1960–1961
   _types.py8773496%88, 262, 292, 296, 1162, 1182–1183, 1185, 1193, 1230, 1242, 1282, 1621, 1720–1725, 1747, 1881, 1893, 2129, 2138, 2256, 2477, 2762–2764, 2854, 2865–2866, 2872–2873
packages/core/agent_framework/openai
   _assistant_provider.py1101190%156–157, 169, 294, 360, 475–480
   _assistants_client.py2762989%401, 415, 418, 420–421, 424, 427, 430–431, 442, 467, 469, 471, 473, 475, 480, 483, 486, 490, 501, 586, 671, 698, 735–738, 790, 807
   _chat_client.py2742291%177, 234–235, 239, 330, 337, 418–425, 427–430, 440, 525, 562, 578
   _responses_client.py5666887%252, 257, 259–260, 271, 289, 297, 320, 400, 491, 494, 549, 553, 555, 557, 559, 635, 645, 650, 693, 751, 765, 782, 795, 850, 929, 934, 938–940, 944–945, 968, 1037, 1059–1060, 1075–1076, 1094–1095, 1226–1227, 1243, 1245, 1320–1328, 1376, 1431, 1446, 1482–1483, 1485–1487, 1501–1503, 1513–1514, 1520, 1535
   _shared.py1251588%63, 69–72, 150, 152, 159, 161, 174, 250, 274, 333–334, 336
TOTAL16321195688% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3967 221 💤 0 ❌ 0 🔥 1m 7s ⏱️

@giles17 giles17 changed the title Python: [BREAKING] Replace Hosted*Tool classes with client static factory methods Python: [BREAKING] Replace Hosted*Tool classes with tool methods Feb 3, 2026
Copy link
Member

@eavanvalkenburg eavanvalkenburg left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation lab Agent Framework Lab python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants