Query AI Foundry Data Agent from Python and receive a response
12:42 08 Sep 2025

I recently set up a Microsoft Fabric Data Agent and connected it to AI Foundry. I now have my data agent on AI Foundry, with its source being the Fabric Data Agent. My goal is to ask questions to this agent from Python and retrieve responses via the SDK.

To start, I just wanted to verify that my connection works correctly. My App Registration setup works:

from azure.identity import ClientSecretCredential
from azure.ai.projects import AIProjectClient

# Configuration

TENANT_ID = "tenant_id"
CLIENT_ID = "client_id"
CLIENT_SECRET = "client_secret"
PROJECT_ENDPOINT = "???"

# Create credential

credential = ClientSecretCredential(
tenant_id=TENANT_ID,
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET
)

# Initialize AI Foundry client

client = AIProjectClient(credential=credential, endpoint=PROJECT_ENDPOINT)
print("Foundry client created!")

Then, to verify the connection, I try to list the agents:

agents = list(client.agents.list_agents())
print("Number of agents found:", len(agents))
for a in agents:
print(a.id, "|", a.name)

The problem is that I always get 0 agents. I suspect this comes from the endpoint I am using, because I cannot find the correct one in AI Foundry.

I am therefore looking for a simple method to query the AI Foundry Data Agent from Python and receive a response directly.

Thank you in advance for your help!

python azure-sdk azure-ai-foundry