Create agent flows

Scenario

In this lab, you will use the structured values collected in earlier labs (such as property type, property name, and visit date) to retrieve data from Dataverse and create a booking request in Dataverse.

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
  • Create an agent flow to create Dataverse data

Prerequisites

  • Must have completed Lab: Work with entities

Detailed steps

Exercise 1 - Create a tool to retrieve data property data from Dataverse

In this exercise, you will create an agent flow that retrieves a property based on user‑provided criteria.

Task 1.1 - Create the Get Property agent flow

  1. Navigate to the Microsoft Copilot Studio portal https://copilotstudio.microsoft.com and ensure you are in the appropriate environment.

  2. Select Agents from the left navigation pane.

  3. Open the Real Estate Booking Service agent.

  4. Select the Tools tab.

  5. Select + Add a tool.

  6. Under Create new, select Agent flow.

  7. Select the trigger step When an agent calls the flow and select + Add an input.

  8. Select Text.

  9. Enter Bedrooms for Input and Number of Bedrooms for Please enter your input.

    Screenshot of trigger properties of the flow.

  10. Select Save draft near the upper-right of the page.

Task 1.2 - Retrieve data from Dataverse

  1. Select the + icon between the two steps in the flow to add a new action.

  2. Enter Dataverse in the Search field and select See more for the Microsoft Dataverse connector.

    Screenshot of searching for connector in the flow.

  3. Select the List rows action.

  4. If prompted for authentication, enter Lab connection for Connection name, select OAuth for Authentication Type, and select Sign in, and use your tenant credentials and Allow access.

    Note: If you see a ‘Failed to create OAuth connection’ error, you may need to allow popups in your browser.

    Screenshot of OAuth error.

    Screenshot of allowing popups in Edge.

  5. Select Real Estate Properties for table name.

  6. Enter contoso_bedrooms eq (with a space after eq) in the Filter Rows field.

  7. With the Filter Rows field still selected, select the lightning icon to its right, then select the Bedrooms parameter.

    Screenshot of configuring list rows action.

  8. Select Save draft near the upper-right of the page.

Task 1.3 - Return results to agent

  1. Select the Respond to the agent node in the authoring canvas and select + Add an output.

  2. Select Text.

  3. Enter PropertyId for Enter a name

  4. Select the Enter a value to respond with field, and select fx (Insert Expression).

  5. Enter the following expression into the top field:

     first(outputs('List_rows')?['body/value'])['contoso_realestatepropertyid']
    
  6. Select Add.

  7. Select + Add an output.

  8. Select Text.

  9. Enter PropertyName for Enter a name.

  10. Select the Enter a value to respond with field, and select fx (Insert Expression).

  11. Enter the following expression:

     first(outputs('List_rows')?['body/value'])['contoso_propertyname']
    

    Screenshot of configuring response action.

  12. Select Add.

  13. Select the Settings tab in the Respond to the agent pane.

  14. Ensure that Asynchronous Response is set to Off.

    Screenshot of response action settings.

  15. Select Save draft near the upper-right of the page.

  16. Select Publish.

  17. In the Your agent flow published successfully! pop-up, select Go back to agent.

  18. Select the agent flow tool that you just created.

  19. In the Details section, update the Flow Name to Get Property

  20. Update the Description to Get properties with the right number of bedrooms.

  21. Select Save

  22. Select the Tools tab and see the Get Property flow you created.

  23. Select Publish.

Task 1.4 - Add the Get Property tool to the topic

  1. Select the Topics tab.

  2. Select the Book Showing topic.

  3. Select the the + icon below the How many bedrooms do you need? question node, select Add a tool, select the Tool tab, and then select the Get Property agent flow.

  4. In the Get Property action pane, select the variable list for Bedrooms (String) and choose the NumberofBedrooms variable.

  5. Select the ellipses (…) in the Which property do you want to see? question node and select Delete.

  6. Select the the + icon under the Tool node and select Send a message.

  7. In the Enter a message field, enter Property (with a space following it).

  8. In the same node, select the {X} (Insert variable) icon and select the propertyname variable.

    Screenshot of step 4 of add a flow action.

  9. Select Save.

