Edit

Consume Fabric data agent from Microsoft Foundry Services (preview)

Data agent in Microsoft Fabric transforms enterprise data into conversational Q&A systems. It enables users to interact with their data through chat, to uncover actionable insights. One way to consume Fabric data agent is through Foundry Agent Service, a core component of Microsoft Foundry. Through integration of Fabric data agents with Foundry, your Azure AI agents can directly tap into the rich, structured, and semantic data available in Microsoft Fabric OneLake. This integration provides immediate access to high-quality enterprise data, and it empowers your Azure AI agents to generate actionable insights and streamline analytical workflows. Organizations can then enhance data-driven decision-making with Fabric data agent as a powerful knowledge source within their Azure AI environments.

Important

This feature is in preview. Use the latest preview release of the azure-ai-projects Python SDK.

Prerequisites

  • Developers and end users in Foundry must at least have the AI Developer Role-Based Access Control (RBAC) role.

How it works

Agent Setup: In Agent Service, create a new agent and add Fabric data agent as one of its knowledge sources. To establish this connection, you need the workspace ID and artifact ID for the Fabric data agent. The setup enables your Azure AI agent to evaluate available sources when it receives a query, to ensure that it invokes the correct tool to process the request. Currently, you can only add one Fabric data agent as a knowledge source to your Azure AI agent.

Note

The model you select in Azure AI Agent setup is only used for Azure AI agent orchestration and response generation. It doesn't affect the model that Fabric data agent uses.

Query Processing: When a user sends a query from the Foundry playground, the Agent Service determines whether or not Fabric data agent is the best tool for the task. If it is, the Azure AI agent:

  • Uses the identity of the end user to generate secure queries over the data sources the user has permission to access from within the Fabric data agent.
  • Invokes Fabric to fetch and process the data, to ensure a smooth, automated experience.
  • Combines the results from Fabric data agent with its own logic to generate comprehensive responses. Identity Passthrough (On-Behalf-Of) authorization secures this flow, to ensure robust security and proper access control across enterprise data.

Note

The Fabric data agent and the Foundry resources should be on the same tenant, and both Microsoft Fabric and Foundry should be signed in with the same account.

Add Fabric data agent to your Azure AI Agent

You can add a Fabric data agent to your Azure AI agent either programmatically or with the user interface (UI). For detailed code examples and further instructions, see the Azure AI Agent integration documentation.

Add Fabric data agent through UI:

  • Navigate to the left pane. Under Build and Customize, select Agents, as shown in the following screenshot:

Screenshot showing the main Azure Foundry page.

This step displays the list of your existing Azure AI agents. You can add Fabric to one of these agents, or you can select New Agent to create a new agent. New agent creation generates a unique agent ID and a default name. You can change that name at any time. For more information, see What is Azure OpenAI in Foundry portal.

  • Initiate Adding a Knowledge Source: Select the Add button, as shown in the following screenshot:

Screenshot showing addition of Fabric data agent as knowledge.

This step opens a menu of supported knowledge source types.

  • Select Microsoft Fabric as the Source: From the list, choose Microsoft Fabric, as shown in the following screenshot:

Screenshot showing selecting Fabric as knowledge source.

With this option, your agent can access the Fabric data agent.

  • Create a connection: If you previously established a connection to a Fabric data agent, you can reuse that connection for your new Azure AI Agent. Otherwise, select New Connection to create a connection, as shown in the following screenshot:

Screenshot showing how to create a new Fabric connection.

The Create a new Microsoft Fabric connection window opens, as shown in the following screenshot:

Screenshot showing creating a connection.

When you set up the connection, provide the Fabric data agent workspace-id and artifact-id values as custom keys. You can find the workspace-id and artifact-id values in the published Fabric data agent endpoint. Your Fabric data agent endpoint has this format: https://fabric.microsoft.com/groups/<workspace_id>/aiskills/<artifact-id>. Select the Is Secret checkbox.

Finally, assign a name to your connection, and choose whether to make it available to all projects in Foundry or to restrict it to the current project.

After you select Connect, the Microsoft Fabric data agent is added as a Knowledge resource, as shown in the following screenshot:

Screenshot that shows how to add instructions.

You must also provide instructions to your Azure AI agent about when, how, and under what conditions to use the Fabric data agent. From the perspective of the Azure AI agent, the Fabric data agent is treated as a Fabric tool, so you can refer to it as such in your instructions.

You can also adjust the deployment model, add Actions, or change Model settings based on your use case requirements. Once your Azure AI agent is fully configured, select Try in playground to test its performance.

Add Fabric data agent programmatically: The following steps describe how to add a Fabric data agent programmatically to your Azure AI agent in Python. For other languages (C#, JavaScript), see this resource.

Step 1: Set up environment variables and import the SDK

Set the following environment variables before you run the code:

  • PROJECT_ENDPOINT: The Foundry project endpoint, found on the Overview page of your Foundry project.
  • MODEL_DEPLOYMENT_NAME: The model deployment name, as listed under Models + endpoints in your Foundry project.
  • FABRIC_CONNECTION_NAME: The name of the Microsoft Fabric connection, as it appears in your Foundry Connected resources.

Install the preview SDKs and import the modules:

pip install azure-identity
pip install --pre azure-ai-projects
import os
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
from azure.ai.agents.models import FabricTool, ListSortOrder

Step 2: Create an agent with the Microsoft Fabric tool enabled

To make the Fabric data agent tool available to your Azure AI agent, retrieve the connection ID from the named connection in your Foundry project, then pass it to FabricTool:

project_client = AIProjectClient(
    endpoint=os.environ["PROJECT_ENDPOINT"],
    credential=DefaultAzureCredential(),
)

# Look up the Fabric connection by name
conn_id = project_client.connections.get(os.environ["FABRIC_CONNECTION_NAME"]).id

# Initialize the Fabric tool with the connection ID
fabric = FabricTool(connection_id=conn_id)

with project_client:
    agents_client = project_client.agents

    agent = agents_client.create_agent(
        model=os.environ["MODEL_DEPLOYMENT_NAME"],
        name="my-agent",
        instructions="You are a helpful agent",
        tools=fabric.definitions,
    )
    print(f"Created agent, ID: {agent.id}")

Step 3: Create a thread and send a message

    # Create a thread for communication
    thread = agents_client.threads.create()
    print(f"Created thread, ID: {thread.id}")

    # Add a message to the thread
    message = agents_client.messages.create(
        thread_id=thread.id,
        role="user",
        content="What is the top sold product in Contoso last month?",
    )
    print(f"Created message, ID: {message.id}")

Step 4: Run the agent and read the output

Process the run, then iterate the messages to read the agent's response:

    # Create and process the run with the Fabric tool
    run = agents_client.runs.create_and_process(thread_id=thread.id, agent_id=agent.id)
    print(f"Run finished with status: {run.status}")

    if run.status == "failed":
        print(f"Run failed: {run.last_error}")

    # Delete the agent when finished
    agents_client.delete_agent(agent.id)
    print("Deleted agent")

    # Fetch and print all messages in the thread
    messages = agents_client.messages.list(thread_id=thread.id, order=ListSortOrder.ASCENDING)
    for msg in messages:
        if msg.text_messages:
            last_text = msg.text_messages[-1]
            print(f"{msg.role}: {last_text.text.value}")