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
-
Open Microsoft Edge and go to
https://app.powerbi.com/. -
If prompted, sign in by using the following credentials:
Setting Value Username @lab.CloudPortalCredential(User1).UsernameTemporary Access Pass (TAP) token @lab.CloudPortalCredential(User1).AccessToken -
In the left pane, select Workspaces and then select ZavaSales@lab.LabInstance.Id.

-
On the command bar, select + New item.

-
In the New item pane, search for
Data agent. Then, in the list of search results, select Data agent (preview).
-
In the Create Data agent name field, enter
Zava-Assistant@lab.LabInstance.Idand then select Create.
-
In the Explorer pane, select + Add Data and then select Data source.

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

-
On the menu bar for the data agent, select Refresh and then expand dbo.
-
Select all tables:

-
Submit the following prompt:
What is the most sold product?
-
In the response, select the drop-down arrow to review the SQL query that was used to derive the response.

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.
-
In the Explorer pane, select the Setup tab.

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

-
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.
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.
-
In the Explorer pane, select the Setup tab.
-
In the Zavalakehouse section, select Example queries.

-
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;
-
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 DESCwhat 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
-
Select Close(X) (the X).

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

-
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:

-
Submit the following prompt:
Who are the top 5 customers by total sales amount?
-
On the command bar for the agent, select Publish.

-
In the Publish data agent dialog, select Publish.

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

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