Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 59

Integrating Copilot Studio with Power Automate

Recommended resources

Hello! Welcome back to your advanced Power Platform developer training.

In our last lesson, we focused on making our chatbot intelligent by managing conversation state with variables and extracting structured data from user input using entities. We learned how to get the "what" from the user—like a city, a date, or a product ID.

Today, we're building the crucial bridge between conversation and execution. We'll learn how to integrate Copilot Studio with Power Automate flows to perform backend actions. This is where your copilot transitions from being a conversationalist to being a productive agent that can create records, query databases, send notifications, and interact with the vast ecosystem of services connected to Power Automate. This skill is central to the PL-400 exam and to building any copilot with real-world utility.

1. From Conversation to Action: Introducing Agent Flows

Your experience with Dynamics 365 plugins and workflows has taught you the importance of separating user interface logic from backend business processing. The same principle applies here: Copilot Studio excels at managing the conversation, while Power Automate excels at orchestrating actions.

The modern way to achieve this integration is through Agent Flows. These are essentially Power Automate cloud flows that are built for, and run within, the Copilot Studio context. This means they use Copilot Studio's licensing (message packs) rather than requiring a separate Power Automate premium license for the user or flow. You can use any premium connector within an Agent Flow, making them incredibly powerful.

To get a comprehensive overview of what Agent Flows are and what they can do, let's watch a detailed tutorial from Reza Dorrani.

Agent Flows in Copilot Studio | Complete Tutorial

This video, 'Agent Flows in Copilot Studio | Complete Tutorial', provides an excellent, up-to-date look at building and using Agent Flows. It covers everything from simple notifications to complex, multi-stage approvals.

Please watch the following three segments: Introduction to Agent Flows (00:32 - 03:29): Focus on understanding what Agent Flows are and the help desk use case presented. Building the Flow (03:29 - 06:28): Observe how a flow is triggered by a SharePoint event and uses actions like 'Get user profile', 'Send an email', and a 'Switch' condition. This demonstrates the standard Power Automate experience within this new context. Calling an Agent Flow from a Topic (19:28 - 22:08): This is the most critical part for our lesson. Pay close attention to how a topic in the copilot calls the agent flow, passes an input (Employee ID), and receives an output (Leave Balance).


2. The Core Mechanism: Inputs and Outputs

As the video demonstrated, the communication between a Copilot Studio topic and an Agent Flow is handled through a clearly defined data contract: inputs and outputs. This is analogous to passing parameters to a method in C# and receiving a return value.

  1. Copilot Topic -> Flow (Inputs): Your topic collects information from the user (using a Question node with entities, as we learned last lesson) and stores it in topic variables. You then pass these variables as inputs to the Agent Flow.
  2. Flow -> Copilot Topic (Outputs): The flow performs its actions (e.g., querying a database, calling an API) and then sends the results back to the topic as output variables. These variables can then be used in the conversation, for example, in a Message node to present the result to the user.

Let's look at the basic mechanics of setting this up.

Use input and output variables to pass information

This Microsoft Learn document, 'Use input and output variables', provides the official step-by-step instructions for this process. We'll use it as a reference for the fundamental steps.

Please review the sections 'Add an input parameter to the flow', 'Add an output parameter to the flow', and 'Call the flow from the topic'. The screenshots clearly illustrate where to click in both the Power Automate and Copilot Studio interfaces to define and map these variables.

The process you just reviewed can be visualized like this:

Copilot Studio Power Automate Flow Integration: Inputs and Outputs
This image shows the Action node in the Copilot Studio authoring canvas. It clearly visualizes the mapping of topic variables to the flow's inputs (like 'City' and 'ZIP code') and the flow's outputs (like 'day_summary') being made available to the topic.

3. Building and Troubleshooting a Practical Flow

All your existing Power Automate skills are directly transferable to building Agent Flows. You can create complex, multi-step automations involving data transformations, loops, and calls to any of the 1000+ available connectors.

Let's watch a practical example of building a more complex flow and, importantly, learn how to troubleshoot it when things go wrong.

Using Microsoft Power Automate with Copilot Studio | EP27

In this video from the official Microsoft Power Platform channel, Shane Young demonstrates creating a flow from scratch to generate a CSV file. He also provides a crucial tip for debugging.

Please watch these two key sections: Building a New Flow (09:24 - 16:41): Follow along as a flow is built that gets data from SharePoint, creates a CSV table, saves it as a file, and generates a sharing link. Notice how the flow is initiated from Copilot Studio and uses the standard Power Automate designer. Troubleshooting Flow Errors (16:41 - 17:45): This is a vital skill. Pay close attention to what to do when your copilot returns an error from a flow. The key takeaway is that you debug the flow by checking its run history in the Power Automate portal, not within Copilot Studio.

