欧博allbetunable to register and run custom function
i am trying to build a agenti ai using custom call as per the azure document.
https://learn.microsoft.com/en-us/azure/ai-services/agents/how-to/tools/function-calling?tabs=python&pivots=code-examplei followed the exact code in my code base, however when running the agent, i am getting below error,
import json import datetime from typing import Any, Callable, Set, Dict, List, Optional def fetch_weather(location: str) -> str: """ Fetches the weather information for the specified location. :param location (str): The location to fetch weather for. :return: Weather information as a JSON string. :rtype: str """ # In a real-world scenario, you'd integrate with a weather API. # Here, we'll mock the response. mock_weather_data = {"New York": "Sunny, 25°C", "London": "Cloudy, 18°C", "Tokyo": "Rainy, 22°C"} weather = mock_weather_data.get(location, "Weather data not available for this location.") weather_json = json.dumps({"weather": weather}) return weather_json # Statically defined user functions for fast reference user_functions: Set[Callable[..., Any]] = { fetch_weather, } functions = FunctionTool(user_functions) ## Create a function tool to bind the function toolset = ToolSet() # toolset.add(functions) ERROR:root:Error executing function 'fetch_weather': Function 'fetch_weather' not found. WARNING:root:Tool outputs contain errors - retrying ERROR:root:Error executing function 'fetch_weather': Function 'fetch_weather' not found.though it creating the agent and thread, but invoking function fails.
2025-08-07 09:38 点击量:12