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
@@ -19,6 +19,7 @@ import uvicorn
# Agent Framework imports
from agent_framework import AgentResponseUpdate, ChatAgent, ChatMessage, FunctionResultContent, Role
from agent_framework import tool
from agent_framework.azure import AzureOpenAIChatClient
# Agent Framework ChatKit integration
@@ -130,7 +131,8 @@ async def stream_widget(
yield ThreadItemDoneEvent(type="thread.item.done", item=widget_item)
# 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")
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
) -> str:
@@ -168,14 +170,14 @@ def get_weather(
)
return WeatherResponse(text, weather_data)
@tool(approval_mode="never_require")
def get_time() -> str:
"""Get the current UTC time."""
current_time = datetime.now(timezone.utc)
logger.info("Getting current UTC time")
return f"Current UTC time: {current_time.strftime('%Y-%m-%d %H:%M:%S')} UTC"
@tool(approval_mode="never_require")
def show_city_selector() -> str:
"""Show an interactive city selector widget to the user.
@@ -17,6 +17,7 @@ from random import randint
from typing import Annotated
from agent_framework import ChatAgent
from agent_framework import tool
from agent_framework.openai import OpenAIChatClient
from aiohttp import web
from aiohttp.web_middlewares import middleware
@@ -76,7 +77,8 @@ def load_app_config() -> AppConfig:
port = 3978
return AppConfig(use_anonymous_mode=use_anonymous_mode, port=port, agents_sdk_config=agents_sdk_config)
# 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")
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
) -> str:
@@ -4,7 +4,7 @@ import json
from datetime import datetime
from typing import Annotated
from agent_framework import ai_function
from agent_framework import tool
from pydantic import Field
# --- Travel Planning Tools ---
@@ -13,7 +13,7 @@ from pydantic import Field
# Mock hotel search tool
@ai_function(name="search_hotels", description="Search for available hotels based on location and dates.")
@tool(name="search_hotels", description="Search for available hotels based on location and dates.")
def search_hotels(
location: Annotated[str, Field(description="City or region to search for hotels.")],
check_in: Annotated[str, Field(description="Check-in date (e.g., 'December 15, 2025').")],
@@ -83,7 +83,7 @@ def search_hotels(
# Mock hotel details tool
@ai_function(name="get_hotel_details", description="Get detailed information about a specific hotel.")
@tool(name="get_hotel_details", description="Get detailed information about a specific hotel.")
def get_hotel_details(
hotel_name: Annotated[str, Field(description="Name of the hotel to get details for.")],
) -> str:
@@ -158,7 +158,7 @@ def get_hotel_details(
# Mock flight search tool
@ai_function(name="search_flights", description="Search for available flights between two locations.")
@tool(name="search_flights", description="Search for available flights between two locations.")
def search_flights(
origin: Annotated[str, Field(description="Departure airport or city (e.g., 'JFK' or 'New York').")],
destination: Annotated[str, Field(description="Arrival airport or city (e.g., 'CDG' or 'Paris').")],
@@ -284,7 +284,7 @@ def search_flights(
# Mock flight details tool
@ai_function(name="get_flight_details", description="Get detailed information about a specific flight.")
@tool(name="get_flight_details", description="Get detailed information about a specific flight.")
def get_flight_details(
flight_number: Annotated[str, Field(description="Flight number (e.g., 'AF007' or 'DL264').")],
) -> str:
@@ -324,7 +324,7 @@ def get_flight_details(
# Mock activity search tool
@ai_function(name="search_activities", description="Search for available activities and attractions at a destination.")
@tool(name="search_activities", description="Search for available activities and attractions at a destination.")
def search_activities(
location: Annotated[str, Field(description="City or region to search for activities.")],
date: Annotated[str | None, Field(description="Date for the activity (e.g., 'December 16, 2025').")] = None,
@@ -468,7 +468,7 @@ def search_activities(
# Mock activity details tool
@ai_function(name="get_activity_details", description="Get detailed information about a specific activity.")
@tool(name="get_activity_details", description="Get detailed information about a specific activity.")
def get_activity_details(
activity_name: Annotated[str, Field(description="Name of the activity to get details for.")],
) -> str:
@@ -545,7 +545,7 @@ def get_activity_details(
# Mock booking confirmation tool
@ai_function(name="confirm_booking", description="Confirm a booking reservation.")
@tool(name="confirm_booking", description="Confirm a booking reservation.")
def confirm_booking(
booking_type: Annotated[str, Field(description="Type of booking (e.g., 'hotel', 'flight', 'activity').")],
booking_id: Annotated[str, Field(description="Unique booking identifier.")],
@@ -579,7 +579,7 @@ def confirm_booking(
# Mock hotel availability check tool
@ai_function(name="check_hotel_availability", description="Check availability for hotel rooms.")
@tool(name="check_hotel_availability", description="Check availability for hotel rooms.")
def check_hotel_availability(
hotel_name: Annotated[str, Field(description="Name of the hotel to check availability for.")],
check_in: Annotated[str, Field(description="Check-in date (e.g., 'December 15, 2025').")],
@@ -614,7 +614,7 @@ def check_hotel_availability(
# Mock flight availability check tool
@ai_function(name="check_flight_availability", description="Check availability for flight seats.")
@tool(name="check_flight_availability", description="Check availability for flight seats.")
def check_flight_availability(
flight_number: Annotated[str, Field(description="Flight number to check availability for.")],
date: Annotated[str, Field(description="Flight date (e.g., 'December 15, 2025').")],
@@ -647,7 +647,7 @@ def check_flight_availability(
# Mock activity availability check tool
@ai_function(name="check_activity_availability", description="Check availability for activity bookings.")
@tool(name="check_activity_availability", description="Check availability for activity bookings.")
def check_activity_availability(
activity_name: Annotated[str, Field(description="Name of the activity to check availability for.")],
date: Annotated[str, Field(description="Activity date (e.g., 'December 16, 2025').")],
@@ -680,7 +680,7 @@ def check_activity_availability(
# Mock payment processing tool
@ai_function(name="process_payment", description="Process payment for a booking.")
@tool(name="process_payment", description="Process payment for a booking.")
def process_payment(
amount: Annotated[float, Field(description="Payment amount.")],
currency: Annotated[str, Field(description="Currency code (e.g., 'USD', 'EUR').")],
@@ -714,7 +714,7 @@ def process_payment(
# Mock payment validation tool
@ai_function(name="validate_payment_method", description="Validate a payment method before processing.")
@tool(name="validate_payment_method", description="Validate a payment method before processing.")
def validate_payment_method(
payment_method: Annotated[dict, Field(description="Payment method to validate (type, number, expiry, cvv).")],
) -> str:
@@ -57,6 +57,7 @@ from agent_framework import (
WorkflowOutputEvent,
executor,
handler,
tool,
)
from agent_framework.azure import AzureAIClient
from azure.ai.projects.aio import AIProjectClient