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

* Replace Hosted*Tool classes with client static factory methods

* fixed failing test

* mypy fix

* mypy fix 2

* declarative mypy fix

* addressed comments

* ToolProtocol removal

* fixed test

* agents mypy fix

* fix failing tests

* mypy fix

* addressed comments

* fixed tests

* addressed comments + added factory method overrides for azureai v2 client

* mypy fix

* added kwargs to azureai tool methods

* fixed in test

* _sessions fix

* test fix
This commit is contained in:
Giles Odigwe
2026-02-10 16:04:27 -08:00
committed by GitHub
Unverified
parent d249473a6d
commit 7a88af0aef
133 changed files with 3018 additions and 2650 deletions
@@ -18,7 +18,6 @@ from agent_framework import (
ContextProvider,
FunctionTool,
Message,
ToolProtocol,
get_logger,
normalize_messages,
)
@@ -217,11 +216,11 @@ class ClaudeAgent(BaseAgent, Generic[OptionsT]):
description: str | None = None,
context_provider: ContextProvider | None = None,
middleware: Sequence[AgentMiddlewareTypes] | None = None,
tools: ToolProtocol
tools: FunctionTool
| Callable[..., Any]
| MutableMapping[str, Any]
| str
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any] | str]
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | str]
| None = None,
default_options: OptionsT | MutableMapping[str, Any] | None = None,
env_file_path: str | None = None,
@@ -242,7 +241,7 @@ class ClaudeAgent(BaseAgent, Generic[OptionsT]):
middleware: List of middleware.
tools: Tools for the agent. Can be:
- Strings for built-in tools (e.g., "Read", "Write", "Bash", "Glob")
- Functions or ToolProtocol instances for custom tools
- Functions for custom tools
default_options: Default ClaudeAgentOptions including system_prompt, model, etc.
env_file_path: Path to .env file.
env_file_encoding: Encoding of .env file.
@@ -288,9 +287,9 @@ class ClaudeAgent(BaseAgent, Generic[OptionsT]):
except ValidationError as ex:
raise ServiceInitializationError("Failed to create Claude Agent settings.", ex) from ex
# Separate built-in tools (strings) from custom tools (callables/ToolProtocol)
# Separate built-in tools (strings) from custom tools (callables/FunctionTool)
self._builtin_tools: list[str] = []
self._custom_tools: list[ToolProtocol | MutableMapping[str, Any]] = []
self._custom_tools: list[FunctionTool | MutableMapping[str, Any]] = []
self._normalize_tools(tools)
self._default_options = opts
@@ -299,11 +298,11 @@ class ClaudeAgent(BaseAgent, Generic[OptionsT]):
def _normalize_tools(
self,
tools: ToolProtocol
tools: FunctionTool
| Callable[..., Any]
| MutableMapping[str, Any]
| str
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any] | str]
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | str]
| None,
) -> None:
"""Separate built-in tools (strings) from custom tools.
@@ -317,7 +316,7 @@ class ClaudeAgent(BaseAgent, Generic[OptionsT]):
# Normalize to sequence
if isinstance(tools, str):
tools_list: Sequence[Any] = [tools]
elif isinstance(tools, (ToolProtocol, MutableMapping)) or callable(tools):
elif isinstance(tools, (FunctionTool, MutableMapping)) or callable(tools):
tools_list = [tools]
else:
tools_list = list(tools)
@@ -458,7 +457,7 @@ class ClaudeAgent(BaseAgent, Generic[OptionsT]):
def _prepare_tools(
self,
tools: list[ToolProtocol | MutableMapping[str, Any]],
tools: list[FunctionTool | MutableMapping[str, Any]],
) -> tuple[Any, list[str]]:
"""Convert Agent Framework tools to SDK MCP server.
@@ -476,7 +475,8 @@ class ClaudeAgent(BaseAgent, Generic[OptionsT]):
sdk_tools.append(self._function_tool_to_sdk_mcp_tool(tool))
# Claude Agent SDK convention: MCP tools use format "mcp__{server}__{tool}"
tool_names.append(f"mcp__{TOOLS_MCP_SERVER_NAME}__{tool.name}")
elif isinstance(tool, ToolProtocol):
else:
# Non-FunctionTool items (e.g., dict-based hosted tools) cannot be converted to SDK MCP tools
logger.debug(f"Unsupported tool type: {type(tool)}")
if not sdk_tools: