[Python] Azure Agentic AI- unable to register and run custom function call

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo

    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-example


    i 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.

    Continue reading...

Compartilhe esta Página