Edit

Consume a Fabric data agent with the Python client SDK (preview)

This article shows how to use the Python client SDK to add a Fabric data agent to web apps and other clients by using interactive browser authentication. You sign in through a browser with your Microsoft Entra ID credentials, and the data agent runs with your permissions. By adding the data agent to external apps, you can build custom interfaces, embed insights in existing workflows, automate reports, and let users run natural language data queries. This approach gives you data agent capabilities while you keep full control of the user experience and app architecture.

Important

The code in this document and the Fabric Data Agent External Client repository use the OpenAI Assistants API (beta.assistants, beta.threads, beta.threads.runs), which OpenAI sunset on August 26, 2026. Because the Assistants API is no longer available, migrate to the MCP endpoint to keep your integration working.

Important

When you use Python client SDK to add a Fabric data agent to web apps or other clients, responses returned by Fabric data agents might be sent outside of Fabric's compliance boundary or geographic region. The applicable web app or client's terms and data handling policies govern how these responses are processed and stored.

Prerequisites

Set up your environment in VS Code

  1. Clone or download the Fabric Data Agent External Client repository. Then open it in VS Code and run the sample client.

  2. Create and activate a Python virtual environment (recommended), and install the required dependencies.

    python -m venv .venv
    
  3. Activate the virtual environment.

    .venv\Scripts\activate
    

Install dependencies

Run the following command to install dependencies:

pip install -r requirements.txt

Note

  • The azure-identity package included in requirements.txt lets you authenticate with Microsoft Entra ID.
  • InteractiveBrowserCredential from the azure-identity package opens a browser so you can sign in with a Microsoft Entra ID account. Use it for local development or apps that allow interactive sign-in.

Configure the client

Choose one of these methods to set the required values (TENANT_ID and DATA_AGENT_URL):

Set the values in your shell. Replace the placeholder text in angle brackets with your own values.

export TENANT_ID=<your-azure-tenant-id>
export DATA_AGENT_URL=<your-fabric-data-agent-url>

To find the published data agent URL, see Use the Fabric data agent programmatically. To locate your tenant ID, see Find your Microsoft Entra tenant ID.

Create the data agent client

Create a FabricDataAgentClient with your tenant ID and data agent URL. When the client initializes, it uses InteractiveBrowserCredential from the azure-identity package to authenticate with Microsoft Entra ID: your default browser opens so you sign in to the tenant that hosts the Fabric data agent.

from fabric_data_agent_client import FabricDataAgentClient

client = FabricDataAgentClient(tenant_id=TENANT_ID, data_agent_url=DATA_AGENT_URL)

Note

  • FabricDataAgentClient comes from the fabric_data_agent_client.py script in the cloned repository, not from a separately installed package.
  • The client uses interactive browser authentication: when you run the script, your default browser opens so you sign in to the tenant that hosts the Fabric data agent.

Ask the data agent a question

After you authenticate, interact with the data agent by using the Python client.

response = client.ask("What were the total sales last quarter?")
print(f"Response: {response}")

The client.ask method sends your question to the data agent and returns an object with the answer. You can view the steps the data agent performed and the corresponding queries it generated to get the answer.

run_details = client.get_run_details("What were the total sales last quarter?")
messages = run_details.get('messages', {}).get('data', [])
assistant_messages = [msg for msg in messages if msg.get('role') == 'assistant']

print("Answer:", assistant_messages[-1])

Optional: Inspect the steps and corresponding query

Inspect the steps the data agent took to arrive at the answer, including any errors during execution.

for step in run_details['run_steps']['data']:
        tool_name = "N/A"
        if 'step_details' in step and step['step_details'] and 'tool_calls' in step['step_details']:
            tool_calls = step['step_details']['tool_calls']
            if tool_calls and len(tool_calls) > 0 and 'function' in tool_calls[0]:
                tool_name = tool_calls[0]['function'].get('name', 'N/A')
        print(f"Step ID: {step.get('id')}, Type: {step.get('type')}, Status: {step.get('status')}, Tool Name: {tool_name}")
        if 'error' in step:
            print(f"  Error: {step['error']}")

This output helps you understand how the agent produced its response and gives transparency when you work with your data in the Python client.