|
| 1 | +--- |
| 2 | +title: 'How to use Assistants with Logic apps' |
| 3 | +titleSuffix: Azure OpenAI |
| 4 | +description: Learn how to create helpful AI Assistants with Logic apps. |
| 5 | +services: cognitive-services |
| 6 | +manager: nitinme |
| 7 | +ms.service: azure-ai-openai |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 05/21/2024 |
| 10 | +author: aahill |
| 11 | +ms.author: aahi |
| 12 | +recommendations: false |
| 13 | +--- |
| 14 | + |
| 15 | +# Call Azure Logic apps as functions using Azure OpenAI Assistants |
| 16 | + |
| 17 | +[Azure Logic Apps](https://azure.microsoft.com/products/logic-apps) is an integration platform in Azure that allows you to build applications and automation workflows with low code tools enabling developer productivity and faster time to market. By using the visual designer and selecting from hundreds of prebuilt connectors, you can quickly build a workflow that integrates and manages your apps, data, services, and systems. |
| 18 | + |
| 19 | +Azure Logic Apps is fully managed by Microsoft Azure, which frees you from worrying about hosting, scaling, managing, monitoring, and maintaining solutions built with these services. When you use these capabilities to create [serverless](../../../logic-apps/logic-apps-overview.md) apps and solutions, you can just focus on the business logic and functionality. These services automatically scale to meet your needs, make automation workflows faster, and help you build robust cloud apps using little to no code. |
| 20 | + |
| 21 | +To accelerate and simplify the creation of intelligent applications, we are now enabling the ability to call Logic Apps workflows through function calling in Azure OpenAI Assistants. |
| 22 | + |
| 23 | +The Assistants playground enumerates and lists all the workflows in your subscription that are eligible for function calling. Here are the requirements for these workflows: |
| 24 | + |
| 25 | +* Consumption Logic Apps: Currently we only support consumption workflows. |
| 26 | +* Request Trigger: Function calling requires a REST-based API. Logic Apps with a request trigger provides a REST endpoint. Therefore only workflows with a request trigger are supported for function calling. |
| 27 | +* Schema: The workflows you want to use for function calling should have a JSON schema describing the inputs and expected outputs. Using Logic Apps you can streamline and provide schema in the trigger which would be automatically imported as a function definition. |
| 28 | + |
| 29 | +## Import your Logic Apps workflows as functions |
| 30 | + |
| 31 | +Here are the steps to import your Logic Apps workflows as function in the Assistants playground in Azure Open AI Studio: |
| 32 | + |
| 33 | +1. In Azure OpenAI Studio, select **Assistants**. Select an existing Assistant or create a new one. After you have configured the assistant with a name and instructions, you are ready to add a function. Select **+ Add function**. |
| 34 | + |
| 35 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\assistants-playground-add-function.png" alt-text="A screenshot showing the Assistant playground with the add function button." lightbox="..\media\how-to\assistants\logic-apps\assistants-playground-add-function.png::: |
| 36 | + |
| 37 | +1. The **Add function** option opens a screen with two tabs. Navigate to the tab for Logic Apps to browse your workflows with a request trigger. Select the workflow from list and select **Save**. |
| 38 | + |
| 39 | + > [!NOTE] |
| 40 | + > This list only shows the consumption SKU workflows and with a request trigger. |
| 41 | +
|
| 42 | + |
| 43 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\import-logic-apps.png" alt-text="A screenshot showing the Assistant playground with the add function button." lightbox="..\media\how-to\assistants\logic-apps\import-logic-apps.png::: |
| 44 | + |
| 45 | + |
| 46 | +## What happens when a Logic Apps is imported in AI Studio and invoked |
| 47 | + |
| 48 | +**The Logic Apps swagger file is used to populate function definitions** |
| 49 | + |
| 50 | +Azure Logic App publishes an OpenAPI 2.0 definition (swagger) for workflows with a request trigger based on [annotations on the workflow](/rest/api/logic/workflows/list-swagger). Users are able to modify the content of this swagger by updating their workflow. AI studio uses this to generate the function definitions that the Assistant requires. |
| 51 | + |
| 52 | +**How does authentication from AI Studio to Logic Apps work?** |
| 53 | + |
| 54 | +Logic Apps support two primary types of authentications to invoke a request trigger. |
| 55 | + |
| 56 | +* Shared Access Signature (SAS) based authentication. |
| 57 | + |
| 58 | + Users can obtain a callback URL containing a SAS using the [list callback URL](/rest/api/logic/workflows/list-callback-url) API. Logic Apps also support using multiple keys and rotating them as needed. Logic Apps also support creating SAS URLs with a specified validity period. For more information, see the [Logic Apps documentation](../../../logic-apps/logic-apps-securing-a-logic-app.md#generate-shared-access-signatures-sas). |
| 59 | + |
| 60 | +* Microsoft Entra ID-based OAuth base authentication policy. |
| 61 | + |
| 62 | + Logic Apps also support authentication trigger invocations with Microsoft Entra ID OAuth, where you can specify authentication policies to be used in validating OAuth tokens. For more information, see the [Logic Apps documentation](../../../logic-apps/logic-apps-securing-a-logic-app.md#generate-shared-access-signatures-sas). |
| 63 | + |
| 64 | +When Azure OpenAI Assistants requires invoking a Logic App as part of function calling, AI Studio will retrieve the callback URL with the SAS to invoke the workflow. |
| 65 | + |
| 66 | +## Create Logic Apps workflows for function calling |
| 67 | +Here are the steps to create a new Logic Apps workflow for function calling. |
| 68 | + |
| 69 | +1. In the Azure portal search box, enter **logic apps**, and select **Logic apps**. |
| 70 | +1. On the Logic apps page toolbar, select **Add**. |
| 71 | +1. On the Create Logic App page, first select the Plan type for your logic app resource. That way, only the options for that plan type appear. |
| 72 | +1. In the **Plan** section, for the Plan type, select **Consumption** to view only the consumption logic app resource settings. |
| 73 | +1. Provide the following information for your logic app resource: Subscription, Resource Group, Logic App name, and Region. |
| 74 | +1. When you're ready, select **Review + Create**. |
| 75 | +1. On the validation page that appears, confirm all the provided information, and select **Create**. |
| 76 | +1. After Azure successfully deploys your logic app resource, select **Go to resource**. Or, find and select your logic app resource by typing the name in the Azure search box. |
| 77 | +1. Open the Logic Apps workflow in designer. Select Development Tools + Logic app designer. This opens your empty workflow in designer. Or you select Blank Logic App from templates |
| 78 | +1. Now you're ready to add one more step in the workflow. A workflow always starts with a single trigger, which specifies the condition to meet before running any subsequent actions in the workflow. |
| 79 | +1. Your workflow is required to have a Request trigger to generate a REST endpoint, and a response action to return the response to AI Studio when this workflow is invoked. |
| 80 | +1. Add a trigger [(Request)](../../../connectors/connectors-native-reqres.md?tabs=consumption) |
| 81 | + |
| 82 | + Select **Add a trigger** and then search for request trigger. Select the **When a HTTP request is received** operation. |
| 83 | + |
| 84 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\create-logic-app-1.png" alt-text="A screenshot showing the Logic Apps designer." lightbox="..\media\how-to\assistants\logic-apps\create-logic-app-1.png::: |
| 85 | + |
| 86 | + Provide the JSON schema for the request. If you do not have the schema use the option to generate schema. |
| 87 | + |
| 88 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\create-logic-app-2.png" alt-text="A screenshot showing the option to provide a JSON schema." lightbox="..\media\how-to\assistants\logic-apps\create-logic-app-2.png::: |
| 89 | + |
| 90 | + Here is an example of the request schema. You can add a description for your workflow in the comment box. This is imported by AI Studio as the function description. |
| 91 | + |
| 92 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\create-logic-app-3.png" alt-text="A screenshot showing an example request schema." lightbox="..\media\how-to\assistants\logic-apps\create-logic-app-3.png::: |
| 93 | + |
| 94 | + Save the workflow. This will generate the REST endpoint for the workflow. |
| 95 | + |
| 96 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\create-logic-app-4.png" alt-text="A screenshot showing the REST endpoint." lightbox="..\media\how-to\assistants\logic-apps\create-logic-app-4.png::: |
| 97 | + |
| 98 | +1. Depending on the business use case, you can now add one or more steps/actions in this workflow. For example, using the MSN weather connector to get the weather forecast for the current location. |
| 99 | + |
| 100 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\create-logic-app-5.png" alt-text="A screenshot showing the MSN weather connector." lightbox="..\media\how-to\assistants\logic-apps\create-logic-app-5.png::: |
| 101 | + |
| 102 | + In the action to **get forecast for today**, we are using the **location** property that was passed to this workflow as an input. |
| 103 | + |
| 104 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\create-logic-app-6.png" alt-text="A screenshot showing the location property." lightbox="..\media\how-to\assistants\logic-apps\create-logic-app-6.png::: |
| 105 | + |
| 106 | +1. Configure the [response](../../../connectors/connectors-native-reqres.md#add-a-response-action). The workflow needs to return the response back to AI Studio. This is done using Response action. |
| 107 | + |
| 108 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\create-logic-app-7.png" alt-text="A screenshot showing the response action." lightbox="..\media\how-to\assistants\logic-apps\create-logic-app-7.png::: |
| 109 | + |
| 110 | + In the response action, you can pick the output from any of the prior steps. You can optionally also provide a JSON schema if you want to return the output in a specific format. |
| 111 | + |
| 112 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\create-logic-app-7.png" alt-text="A screenshot showing the comment box to specify a JSON schema." lightbox="..\media\how-to\assistants\logic-apps\create-logic-app-7.png::: |
| 113 | + |
| 114 | +1. The workflow is now ready. In AI Studio, you can import this function using the **Add function** feature in the Assistants playground. |
| 115 | + |
| 116 | + :::image type="content" source="..\media\how-to\assistants\logic-apps\assistants-playground-add-function.png" alt-text="A screenshot showing the Assistant playground." lightbox="..\media\how-to\assistants\logic-apps\assistants-playground-add-function.png::: |
| 117 | + |
| 118 | +Azure Logic Apps has connectors to hundreds of line-of-business (LOB) applications and databases including but not limited to: SAP, Salesforce, Oracle, SQL, and more. You can also connect to SaaS applications or your in-house applications hosted in virtual networks. These out of box connectors provide operations to send and receive data in multiple formats. Leveraging these capabilities with Azure Open AI assistants, you should be able to quickly bring your data for Intelligent Insights powered by Azure Open AI. |
| 119 | + |
| 120 | +## See also |
| 121 | + |
| 122 | +* [Learn more about Assistants](../concepts/assistants.md) |
0 commit comments