Azure AI Agent Service cannot successfully call provided actions, even though it will tell you it has the ability to.
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