Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Task 01: Create and enhance a data agent

Introduction

Serena believes that generative AI offers a transformative way to interact with data, significantly boosting data-driven decision-making in organizations worldwide. Fabric Data Agents, a new capability in Fabric, allows data analysts like Serena to create their own generative AI experiences.

In this exercise, create a conversational data agent.

Key steps

01: Create the agent

  1. Open Microsoft Edge and go to https://app.powerbi.com/.

  2. If prompted, sign in by using the following credentials:

    Setting Value
    Username @lab.CloudPortalCredential(User1).Username
    Temporary Access Pass (TAP) token @lab.CloudPortalCredential(User1).AccessToken
  3. In the left pane, select Workspaces and then select ZavaSales@lab.LabInstance.Id.

    u49ip7wn.jpg

  4. On the command bar, select + New item.

    u8m5bkzc.jpg

  5. In the New item pane, search for Data agent. Then, in the list of search results, select Data agent (preview).

    uh5w7atc.jpg

  6. In the Create Data agent name field, enter Zava-Assistant@lab.LabInstance.Id and then select Create.

    xatr9m26.jpg

  7. In the Explorer pane, select + Add Data and then select Data source.

    5eox0cyt.jpg

  8. In the list of data sources, select Zavalakehouse@lab.LabInstance.Id and then select Add. Wait while Fabric establishes a connection with the lakehouse.

    4bnggcpj.jpg

  9. On the menu bar for the data agent, select Refresh and then expand dbo.

  10. Select all tables:

    x4dfo458.jpg

  11. Submit the following prompt:

     What is the most sold product?
    

    eqbv5pzw.jpg

  12. In the response, select the drop-down arrow to review the SQL query that was used to derive the response.

    cjqznu9j.jpg

    It may take a minute or two before you see a response. Refresh the browser page if the data agent does not respond as expected.


02: Add instructions for the agent

The agent answered the question fairly well based on the selected tables. However, the SQL query needs some improvement.

Results may be sorted by order quantity even though total sales revenue associated with the product is the most important consideration.

To improve the query generation, you’ll provide some instructions to the agent.

  1. In the Explorer pane, select the Setup tab.

    q051e0wd.jpg

  2. In the Zavalakehouse@lab.LabInstance.Id section, select Data source instructions.

    m1dbvyfs.jpg

  3. In the Data source instructions field, enter the following instructions:

     Whenever I ask about "the most sold" products or items, the metric of interest is total sales revenue and not order quantity.
    
     The primary table to use is FactInternetSales. Only use FactResellerSales if explicitly asked about resales or when asked about total sales.
    

    hcabyaug.jpg


03: Add example queries

In addition to instructions, examples serve as another effective way to guide the AI. You can add examples that represent questions that the data agent often receives, or questions that require complex joins.

  1. In the Explorer pane, select the Setup tab.

  2. In the Zavalakehouse section, select Example queries.

    ta5kk0o9.jpg

  3. Select + Add example and enter the following question and SQL query.

    Fabric validates each of the queries after you paste the query into the field. The process for validating the three queries may take a couple of minutes.

    Fabric will alert you if a query has errors. You must fix (or delete) any queries that cause errors.

    Question SQL query
    What is the most sold product? SELECT TOP 1 dp.EnglishProductName AS MostSoldProduct FROM dbo.dimproduct dp JOIN dbo.factinternetsales fis ON dp.ProductKey = fis.ProductKey JOIN dbo.factresellersales frs ON dp.ProductKey = frs.ProductKey GROUP BY dp.EnglishProductName ORDER BY SUM(fis.SalesAmount) DESC;

    39ym35qw.jpg

  4. Repeat the process to add the following questions and queries.

    On the command bar, use + Add to add the additional questions and queries.

    Question SQL query
    who are the top 5 customers by total sales amount? SELECT TOP 5 CONCAT(dc.FirstName, ' ', dc.LastName) AS CustomerName, SUM(fis.SalesAmount) AS TotalSpent FROM factinternetsales fis JOIN dimcustomer dc ON fis.CustomerKey = dc.CustomerKey GROUP BY CONCAT(dc.FirstName, ' ', dc.LastName) ORDER BY TotalSpent DESC
    what is the total sales amount by year? SELECT dd.CalendarYear, SUM(fis.SalesAmount) AS TotalSales FROM factinternetsales fis JOIN dimdate dd ON fis.OrderDateKey = dd.DateKey GROUP BY dd.CalendarYear ORDER BY dd.CalendarYear

    x9p15zl8.jpg

  5. Select Close(X) (the X).

    xa90dqh9.jpg

  6. Return to the agent Test the agent’s responses tab and select Clear chat.

    zqie1gka.jpg

  7. Submit the following prompt:

     What is the most sold product?
    

    Asking the question now returns a different answer, Mountain-200 Black, 38, as shown in the below screenshot:

    70422zds.jpg

  8. Submit the following prompt:

     Who are the top 5 customers by total sales amount?
    

    wuxu51bw.jpg

  9. On the command bar for the agent, select Publish.

    fm5l4927.jpg

  10. In the Publish data agent dialog, select Publish.

    jaxhloe8.jpg

  11. After the Successfully published data agent message displays, select View publishing details.

    44z8ezjq.jpg

    If the dialog confirming that publication is complete is no longer visible, on the command bar for the agent, select Settings (the gear icon) to view the same information.

  12. Review the value in the Published URL field. The URL contains some important information that you need to copy.

    • workspaces: This is the unique workspace ID. Copy the unique identifier to the following text field: @lab.TextBox(FabricDataAgentWorkspaceID)
    • dataagents: This is the unique artifact ID. Copy the unique identifier to the following text field: @lab.TextBox(FabricDataAgentArtifactID)

    In the following example URL, 43604616-db0c-4e91-91f7-81a78f6c1f96 is the workspace ID and de592c0f-a3f3-4618-af9c-bcd04bc4140a is the artifact ID.

    https://api.fabric.microsoft.com/v1/workspaces/43604616-db0c-4e91-91f7-81a78f6c1f96/dataagents/de592c0f-a3f3-4618-af9c-bcd04bc4140a/aiassistant/openai