Python: [BREAKING] changed AIFunction to FunctionTool and @ai_function to @tool (#3413)

* changed AIFunction to FunctionTool and @ai_function to @tool

* test and mypy fixes

* mypy fix

* switch function tool to always_require

* fix noop

* fix github copilot imports

* test fixes

* fix ollama test

* fixes for tests

* fix tests

* reverted change to always_require and extended timeout

* fix test
This commit is contained in:
Eduard van Valkenburg
2026-01-28 15:53:53 +01:00
committed by GitHub
Unverified
parent 15b43f2abe
commit a7d924a7d2
255 changed files with 1202 additions and 1290 deletions
@@ -6,9 +6,9 @@ from typing import TYPE_CHECKING, Any, Generic, TypedDict, cast
from agent_framework import (
AGENT_FRAMEWORK_USER_AGENT,
AIFunction,
ChatAgent,
ContextProvider,
FunctionTool,
Middleware,
ToolProtocol,
normalize_tools,
@@ -445,9 +445,9 @@ class AzureAIAgentsProvider(Generic[TOptions_co]):
# Add user-provided function tools and MCP tools
if provided_tools:
for provided_tool in provided_tools:
# AIFunction - has implementation for function calling
# FunctionTool - has implementation for function calling
# MCPTool - ChatAgent handles MCP connection and tool discovery at runtime
if isinstance(provided_tool, (AIFunction, MCPTool)):
if isinstance(provided_tool, (FunctionTool, MCPTool)):
merged.append(provided_tool) # type: ignore[reportUnknownArgumentType]
return merged
@@ -488,7 +488,7 @@ class AzureAIAgentsProvider(Generic[TOptions_co]):
provided_names: set[str] = set()
if provided_tools:
for tool in provided_tools:
if isinstance(tool, AIFunction):
if isinstance(tool, FunctionTool):
provided_names.add(tool.name)
# Check for missing implementations
@@ -10,7 +10,6 @@ from typing import Any, ClassVar, Generic, TypedDict
from agent_framework import (
AGENT_FRAMEWORK_USER_AGENT,
AIFunction,
Annotation,
BaseChatClient,
ChatAgent,
@@ -21,6 +20,7 @@ from agent_framework import (
ChatResponseUpdate,
Content,
ContextProvider,
FunctionTool,
HostedCodeInterpreterTool,
HostedFileSearchTool,
HostedMCPTool,
@@ -1117,7 +1117,7 @@ class AzureAIAgentClient(BaseChatClient[TAzureAIAgentOptions], Generic[TAzureAIA
tool_definitions: list[ToolDefinition | dict[str, Any]] = []
for tool in tools:
match tool:
case AIFunction():
case FunctionTool():
tool_definitions.append(tool.to_json_schema_spec()) # type: ignore[reportUnknownArgumentType]
case HostedWebSearchTool():
additional_props = tool.additional_properties or {}
@@ -6,9 +6,9 @@ from typing import Any, Generic, TypedDict
from agent_framework import (
AGENT_FRAMEWORK_USER_AGENT,
AIFunction,
ChatAgent,
ContextProvider,
FunctionTool,
Middleware,
ToolProtocol,
get_logger,
@@ -20,10 +20,12 @@ from azure.ai.projects.aio import AIProjectClient
from azure.ai.projects.models import (
AgentReference,
AgentVersionDetails,
FunctionTool,
PromptAgentDefinition,
PromptAgentDefinitionText,
)
from azure.ai.projects.models import (
FunctionTool as AzureFunctionTool,
)
from azure.core.credentials_async import AsyncTokenCredential
from pydantic import ValidationError
@@ -224,7 +226,7 @@ class AzureAIProjectAgentProvider(Generic[TOptions_co]):
# Connect MCP tools and discover their functions BEFORE creating the agent
# This is required because Azure AI Responses API doesn't accept tools at request time
mcp_discovered_functions: list[AIFunction[Any, Any]] = []
mcp_discovered_functions: list[FunctionTool] = []
for mcp_tool in mcp_tools:
if not mcp_tool.is_connected:
await mcp_tool.connect()
@@ -433,9 +435,9 @@ class AzureAIProjectAgentProvider(Generic[TOptions_co]):
# Add user-provided function tools and MCP tools
if provided_tools:
for provided_tool in provided_tools:
# AIFunction - has implementation for function calling
# FunctionTool - has implementation for function calling
# MCPTool - ChatAgent handles MCP connection and tool discovery at runtime
if isinstance(provided_tool, (AIFunction, MCPTool)):
if isinstance(provided_tool, (FunctionTool, MCPTool)):
merged.append(provided_tool) # type: ignore[reportUnknownArgumentType]
return merged
@@ -452,12 +454,14 @@ class AzureAIProjectAgentProvider(Generic[TOptions_co]):
"""Validate that required function tools are provided."""
# Normalize and validate function tools
normalized_tools = normalize_tools(provided_tools)
tool_names = {tool.name for tool in normalized_tools if isinstance(tool, AIFunction)}
tool_names = {tool.name for tool in normalized_tools if isinstance(tool, FunctionTool)}
# If function tools exist in agent definition but were not provided,
# we need to raise an error, as it won't be possible to invoke the function.
missing_tools = [
tool.name for tool in (agent_tools or []) if isinstance(tool, FunctionTool) and tool.name not in tool_names
tool.name
for tool in (agent_tools or [])
if isinstance(tool, AzureFunctionTool) and tool.name not in tool_names
]
if missing_tools:
@@ -5,8 +5,8 @@ from collections.abc import Mapping, MutableMapping, Sequence
from typing import Any, ClassVar, Literal, cast
from agent_framework import (
AIFunction,
Content,
FunctionTool,
HostedCodeInterpreterTool,
HostedFileSearchTool,
HostedImageGenerationTool,
@@ -29,7 +29,6 @@ from azure.ai.projects.models import (
ApproximateLocation,
CodeInterpreterTool,
CodeInterpreterToolAuto,
FunctionTool,
ImageGenTool,
ImageGenToolInputImageMask,
MCPTool,
@@ -42,6 +41,9 @@ from azure.ai.projects.models import (
from azure.ai.projects.models import (
FileSearchTool as ProjectsFileSearchTool,
)
from azure.ai.projects.models import (
FunctionTool as AzureFunctionTool,
)
from pydantic import BaseModel
logger = get_logger("agent_framework.azure")
@@ -141,7 +143,7 @@ def to_azure_ai_agent_tools(
tool_definitions: list[ToolDefinition | dict[str, Any]] = []
for tool in tools:
match tool:
case AIFunction():
case FunctionTool():
tool_definitions.append(tool.to_json_schema_spec()) # type: ignore[reportUnknownArgumentType]
case HostedWebSearchTool():
additional_props = tool.additional_properties or {}
@@ -439,11 +441,11 @@ def to_azure_ai_tools(
container = CodeInterpreterToolAuto(file_ids=file_ids if file_ids else None)
ci_tool: CodeInterpreterTool = CodeInterpreterTool(container=container)
azure_tools.append(ci_tool)
case AIFunction():
case FunctionTool():
params = tool.parameters()
params["additionalProperties"] = False
azure_tools.append(
FunctionTool(
AzureFunctionTool(
name=tool.name,
parameters=params,
strict=False,