This sample highlights how to use the Azure AI Agent service function calling where function calls are placed on a storage queue by the Agent service to be processed by an Azure Function listening to that queue.
You can learn more about Azure functions in the Official documentation
The app
folder contains the function code used in this sample while the infra folder contains all of the Azure resources that need to be created.
Once you have your Azure subscription, run the following in a new terminal window to create Azure OpenAI and other resources needed:
azd init --template https://github.com/Azure-Samples/azure-functions-ai-services-agent-python
Mac/Linux:
chmod +x ./infra/scripts/*.sh
Windows:
set-executionpolicy remotesigned
Run the follow command to provision resources in Azure
azd provision
Create local.settings.json (Should be in the same folder as host.json. Automatically created if you ran azd provision)
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"STORAGE_CONNECTION__queueServiceUri": "https://<storageaccount>.queue.core.windows.net",
"PROJECT_CONNECTION_STRING": "<project connnection for AI Project>",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
}
- Open the folder in a new terminal.
- Run the
code .
code command to open the project in Visual Studio Code. - In the command palette (F1), type
Azurite: Start
, which enables debugging with local storage for Azure Functions runtime. - Press Run/Debug (F5) to run in the debugger. Select Debug anyway if prompted about local emulator not running.
- Send POST
prompt
endpoints respectively using your HTTP test tool. If you have the RestClient extension installed, you can execute requests directly from thetest.http
project file.
Run this command to provision the function app, with any required Azure resources, and deploy your code:
azd up
You're prompted to supply these required deployment parameters:
Parameter | Description |
---|---|
Environment name | An environment that's used to maintain a unique deployment context for your app. You won't be prompted if you created the local project using azd init . |
Azure subscription | Subscription in which your resources are created. |
Azure location | Azure region in which to create the resource group that contains the new Azure resources. Only regions that currently support the Flex Consumption plan are shown. |
After publish completes successfully, azd
provides you with the URL endpoints of your new functions, but without the function key values required to access the endpoints. To learn how to obtain these same endpoints along with the required function keys, see Invoke the function on Azure in the companion article Quickstart: Create and deploy functions to Azure Functions using the Azure Developer CLI.
You can run the azd up
command as many times as you need to both provision your Azure resources and deploy code updates to your function app.
Note
Deployed code files are always overwritten by the latest deployment package.
When you're done working with your function app and related resources, you can use this command to delete the function app and its related resources from Azure and avoid incurring any further costs (--purge does not leave a soft delete of AI resource and recovers your quota):
azd down --purge