Professional Error Handling

As a developer, you know that simply letting an unhandled exception bubble up to the user is poor practice. When a backend flow fails, your copilot shouldn't just display a raw error message like "BadGateway".

You can create a more professional user experience by handling these failures gracefully within Copilot Studio. The Action node has an On Error path that you can use to catch failures and guide the user.

Implementing Error Handling in Copilot Studio with Power Automate
This diagram illustrates a robust error handling pattern. A failed flow run is detected, and instead of showing a technical error, the copilot displays a helpful message like 'Something went wrong, but we've logged the issue...' This is a best practice for production-ready copilots.

4. Advanced Integration: Connecting to Your C# and Azure Services

While connectors are powerful, you'll often need to integrate with your own custom APIs and services. Given your background in C# and REST APIs, this is where you can build highly customized, powerful solutions.

A common and robust enterprise pattern is to use an Agent Flow to call a secure Azure Function. The Azure Function acts as a façade or intermediary that contains your custom business logic, connects to proprietary systems, or calls other services.

Integrating Azure AI Foundry with Microsoft Copilot Studio

This technical article by Holger Imbery, 'Integrating Azure AI Foundry with Microsoft Copilot Studio', details an enterprise-grade pattern for this exact scenario. While it focuses on AI Foundry, the architecture applies to calling any backend service via an Azure Function.

Please read 'Excursion 1: ... (the robust way)'. Focus on these key points: Target Architecture: Understand the flow: Copilot Studio -> Agent Flow (HTTP action) -> Azure Function. Example Code: Review the '.NET 8 Isolated Azure Function' C# code. This shows how to create an HTTP-triggered function that acts as a façade for a backend service. Security: Skim the sections 'Secure the Function Endpoint' and the 'Security & Operations Checklist'. This highlights professional best practices for securing your API using Function keys, Microsoft Entra ID, or API Management, which are critical for the PL-400 exam.

This pattern is extremely powerful. It allows you to:

  • Leverage your existing C# and .NET skills.
  • Implement complex business logic that is difficult or impossible in Power Automate alone.
  • Create a secure and governable layer between the Power Platform and your backend systems.
  • Connect to any system that can be accessed via a REST API.
Test your understanding!

You have a Copilot Studio agent that needs to retrieve a customer's order status from a legacy, on-premises SQL database that is not exposed to the internet. The company has an existing .NET API running in Azure that can securely connect to this database via a private network.

What would be the most appropriate and secure architecture to allow the copilot to get this data?

Show answer

The best approach would be to follow the advanced integration pattern we just discussed:

  1. Copilot Studio Topic: The copilot asks the user for their Order ID and saves it to a variable.
  2. Agent Flow: An Agent Flow is called from the topic. It receives the Order ID as an input parameter.
  3. HTTP Action: The Agent Flow uses the standard HTTP action to make a secure call to the existing .NET API endpoint in Azure, passing the Order ID in the request.
  4. .NET API (Azure Function or App Service): The API receives the request, connects to the on-premises SQL database (using its existing secure connection), retrieves the order status, and returns it in the HTTP response.
  5. Return to Copilot: The Agent Flow parses the JSON response from the API and passes the order status back to the Copilot Studio topic as an output variable. The copilot then displays the status to the user.

This architecture is secure, scalable, and leverages existing infrastructure and developer skills effectively.


Conclusion

In this lesson, you've connected the conversational front-end of Copilot Studio to the powerful action-oriented back-end of Power Automate. This is the key to building copilots that don't just talk, but do.

Key Takeaways:

  • Agent Flows are the bridge: They are the modern, licensed-inclusive way to perform backend actions from Copilot Studio.
  • Inputs and Outputs are the contract: All communication between a topic and a flow happens through a well-defined set of input and output parameters.
  • Your Flow skills are reusable: The process of building logic, using connectors, and working with data inside an Agent Flow is identical to your existing Power Automate experience.
  • Debug in the right place: When a flow called by a copilot fails, diagnose the issue by checking the flow's run history in the Power Automate maker portal.
  • Leverage Azure for advanced scenarios: For maximum power and flexibility, use Agent Flows to call your own custom APIs hosted in Azure, like Azure Functions written in C#.

What's Next?

We've now enabled our copilot to perform powerful actions, such as querying databases or creating records. But how do we ensure that only the right people can perform these actions? Our next lesson, Implement user authentication in a chatbot using Azure AD, will address this. We will learn how to make our copilot aware of who it's talking to, enabling it to perform actions securely in the context of the logged-in user.