Bendrinti naudojant


Return a list of results

It's common to ask an agent to look for data in an external system and return a list of results. To do that, an agent can call a Power Automate flow to:

  1. Authenticate and connect to an external solution.
  2. Run a query based on the user input.
  3. Format the results.
  4. Return the results to the agent.

This example uses the Dataverse connector in Power Automate to search for accounts. The connector returns a list of results that includes the account name, city, and account number to your agent.

Prerequisites

Set up a Dataverse Account table

The Account table is a standard table available by default in Power Platform environments. However, it doesn't come with account data. Before your agent can search for accounts, you must populate the Account table.

If you already have an Account table with data, skip this step and move on to Create a topic. However, remember to use search terms relevant to your data when you test your agent in later steps.

  1. Go to the Power Apps portal.

  2. In the navigation pane, select Tables.

  3. Select the Account table, and then on the table properties page, select Edit.

  4. Add the following rows to the table:

    Address 1: City Account Name Account Number
    Seattle Contoso Inc AC0125
    San Francisco Contoso Residences AC0255
    Olympia Contoso Meal Delivery AC0035

Create a topic

  1. In Copilot Studio, go to the Topics page for your agent.

  2. Create a topic called Account search.

  3. Add the following trigger phrases:

    • I'm looking for a customer
    • I'm looking for an account
    • search account
    • search customer
  4. Add a Message node and enter the message "Sounds like you're looking for an account. I can look that up for you."

  5. Add a Question node and enter the message "What's the name of the customer you're looking for?"

  6. For Identify, select Organization.

    User's entire response would also work. However, by selecting the Organization entity, you take advantage of the agent's language understanding capabilities to extract the organization name from the response.

  7. For Save user response as, rename the variable to "organization".

    Screenshot of the 'Account search' topic with a Message node and a Question node.

Create a flow

  1. Select the Add node icon below any node, and select Add an action.

  2. On the Basic actions tab, select New Power Automate flow.

  3. In Power Automate, select the name of the flow and replace it with Search account.

  4. Select the Run a flow from Copilot flow trigger and add a Text input parameter named Organization.

    Screenshot of the flow trigger with the 'Organization' text input.

  5. Select the Add icon below the Run a flow from Copilot flow trigger.

  6. In Add an action, search for "Microsoft Dataverse", and select the Search rows action.

    This action uses fuzzy matching to find relevant accounts in your Dataverse Account table.

  7. In the Search term box, enter a slash (/), select Insert dynamic content, and then select your Organization input parameter.

  8. For Advanced parameters, select Show all and set the following values:

    • Table filter Item: account
    • Sort by Item - 1: search.score desc
    • Sort by Item - 2: name asc

    Screenshot of the 'Search rows' action properties with advanced options.

Format results

The Search rows action returns the List of rows variable, which contains JSON data. Before you can use the data, you must analyze it with the Parse JSON action.

  1. Select the Add icon below the Search rows action.

  2. In Add an action, search for "Data Operation", and select the Parse JSON action.

  3. In the Content box, enter a slash (/), select Insert dynamic content, and then select List of rows.

  4. Copy the following JSON schema and paste it in the Schema box:

    {
        "type": "array",
        "items": {
            "type": "object",
            "properties": {
                "@@search.score": {
                    "type": "number"
                },
                "name": {
                    "type": "string"
                },
                "address1_city": {
                    "type": "string"
                },
                "accountnumber": {
                    "type": "string"
                }
            },
            "required": [
                "name"
            ]
        }
    }
    

    Screenshot of the JSON schema in the Parse JSON action properties.

  5. Select the Add icon below the Parse JSON action.

  6. In Add an action, search for "Variable", and select the Initialize variable action.

  7. In the Name box, enter "ListOfAccounts".

  8. For Type, select String.

    Screenshot of the 'Initialize variable' action properties.

  9. Select the Add icon below the Initialize variable action.

  10. In Add an action, search for "Control", and select the Apply to each action.

  11. In the Select an output from previous steps box, enter a slash (/), select Insert dynamic content, and then select the Body variable under Parse JSON.

  12. Select the Add icon inside the Apply to each action.

  13. In Add an action, search for "Variable", and select the Append to string variable action.

  14. For Name, select ListOfAccounts.

  15. Copy the following text and paste it in the Value box:

    - @{items('Apply_to_each')['accountnumber']}: @{items('Apply_to_each')['name']} - @{items('Apply_to_each')['address1_city']}
    
  16. Add a line break after the snippet to make each result appear on its own line.

    Screenshot of the 'Append to string variable' action properties.

  17. In the Respond to Copilot action, add a Text output.

  18. For Name, enter "FoundAccounts".

  19. For the value, enter a slash (/) in the box, select Insert dynamic content, and then select the ListOfAccounts variable.

    Screenshot of the 'Respond to Copilot' action properties.

  20. Save and publish your flow.

Call the flow from Copilot Studio

  1. In Copilot Studio, select the Add node icon under the Question node, select Add an action, and then select the flow you created earlier, Search account.

  2. Set the flow input parameter to the output variable from the Question node: Organization (String) gets its value from the organization variable.

  3. Add a Message node and enter the message "Okay, this is what I found."

  4. Add a second Message node. Select the Insert variable icon, and then select FoundAccounts.

    Screenshot of the conversation flow that responds with a list of found accounts.

  5. Select Save.

  6. Test your agent.

    Screenshot of an example conversation in the test panel.