Exercise 2 - Create a tool to create a booking request

Microsoft Copilot Studio can create data in Microsoft Dataverse using agent flows.

Task 2.1 - Create agent flow to make a booking

  1. Select the Tools tab in Real Estate Booking Service.

  2. Select + Add a tool.

  3. Under Create new, select Agent flow .

  4. Select Save draft and wait for the agent flow to save.

  5. Select the Overview tab

  6. Select Edit in the Details section.

  7. Rename the agent flow Create Booking Request

  8. Select Save.

  9. Select the Designer tab.

  10. Select the trigger step When an agent calls the flow and select + Add an input.

  11. Select Text.

  12. Enter PropertyId for Input and Property for Please enter your input.

  13. Select + Add an input.

  14. Select Text.

  15. Enter ViewerName for Input and Viewer Name for Please enter your input.

  16. Select + Add an input.

  17. Select Text.

  18. Enter ViewerEmail for Input and Viewer Email for Please enter your input.

    Screenshot of configuring flow parameters action.

  19. Select the + icon between the two steps in the flow to add a new action.

  20. Enter Dataverse in the Search field and select See more for the Microsoft Dataverse connector.

  21. Select the Add a new row action.

  22. Select Booking Requests for table name.

  23. Enter Agent booking in the Booking Name field.

  24. Select Show all under Advanced parameters.

  25. 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.

  26. Select the Viewer Email field, select the lightning icon, then select the ViewerEmail parameter.

  27. Select the Viewer Name field, select the lightning icon, then select the ViewerName parameter.

    Screenshot of configuring flow add row action.

  28. Select the Respond to the agent action and open the Respond to the agent pane.

  29. Select the Settings tab.

  30. Ensure that Asynchronous Response is set to Off.

  31. Select Save draft in the upper-right of the window.

  32. Wait for the save to complete, then select Publish.

Task 2.2 - Validate your tools

  1. Return to your Real Estate Booking Service agent.

  2. 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 and configure.

Task 2.3 - Add the Create Booking Request tool to the topic

  1. Select the Topics tab.

  2. Select the Book Showing topic.

  3. Select the the + icon above the End all topics node at the bottom, select Add a tool, then select the Create Booking Request agent flow.

  4. Select the PropertyId variable for the PropertyId input parameter.

  5. Select the Name variable for the ViewerName input parameter.

  6. Select the EmailAddress variable for the ViewerEmail input parameter.

  7. Select Save.

  8. Select the Action node you just created for the Create Booking Request tool.

  9. Select Copilot.

  10. In What do you want to do?, enter: After this action runs, send a message that the Real Estate Booking has been scheduled and thank the user.

  11. Select Update.

A Message node has been created. Revise the message as desired to let the user know that a booking has been scheduled.

Exercise 3 - Test your agent

Task 3.1 - Make a booking request

  1. Open the Test panel.

  2. If it’s not enabled, enable Track between topics.

  3. Select the Start new test session icon at the top of the testing panel.

  4. 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

  5. Enter a name and email address.

  6. After you supply the information, an Adaptive Card displays the information that you entered and asks if the details are correct. Select Yes.

  7. Select House for the type of property prompt.

  8. Enter 3 for the number of bedrooms prompts.

    Screenshot of the test pane with the information entered.

  9. Enter Tomorrow 2:00 PM to the What date and time do you want to see the property? prompt.

A Booking Request should be created based on the information you have given the agent.

Task 3.2 - Verify the booking request

  1. Navigate to https://make.powerapps.com in a new tab.

  2. Make sure you are in the appropriate environment.

  3. Select Apps in the left navigation.

  4. Select Play on the Real Estate Property Management model-driven app.

  5. In the left navigation, select Booking Requests. View the booking request your agent just created for you.

    Screenshot of Maker portal showing booking request data.