azure-sdk-for-python: AI Project client says "Invalid tool value(s): azure_function"

Hi all, I have been trying to create an agent with an azure function (queue trigger) deployed into azure with the azure ai foundry SDK. The only problem is when i create an agent with tool as the azure function, it fails saying: “Invalid tool value(s): azure_function”

Pasting the code for reference:

import os
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
from dotenv import load_dotenv

load_dotenv()

project_connection_string = os.getenv("PROJECT_CONNECTION_STRING")
model=os.getenv("MODEL_DEPLOYMENT_NAME")
storage_connection_string = os.getenv("STORAGE_CONNECTION_queueServiceUri")
input_queue_name = os.getenv("INPUT_QUEUE_NAME")
output_queue_name = os.getenv("OUTPUT_QUEUE_NAME")

project_client = AIProjectClient.from_connection_string(
        credential=DefaultAzureCredential(),
        conn_str=project_connection_string
    )



agent = project_client.agents.create_agent(
        model=model,
        name="azure-function-agent",
        instructions="You are a helpful support agent. Answer the user's questions to the best of your ability.",
        headers={"x-ms-enable-preview": "true"},
        tools=[
            {
                "type": "azure_function",
                "azure_function": {
                    "function": {
                        "name": "queue_trigger1",
                        "description": "Deliver a DeathNote to the user in Batman's style.",
                        "parameters": {
                            "type": "object",
                            "properties": {
                                "name": {"type": "string", "description": "the name of the user or the name of the person to which the deathnote is to be delivered."},
                            },
                            "required": ["name"]
                        }
                    },
                    "input_binding": {
                        "type": "storage_queue",
                        "storage_queue": {
                            "queue_service_uri": storage_connection_string,
                            "queue_name": input_queue_name
                        }
                    },
                    "output_binding": {
                        "type": "storage_queue",
                        "storage_queue": {
                            "queue_service_uri": storage_connection_string,
                            "queue_name": output_queue_name
                        }
                    }
                }
            }
        ],
    )

thread = project_client.agents.create_thread()

message = project_client.agents.create_message(
        thread_id=thread.id,
        role="user",
        content="deliver a deathnote by batman to Kuljot",
)
print(f"Created message, ID: {message.id}")

# Create and process agent run in thread with azure function supplied as a tool
run = project_client.agents.create_and_process_run(thread_id=thread.id, assistant_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)
#Displaying the assistant response
print(messages.data[0].content[0].text.value)
    

Any help or resolution would be highly appreciated!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 36 (10 by maintainers)

Most upvoted comments

@DennesTorres By the way I also found a way to create the capability host and attach to “Azure AI Hub” via the az CLI which could be run in a CloudShell Session in Azure Portal: az ml capability-host create --name my-host-name --resource-group my-resource-group --workspace-name my-workspace Read more at : https://learn.microsoft.com/en-us/cli/azure/ml/capability-host?view=azure-cli-latest I will to try this out; during the time I tested, this documentation wasn’t available so definitely something new to consider 😃

@kuljotSB Thank you for the suggestion. I checked the documentation as well, but I got errors in one parameter (service connections or similar). I can see you are not using it. I will try this if needed.

I tried to update the SDK and I think I managed to make it work. The documention is a bit mixed, the code is slightly different and there is the requirement of specific RBAC permissions, but it seems it worked.

The functions linked to the agent don’t appear in the UI in Foundry. Is this correct? I still need to advance the tests and ensure the agent calls the function correctly.

yeah the functions sometime don’t appear up (possible because the foundry seems to be still in “preview”)…so yeah testing is pretty much required still 😦

@DennesTorres By the way I also found a way to create the capability host and attach to “Azure AI Hub” via the az CLI which could be run in a CloudShell Session in Azure Portal:

az ml capability-host create --name my-host-name --resource-group my-resource-group --workspace-name my-workspace

Read more at : https://learn.microsoft.com/en-us/cli/azure/ml/capability-host?view=azure-cli-latest

I will to try this out; during the time I tested, this documentation wasn’t available so definitely something new to consider 😃

@kuljotSB Thank you for the suggestion. I checked the documentation as well, but I got errors in one parameter (service connections or similar). I can see you are not using it. I will try this if needed.

I tried to update the SDK and I think I managed to make it work. The documention is a bit mixed, the code is slightly different and there is the requirement of specific RBAC permissions, but it seems it worked.

The functions linked to the agent don’t appear in the UI in Foundry. Is this correct? I still need to advance the tests and ensure the agent calls the function correctly.