Azure AI Agent Service cannot successfully call provided actions, even though it will tell you it has the ability to.

JacksonAlvarez-5176 70 Reputation points
2025-05-06T18:00:47.3166667+00:00

After successfully setting up an agent, adding File Search capabilities, and preparing a REST API for my model to be able to call, it was unable to do so.

I tried to get the model to call the api functions in 2 ways, both in the Foundry Playground, and by creating a thread/message in a script. In the foundry playground, the model tries to call the function but then hangs, and in the script, it just gives the output below. Additionally, I tried setting up the api call in two different ways: the custom function calling method, and using its Open AI Spec. They both lead to the same issue.

Below is the setup script using the Azure Python SDK, and the terminal output when running it.

I am using gpt-o4-mini

CODE:

# Initialize agent toolset with user functions
    functions = FunctionTool(user_functions)
    toolset = ToolSet()
    toolset.add(functions)

    print('Toolset: ')
    print(toolset.get_definitions_and_resources())
    print()


    agent = project_client.agents.update_agent(agent_id=agent_id, toolset=toolset)

    print(f"Added toolset to agent")

    print(json.dumps(agent.as_dict(), indent=4))

    print()


    # Create thread for communication
    thread = project_client.agents.create_thread()
    print(f"Created thread")

    # Create message to thread
    message = project_client.agents.create_message(
        thread_id=thread.id,
        role="user",
        content="Hello, can you recommend me a water product?",
    )
    print(f"Created message")

    # Create and process agent run in thread with tools
    run = project_client.agents.create_and_process_run(thread_id=thread.id, agent_id=agent_id)
    print(f"Run finished with status: {run.status}")

    if run.status == "failed":
        print(f"Run failed: {run.last_error}")

    # Fetch and log all messages
    messages = project_client.agents.list_messages(thread_id=thread.id)
    print(f"Messages: {messages}")

OUTPUT:

Toolset:
{'tool_resources': {}, 'tools': [{'type': 'function', 'function': {'name': 'get_product_recommendation', 'description': "Returns a product based on an input preference value of 'Water', 'Land', or None", 'parameters': {'type': 'object', 'properties': {'preference': {'type': 'string', 'description': "The user's product line preference. Whether they like Land products, Water products, or have no preference (None)"}}, 'required': []}}}, {'type': 'function', 'function': {'name': 'get_available_parts_by_product', 'description': 'Returns the list of currently available parts for the input product', 'parameters': {'type': 'object', 'properties': {'product': {'type': 'string', 'description': "The user's given product. Can be any of these ['Jet Boats', 'Waverunners', 'Outboards', 'ATVs', 'Side by Sides', 'Motorcycles', 'Snowmobiles']"}}, 'required': ['product']}}}]}
Added toolset to agent
{
    "id": "[REDACTED]",
    "object": "assistant",
    "created_at": 1746118131,
    "name": "Agent168",
    "description": null,
    "model": "gpt-4o-mini",
    "instructions": "",
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_product_recommendation",
                "description": "Returns a product based on an input preference value of 'Water', 'Land', or None",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "preference": {
                            "type": "string",
                            "description": "The user's product line preference. Whether they like Land products, Water products, or have no preference (None)"
                        }
                    },
                    "required": []
                },
                "strict": false
            }
        },
        {
            "type": "function",
            "function": {
                "name": "get_available_parts_by_product",
                "description": "Returns the list of currently available parts for the input product",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "product": {
                            "type": "string",
                            "description": "The user's given product. Can be any of these ['Jet Boats', 'Waverunners', 'Outboards', 'ATVs', 'Side by Sides', 'Motorcycles', 'Snowmobiles']"
                        }
                    },
                    "required": [
                        "product"
                    ]
                },
                "strict": false
            }
        }
    ],
    "top_p": 1.0,
    "temperature": 1.0,
    "tool_resources": {
        "file_search": {
            "vector_store_ids": [
                "[REDACTED]"
            ]
        }
    },
    "metadata": {},
    "response_format": "auto"
}
Created thread
Created message
ERROR:root:Error executing function 'get_product_recommendation': Function 'get_product_recommendation' not found.
WARNING:root:Tool outputs contain errors - retrying
Run finished with status: RunStatus.COMPLETED
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,602 questions
{count} vote

