mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
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:
committed by
GitHub
Unverified
parent
d249473a6d
commit
7a88af0aef
@@ -21,7 +21,7 @@ from agent_framework import (
|
||||
ResponseStream,
|
||||
normalize_messages,
|
||||
)
|
||||
from agent_framework._tools import FunctionTool, ToolProtocol
|
||||
from agent_framework._tools import FunctionTool
|
||||
from agent_framework._types import normalize_tools
|
||||
from agent_framework.exceptions import ServiceException, ServiceInitializationError
|
||||
from copilot import CopilotClient, CopilotSession
|
||||
@@ -151,10 +151,10 @@ class GitHubCopilotAgent(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]
|
||||
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
|
||||
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
|
||||
| None = None,
|
||||
default_options: OptionsT | None = None,
|
||||
env_file_path: str | None = None,
|
||||
@@ -173,7 +173,7 @@ class GitHubCopilotAgent(BaseAgent, Generic[OptionsT]):
|
||||
description: Description of the GitHubCopilotAgent.
|
||||
context_provider: Context Provider, to be used by the agent.
|
||||
middleware: Agent middleware used by the agent.
|
||||
tools: Tools to use for the agent. Can be functions, ToolProtocol instances,
|
||||
tools: Tools to use for the agent. Can be functions
|
||||
or tool definition dicts. These are converted to Copilot SDK tools internally.
|
||||
default_options: Default options for the agent. Can include cli_path, model,
|
||||
timeout, log_level, etc.
|
||||
@@ -479,7 +479,7 @@ class GitHubCopilotAgent(BaseAgent, Generic[OptionsT]):
|
||||
|
||||
def _prepare_tools(
|
||||
self,
|
||||
tools: list[ToolProtocol | MutableMapping[str, Any]],
|
||||
tools: list[FunctionTool | MutableMapping[str, Any]],
|
||||
) -> list[CopilotTool]:
|
||||
"""Convert Agent Framework tools to Copilot SDK tools.
|
||||
|
||||
@@ -492,14 +492,11 @@ class GitHubCopilotAgent(BaseAgent, Generic[OptionsT]):
|
||||
copilot_tools: list[CopilotTool] = []
|
||||
|
||||
for tool in tools:
|
||||
if isinstance(tool, ToolProtocol):
|
||||
match tool:
|
||||
case FunctionTool():
|
||||
copilot_tools.append(self._tool_to_copilot_tool(tool)) # type: ignore
|
||||
case _:
|
||||
logger.debug(f"Unsupported tool type: {type(tool)}")
|
||||
if isinstance(tool, FunctionTool):
|
||||
copilot_tools.append(self._tool_to_copilot_tool(tool)) # type: ignore
|
||||
elif isinstance(tool, CopilotTool):
|
||||
copilot_tools.append(tool)
|
||||
# Note: Other tool types (e.g., dict-based hosted tools) are skipped
|
||||
|
||||
return copilot_tools
|
||||
|
||||
|
||||
Reference in New Issue
Block a user