Integrate Logic App workflows as plugins with Semantic Kernel: Step-by-step guide
Semantic Kernel is a framework that integrates natural language processing (NLP) and AI into applications, making it easier to use advanced AI models. It is particularly powerful when combined with plugins, which extend its capabilities by connecting to a variety of external services.
Integrating Logic Apps as a plugin into Semantic Kernel enhances its functionality by providing access to over 1000 connectors, something that my colleague. Matthew has written about in the past. This integration allows for seamless connections with cloud services, on-premises systems, and hybrid environments. By using these plugins, customers can automate complex workflows, trigger actions, and interact with multiple systems. They can also effortlessly integrate their applications with diverse external systems, enabling them to leverage advanced features without the need for extensive custom development, thus saving time and resources.
So, let’s take a look at how to set up this integration. I have included sample here on GitHub to clone so you can follow through.
Here are the steps:
Setting up a Logic App
Deploying an OpenAI model
Configuring Easy Auth
Set up app registration
Add EasyAuth to Logic App (Standard)
Provide authentication details in the Semantic Kernel’s Program.cs file
Adding Logic App as plugin in Semantic Kernel
Testing the plugin
Setting up a Logic App
I have a Logic App (Standard) with two workflows:
One that retrieves active tickets for a particular location passed in as JSON payload
Another that provides weather updates also for a location
Both workflows use HTTP request-based triggers. Add a comment in the trigger describing the prompt that will trigger the workflow. For example, for the workflow that retrieves active tickets, you might use “retrieves active tickets” from Dataverse.
Make sure to have HTTP request trigger and response action so that the Semantic Kernel planner knows which workflow to call and return the appropriate response.
Configuring OpenAI
Create an OpenAI resource and , as you’ll need it along with the model details for the environment variables of the Semantic Kernel app. Here is where you can find the API key and endpoint in the OpenAI resource
Next, navigate to Azure OpenAI Studio from the “Overview” page of your newly created resource. Then, create a model deployment in the AI Studio.
Keep in mind:
Function calling is not supported by many OpenAI models. I made the mistake of using gpt-35-turbo, but with 0301 version, which did not work with Semantic Kernel. Check that support function calling and create deployment. I used GPT-4o as my base model.
Set a high token limit to prevent errors when your conversation exceeds the maximum token limit. I set it to 20k tokens per minute.
Configuring Easy Auth
Easy Auth for Logic Apps is a feature that provides built-in authentication and authorization, making it simple to secure your workflows. It supports various authentication providers like Azure Active Directory, Google, and Facebook, allowing users to log in with their existing credentials. Easy Auth handles token validation and authorization checks, ensuring that only authorized users can access your Logic Apps. This streamlined setup enhances security by protecting workflows and sensitive data without the need for custom code.
I have divided it in 3 sections to help with visualizing how to configure EasyAuth.
Create app registration:
In Azure Portal, search for “App registration”. If you do not already have one, please create a new app registration. Here is my App registration which has ClientID and other details that we will add in our Logic App in the next step.
Next, let’s add Scope which we will use in our Semantic Kernel application. Navigate to Manage->Expose an API to create a new Scope for your app registration. Fill out the necessary details, it would look something like this:
Add EasyAuth to Logic App:
Our team recently released a UI to help with configuring EasyAuth on your app. Follow these steps to fill out details to successfully set it up:
Open your Logic App (Standard) in Azure Portal
Navigate to Settings -> Authentication in your Logic App (Standard)
Click on “Add identity provider”
Client ID can be added from your app registration’s Overview page as shown in image from last step
Issuer URL: This is the URL of the identity provider that issued the token, it is in the format: https://sts.windows.net/{TenantID}
Note that you can also find TenantID from the “Overview” page of your app registration, just like how you found clientID
6. Allowed token audiences: Set this to the Application ID URI of your app. You can find that property in your App registration’s Manage->Expose an API blade in Portal TOC. It would be something like this:
7. Additional checks: Here is what you need to check for Client Application, Identity and Tenant requirements:
Click on “Add”. The identity provider would look something like this after adding:
Provide authentication details in Semantic Kernel:
In the Program.cs file, there are a few authentication details that need to be filled out. Follow the steps to get the right values:
ClientId and TenantId: this is the same as the one you copy/pasted from the App registration in previous steps
Authority: it will be in the format:
string Authority = $”https://login.microsoftonline.com/{Tenant_ID}”;
Scopes: this array variable will be the scope that we created in our app registration. It can be found in your App registration, Manage->Expose an API
And that is all you need to complete configuring EasyAuth successfully.
Adding Logic App as plugin in Semantic Kernel
With all the variables defined, you can now add the plugin to the Program.cs file of your Semantic Kernel application. Additionally, I’ve attached a sample on GitHub that you can clone to easily set up the application locally and get started.
Use the ImportPluginFromOpenAPIAsync() method, replacing the pluginName and uri parameters with the desired plugin name and name of your Logic App respectively, to add the plugin. It would look like this
To find the full code for Program.cs, please go to the sample GitHub sample attached or take a look at my colleague, Xuhong’s blog on how she plugs in logic app using the OpenAPI method.
5. Testing the plugin
Open the VS Code terminal and run the build command to identify any issues. Then, use dotnet run to start the application. You will be prompted to sign in from your account, and once authentication is complete, you can start conversing with the assistant.
Given the integration, you can ask questions like “What is the weather in Seattle” or “Retrieve all active tickets in Kirkland,” which should trigger the appropriate Logic App (Standard) workflow to get weather or get tickets. It will also pass in the location parameter as JSON payload to the workflow. Here is how my conversation looks like
Looking at logic app workflow that was triggered, one can see the run execution so it’s easy to visualize and troubleshoot what went wrong in your workflow plugin.
Here is what the run history looks like of the workflow being called:
Conclusion:
Integrating Logic Apps as a plugin in SDKs like Semantic Kernel opens new possibilities for pro-developers to utilize plugins beyond traditional languages like Python, .NET, and Java. With the extensive connectivity provided by Logic Apps, developers can interact with any system, extending beyond just RAG to more advanced agent capabilities for task completion. Additionally, nested workflows can function as separate agents to handle different aspects of a task based on the prompts provided. We invite your feedback on how we can enhance our platform capabilities to better support agent-based applications.
Appendix:
https://techcommunity.microsoft.com/t5/fasttrack-for-azure/integrating-logic-app-with-semantic-kernel-a-detailed-guide-and/ba-p/4184910
https://devblogs.microsoft.com/semantic-kernel/connect-logic-apps-1400-connectors-to-semantic-kernel/
Microsoft Tech Community – Latest Blogs –Read More