Accepted answer
  1. Osama Tarek 105 Reputation points
    2025-05-19T06:52:03.9133333+00:00

    try to add this line to your code

    (1.0.0b9 version works)

    project_client.agents.enable_auto_function_calls(toolset=toolset)
    

    according to this github issue : https://github.com/Azure/azure-sdk-for-python/issues/40782

    import os
    from azure.ai.projects import AIProjectClient
    from azure.identity import DefaultAzureCredential
    from azure.ai.projects.models import FunctionTool, ToolSet
    from user_function import fetch_weather # user functions which can be found in a user_functions.py file.
    
    
    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
    
    # Create an Azure AI Client from a connection string, copied from your Azure AI Foundry project.
    # It should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
    # Customers need to login to Azure subscription via Azure CLI and set the environment variables
    
    
    project_client = AIProjectClient.from_connection_string(
        credential=DefaultAzureCredential(),
        conn_str="<projectconnectionstring",
    )
    
    # Initialize agent toolset with user functions
    functions = FunctionTool([fetch_weather])
    toolset = ToolSet()
    toolset.add(functions)
    project_client.agents.enable_auto_function_calls(toolset=toolset)
    agent = project_client.agents.create_agent(
        model="Mistral-Large-2411-jkxfu", name="my-agent-2", instructions="You are a weather bot. Use the provided functions to help answer questions.", toolset=toolset
    )
    print(f"Created agent, ID: {agent.id}")
    
    # Create thread for communication
    thread = project_client.agents.create_thread()
    print(f"Created thread, ID: {thread.id}")
    
    # Create message to thread
    message = project_client.agents.create_message(
        thread_id=thread.id,
        role="user",
        content="Hello, send an email with the datetime and weather information in New York?",
    )
    print(f"Created message, ID: {message.id}")
    # Create and process agent run in thread with tools
    run = project_client.agents.create_and_process_run(thread_id=thread.id, agent_id=agent.id)
    print(f"Run finished with status: {run.status}")
    
    if run.status == "failed":
        print(f"Run failed: {run.last_error}")
    
    # Delete the agent when done
    project_client.agents.delete_agent(agent.id)
    print("Deleted agent")
    
    # Fetch and log all messages
    messages = project_client.agents.list_messages(thread_id=thread.id)
    print(f"Messages: {messages}")
    

    it solved the issue for me. Thank you

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sina Salam 22,031 Reputation points Volunteer Moderator
    2025-05-18T19:47:44.88+00:00

    Hello JacksonAlvarez-5176,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you're having persistent issues with Azure AI Agent Service when trying to invoke custom functions using the GPT-4o-mini model.

    Your issue is not due to misconfiguration but rather a limitation of the GPT-4o-mini model. Switching to a stable model or implementing manual function handling are the most reliable paths forward.

    Note while your toolset correctly lists the functions, the model fails to execute them due to a known bug where GPT-4o-mini cannot reliably resolve or invoke registered functions at runtime. This is a model-specific issue that has been reported by multiple users and acknowledged in the community forums. Therefore, even though your code and configuration appear correct, the model’s internal function resolution mechanism is currently unreliable.

    Therefore, the most effective solution is to switch to a more stable model like GPT-4o or GPT-4, which have proven to handle function calling more reliably. If switching models is not an option, a practical workaround is to implement manual function invocation. This involves prompting the model to return a structured JSON intent, parsing that intent in your backend, executing the corresponding function manually, and then feeding the result back into the conversation. This approach bypasses the model’s unreliable auto-invocation logic while preserving the interactive experience.

    Additionally, be sure you have Azure SDK up to date and that you’re using the latest API parameters. Replace deprecated fields like functions and function_call with tools and tool_choice, as outlined in the latest Azure documentation.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.