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
@@ -4,7 +4,7 @@ import asyncio
from collections.abc import Awaitable, Callable
from typing import Annotated
from agent_framework import FunctionInvocationContext, ai_function, function_middleware
from agent_framework import FunctionInvocationContext, tool, function_middleware
from agent_framework.openai import OpenAIChatClient
from pydantic import Field
@@ -81,7 +81,8 @@ class SessionContextContainer:
runtime_context = SessionContextContainer()
@ai_function
# NOTE: approval_mode="never_require" is for sample brevity. Use "always_require" in production; see samples/getting_started/tools/function_tool_with_approval.py and samples/getting_started/tools/function_tool_with_approval_and_threads.py.
@tool(approval_mode="never_require")
async def send_email(
to: Annotated[str, Field(description="Recipient email address")],
subject: Annotated[str, Field(description="Email subject line")],
@@ -112,7 +113,7 @@ async def send_email(
return f"Email sent to {to} from user {user_id} (tenant: {tenant}). Subject: '{subject}'"
@ai_function
@tool(approval_mode="never_require")
async def send_notification(
message: Annotated[str, Field(description="Notification message to send")],
priority: Annotated[str, Field(description="Priority level: low, medium, high")] = "medium",
@@ -241,7 +242,7 @@ async def pattern_1_single_agent_with_closure() -> None:
# Create tools for sub-agents (these will use kwargs propagation)
@ai_function
@tool(approval_mode="never_require")
async def send_email_v2(
to: Annotated[str, Field(description="Recipient email")],
subject: Annotated[str, Field(description="Subject")],
@@ -253,7 +254,7 @@ async def send_email_v2(
return f"Email sent to {to} with subject '{subject}'"
@ai_function
@tool(approval_mode="never_require")
async def send_sms(
phone: Annotated[str, Field(description="Phone number")],
message: Annotated[str, Field(description="SMS message")],
@@ -377,7 +378,7 @@ class AuthContextMiddleware:
await next(context)
@ai_function
@tool(approval_mode="never_require")
async def protected_operation(operation: Annotated[str, Field(description="Operation to perform")]) -> str:
"""Protected operation that requires authentication."""
return f"Executed protected operation: {operation}"