Create a flow
Learn how to use a cloud flow in Copilot Studio by giving an agent the ability to produce a weather forecast on request. In this first example, you'll create a flow that fetches a weather forecast. In the next example, you'll call the flow as an action from a topic so the agent can respond with the forecast when a customer asks about the weather.
To work with agents, a Power Automate flow requires specific flow trigger and response action.
Flow trigger: Run a flow from Copilot
Response action: Respond to Copilot
When you create a flow from Copilot Studio, the trigger and the action are added for you. You can modify an existing flow for use with agents by changing it to use these actions.
Important
To use cloud flows in custom agents in Copilot Studio, the flows must:
- Have the Run a flow from Copilot trigger.
- Be located in a solution within the same environment as the agent. Existing flows can be added to a solution to be available when adding actions to your agent.
- Return a response synchronously with the Respond to Copilot action, within the 100-second action limit. To avoid timeouts, optimize the flow logic, queries, and the amount of data returned so that a typical run is below this limit. Actions that need to run longer can be placed after the Respond to Copilot action to continue executing for up to the flow run duration limit, which is typically 30 days.
Prerequisites
- Access to Copilot Studio with a license that includes the use of flows within the context of Copilot Studio creations.
Create a flow to use with an agent
Go to the Topics page for your agent.
Open the topic from which you want to call a flow.
Select Add node (+) below an existing node to add a new node.
In the node selection window, select Call an action, Basic Action and then select Create a flow.
The Power Automate portal opens in a new tab, with a starter flow template open for editing. The portal opens in the same environment as the agent and uses the same user credentials.
Tip
Rename nodes to make them easier to identify. Select the node's name field to update the name directly, or select the More icon (…) of the node and select Rename from the menu. You can also rename nodes in the code editor.
It's not possible to rename Trigger nodes and Go to step nodes.
Node names can be up to 500 characters in length.
Now add actions to your flow. In this example, you add an action that fetches the current forecast from MSN Weather.
Select the name of the flow and rename it Get weather forecast.
Add the following input parameters to the Run a flow from Copilot trigger:
- City (Text)
- Zipcode (Number)
Select Add an action to create a new action below the Run a flow from Copilot flow trigger.
Search for MSN weather, and then select the Get forecast for today action.
In the Get forecast for today action, in the Location box, select Add dynamic content, and then select City and Zipcode.
In the Respond to Copilot action, add the following output parameters and variables:
Output parameter Type Variable day_summary
String Day Summary location
String Location chance_of_rain
Number Day Rain Chance Select Save.
Manage which connections are used by the flow
In a supported authenticated agent, cloud flows can be configured to use user credentials when they're run as part of a generative orchestration plan or called from a topic. If you are using the flow in a supported channel, this requires no special configuration in your agent dialog, and users will be able to manage their connections while using the agent.
Cloud flows in environments using customer-managed keys (CMK) cannot yet be run with end user credentials as part of generative orchestration plans or from topics. Ensure the run-only settings for cloud flows in CMK environments are set to specific connections instead of Provided by run-only user.
Modify an existing flow to use with an agent
If you have a flow with a different trigger that you wish to use with your agent, you can change the flow to use the Run a flow from Copilot trigger and Respond to Copilot response action, and make sure it's in a solution in the same environment as the custom agent.
Go to the Power Automate portal and use the Environment selector at the top right to choose the environment where your flow is stored.
Navigate to My flows in the left side and search for the flow.
Select the flow.
Add the Copilot trigger and response action
If your flow doesn't already include the Copilot trigger and response action, you must add them before you can use the flow with your agent.
Select New step.
Search for Copilot and select Run a flow from Copilot.
Select New step.
Search for the Copilot connector and select Respond to Copilot. The response action can be used at multiple branches in the flow, but must have the same outputs at each usage.
Save and publish the flow.
Ensure response action is set to return in real time
Flows that you want to use in an agent must return values in real time, or synchronously. Flows that run in the background, or asynchronously, may cause an error when your agent tries to run them. Instead of running the flow, the agent will say, "Something unexpected happened. We're looking into it. Error code: 3000."
When you create a flow from Copilot Studio, asynchronous responses are turned off by default. If you modified an existing flow that has asynchronous responses turned on, follow these steps to check the setting and ensure it is turned off:
Open your flow and find the Respond to Copilot action(s).
Select the Settings tab.
Set Asynchronous Response to Off, and then select Done.
Add the flow to a solution
To be available to agents, flows must be stored in a solution in the same Power Platform environment. If a flow is in a solution, a Solutions tile will be visible on the flow's detail page that lists which solutions the flow is in. Flows can be added to the Default Solution for use with agents, or moved into a different solution using the below steps:
Go to the Power Automate portal.
Go to Solutions and either select an existing solution or create a solution for your flows.
To create a solution, select New solution.
Give your new solution a name, select CDS Default Publisher in the Publisher field, enter a Version number, and then select Create.
On the Solutions tab, go to the solution you want to use. Select Add existing to add a flow to it.
On the Add existing flow page, select the From solutions tab, select your flow, and then select Add.
To move a flow from the My flows tab to a solution, select Outside solutions, and then select Add to add your flow to the solution.