Create agent flows
Scenario
In this exercise, you will:
- Create an agent flow
This exercise will take approximately 30 minutes to complete.
What you will learn
- How to create a tool for running an agent flow in Copilot Studio
High-level lab steps
- Create an agent flow to retrieve Dataverse data with an agent action
- Create an agent flow to create Dataverse data with an agent action
Prerequisites
- Must have completed Lab: Work with entities
Detailed steps
Exercise 1 - Create agent action to retrieve data from Dataverse
Microsoft Copilot Studio can access data in Microsoft Dataverse using agent flows.
Task 1.1 - Create agent flow to retrieve a property
-
Navigate to the Microsoft Copilot Studio portal
https://copilotstudio.microsoft.com
and ensure you are in the appropriate environment. -
Select Agents from the left navigation pane.
-
Select the Real Estate Booking Service you created in the earlier lab.
-
Select the Tools tab.
-
Select + Add a tool.
-
Select + New tool.
-
Select Agent flow.
-
Select the trigger step When an agent calls the flow and select + Add an input.
-
Select Text.
-
Enter
Bedrooms
for Input andNumber of Bedrooms
for Please enter your input. -
Select the + icon between the two steps in the flow to add a new action.
-
Enter
Dataverse
in the Search field and select See more for the Microsoft Dataverse connector. -
Select the List rows action.
-
If prompted for authentication, enter
Lab connection
for Connection name, select OAuth for Authentication Type, and select **Sign in.Note: If you see a ‘Failed to create OAuth connection’ error, you may need to allow popups in your browser.
-
Select Real Estate Properties for table name.
-
Enter
contoso_bedrooms eq
(with a space after eq) in the Filter Rows field. -
With the Filter Rows field still selected, select the lightning icon to its right, then select the Bedrooms parameter.
Important: Ensure there is a space between eq and Bedrooms.
-
Select the Respond to Copilot action in the authoring canvas and select + Add an output.
-
Select Text.
-
Enter
PropertyId
for Enter a name -
Select the Enter a value to respond with field, and select fx (Insert Expression).
-
Enter the following expression into the top field:
first(outputs('List_rows')?['body/value'])['contoso_realestatepropertyid']
-
Select Add.
-
Select + Add an output.
-
Select Text.
-
Enter
PropertyName
for Enter a name. -
Select the Enter a value to respond with field, and select fx (Insert Expression).
-
Enter the following expression:
first(outputs('List_rows')?['body/value'])['contoso_propertyname']
-
Select Add.
-
Select the Settings tab in the Respond to Copilot pane.
-
Ensure that Asynchronous Response is set to Off.
-
Select Save draft near the upper-right of the page.
-
Wait for the save to complete, then select Publish. In the Your agent flow published successfully! pop-up, select Go back to agent.
-
Select the Overview tab.
-
Select Edit in the Details section.
-
Update the Flow name to
Get Property
-
Select Save
-
Select Agents and select your Real Estate Booking Service agent.
-
Select Tools and see the Get Property flow you created.
Task 1.2 - Add the Get Property agent action to the topic
-
Select the Topics tab.
-
Select the Book a Real Estate Showing topic.
-
Select the the + icon below the How many bedrooms do you need question? node, select Add a tool, then select the Get Property flow.
-
Select the NumberofBedrooms variable for the Bedrooms input parameter.
-
Select the three dots in the Which property do you want to see? question node and select Delete.
-
Select the the + icon under the Action node and select Send a message.
-
In the Enter a message field, enter
Property
(with a space following it). -
In the same node, select the {X} (Insert variable) icon and select the PropertyName variable.
-
Select Save.
Exercise 2 - Create agent action to create data in Dataverse
Microsoft Copilot Studio can ceate data in Microsoft Dataverse using agent flows.
Task 2.1 - Create agent flow to make a booking
-
Select the tools tab in Real Estate Booking Service.
-
Select + Add a tool.
-
SSelect + New tool and then Agent flow .
-
Select Save draft and wait for the agent flow to save.
-
Select the Overview tab
-
Select Edit in the Details section.
-
Rename the flow
Create Booking Request
-
Select Save.
-
Select te Designer tab.
-
Select the trigger step When an agent calls the flow and select + Add an input.
-
Select Text.
-
Enter
PropertyId
for Input andProperty
for Please enter your input. -
Select + Add an input.
-
Select Text.
-
Enter
ViewerName
for Input andViewer Name
for Please enter your input. -
Select + Add an input.
-
Select Text.
-
Enter
ViewerEmail
for Input andViewer Email
for Please enter your input. -
Select the + icon between the two steps in the flow to add a new action.
-
Enter
Dataverse
in the Search field and select See more for the Microsoft Dataverse connector. -
Select the Add a new row action.
-
Select Booking Requests for table name.
-
Enter
Agent booking
in the Booking Name field. -
Select Show all under Advanced parameters.
-
Enter
contoso_bookingrequests()
in the Property (Real Estate Properties) field, move the cursor within the parentheses, select the lightning icon, then select the PropertyId parameter. -
Select the Viewer Email field, select the lightning icon, then select the ViewerEmail parameter.
-
Select the Viewer Name field, select the lightning icon, then select the ViewerName parameter.
-
Select the Respond to Copilot action.
-
Select the Settings tab.
-
Ensure that Asynchronous Response is set to Off.
-
Select Save draft in the upper-right of the window.
-
Wait for the save to complete, then select Publish.
-
Select Overview tab.
-
Select Edit in the Details section.
-
Rename the agent flow
Create Booking Request
-
Select Save.
Task 2.2 - Validate your tools
-
Select Agents and open your Real Estate Booking Service agent.
-
Select the Tools tab and validate that both of your agent flows are in the list. If not, select +Add a tool > Flow > and select the missing agent flow. Select Add to agent.
Task 2.3 - Add the Create Booking Request agent action to the topic
-
Select the Topics tab.
-
Select the Book a Real Estate Showing topic.
-
Select the the + icon below the What date and time do you want to see the property? node, select Add a tool, then select the Create Booking Request flow.
-
Select the PropertyId variable for the PropertyId input parameter.
-
Select the Name variable for the ViewerName input parameter.
-
Select the EmailAddress variable for the ViewerEmail input parameter.
-
Select the the + icon below the new Action node, select Topic management, select Go to another topic and select End of Conversation.
-
Select Save.
-
Select Publish and select Publish again.
Exercise 3 - Test the agent actions
Task 3.1 - Make a booking request
-
If closed, select the Test button in the upper-right of the screen to open the testing panel.
-
Select the three dots at the top of the testing panel in the upper-right of the screen.
-
If it’s not enabled, enable Track between topics.
-
Select the Start a new conversation (refresh) icon at the top of the testing panel.
-
When the Conversation Start message appears, your agent will start a conversation. In response, enter a trigger phrase for the topic that you’ve created:
I want to book a real estate showing
-
Enter the following information:
Name: <Your name>
Email address: <Your email address>
-
After you supply the information, an Adaptive Card displays the information that you entered and asks if the details are correct. Select Yes.
-
Select House for the type of property prompt.
-
Enter
3
for the number of bedrooms prompts. -
Enter
Tomorrow 2:00 PM
to the What date and time do you want to see the property? prompt. -
Select Yes to the Did that answer your question? prompt.
-
Select any rating.
-
Enter No to the Can I help with anything else? prompt.
Task 3.2 - Verify the booking request
-
If it’s not still open, navigate to
https://make.powerapps.com
in a new tab. -
Make sure you are in the appropriate environment.
-
Select Apps in the left navigation.
-
Select Play on the Real Estate Property Management model-driven app.
-
In the left navigation, select Booking Requests. View the booking request your agent just created for you.