Embedding a Fabric Data Agent in Your Own App
Service principal auth made Fabric Data Agents callable without a user sign-in. Here's the payoff: turning a published agent into a drop-in chat widget inside your own product, with conversation memory, the official REST API, and a secret that never leaks to the browser.
This post's backend calls the agent through the OpenAI Assistants-style endpoint (threads and runs), and OpenAI shut down the Assistants API on August 26, 2026. The architecture still holds: browser to your backend, backend to the agent, secret on the server. Only the call inside the proxy changes, to the agent's MCP endpoint, and the MCP endpoint keeps no thread, so your backend holds any conversation context itself. See Calling a Fabric Data Agent over MCP.
Once a Fabric Data Agent can authenticate on its own behalf, the interesting question stops being how do I call it and becomes where do I put it. The answer is: anywhere. A support portal, an internal ops dashboard, a customer-facing web app: a published Data Agent can become a natural-language chat surface sitting directly on top of your governed Fabric data.
This is the follow-on to service principal authentication. That feature removed the human from the loop; embedding is what you do with the headroom it created. Here is the full flow: the conversation lifecycle, how memory actually works, and the one architectural rule you cannot skip.
- 3 calls to first answer. Acquire a token, open a conversation, send a message. That is the entire critical path from published agent to rendered reply.
- 1 ID to remember. Conversation memory is not magic. It is one identifier you persist between turns. Hold onto it and the agent keeps context.
- 0 secrets in the browser. The client secret lives on your backend and never ships to the client. The browser talks to your proxy; your proxy talks to Fabric.
What "Embedding" Actually Means Here
A Fabric Data Agent exposes a conversational REST API. You send it natural-language questions; it plans across its attached data sources (lakehouses, warehouses, semantic models), runs the queries, and returns a grounded answer. Embedding means wrapping that API in a chat interface your users never leave your app to reach.
Three things have to be in place before any code runs:
- A published Data Agent: built in Fabric, with data sources attached and clear AI instructions. Publishing is what exposes the API endpoint.
- A service principal: an Entra ID app registration granted access to the agent's workspace, so your app authenticates without a user sign-in. This is the piece we covered in depth in the service principal authentication article.
- The Data Agent API URL: the published endpoint for your specific agent, copied from Fabric. Everything below hangs off this URL.
The Conversation Lifecycle
A chat is not a single request/response. Under the hood it is a small state machine: open a conversation, add a message, tell the agent to process it, wait for it to finish, then read what it said. The published API follows the same assistants-style pattern many teams already know, which makes it approachable.
1 · Authenticate
Use the OAuth 2.0 client-credentials flow to exchange your service principal credentials for a bearer token scoped to the Fabric API.
2 · Open a conversation
Create a conversation (thread) and keep the ID it returns. This ID is the memory. Every follow-up question posts against it.
3 · Send & process
Add the user's message to the conversation and kick off a run. The agent plans, queries the data sources, and composes an answer.
4 · Poll & read
Runs are asynchronous. Poll until the run reports complete, then read the newest assistant message and render it in your UI.
The Backend: Where the Secret Stays
The single non-negotiable rule of embedding: the client secret never reaches the browser. If it does, anyone who opens dev tools can query your entire data estate as your service principal. So the token exchange and the Fabric calls both happen server-side, behind a thin proxy your frontend talks to.
The DATA_AGENT_URL (the published endpoint you copied from Fabric) is what openConversation and askAgent call under the hood, always with that same bearer token. Because tokens are short-lived, acquire one per request (the Azure Identity SDK caches and refreshes for you) rather than holding a stale one.
Conversation Memory: One ID, Not a Database
The feature people expect from a chat widget ("it remembers what I just asked") is the cheapest part to build. The agent maintains conversation state server-side, keyed by the conversation ID. Your job is simply to hand that ID back on the next turn.
Start conversationId as null, let the backend mint one on the first message, and store whatever it returns. Want a fresh context, like a "new chat" button? Set it back to null. That is the entire memory model.
Production Checklist
Proxy every call
The browser only ever talks to your backend. No Fabric URL, no token, and no client secret should be observable in network traffic from the client.
Scope the service principal narrowly
The SPN can see whatever it is granted. Give it access to exactly the workspace and agent it needs. An embedded chat is a natural-language query surface over everything that identity can reach.
Add your own guardrails
Rate-limit the proxy, validate and cap message length, and log conversations. The agent grounds its answers in your data, but the endpoint in front of it is yours to protect.
Handle the async run honestly
Runs take a few seconds. Show a thinking state, set a sensible poll timeout, and surface a clear error if a run fails rather than leaving the UI hanging.
Try It: Generate Your Embed Code
You do not have to wire the whole flow up by hand to see it work. We built an open-source template that runs the complete service principal → conversation → answer loop in the browser and generates drop-in embed code from your own credentials. Enter your Tenant ID, Client ID, Client Secret, and Data Agent API URL, test the connection live, then copy the snippet straight into your app.
Testing only: this demo breaks the rule on purpose
Entering a client secret into a browser-hosted form is exactly what the "secrets never reach the browser" rule above forbids in production. Use a throwaway development service principal scoped to a non-production workspace, and rotate or delete the secret as soon as you finish testing. Never paste production credentials here.
Why This Is the Moment
For years, "let business users ask questions of the data in plain English" was a slide, not a shipped feature. The last mile was always a bespoke NL-to-SQL project that aged badly. A published Fabric Data Agent collapses that mile. The intelligence, the grounding, and the governance live in Fabric; embedding is a few dozen lines of glue.
Service principal auth made it headless. Conversation memory made it feel like a real assistant. The backend proxy made it safe to expose. Put those three together and a governed Fabric Data Agent becomes a first-class feature of your product, not a demo you show once, but a surface your users actually work in.
Further Reading
- Service Principal Authentication for Fabric Data Agents: the auth foundation this article builds on
- Fabric Data Agent concepts: Microsoft Learn documentation on building and publishing agents
- Data Agent REST API reference: the conversation and run endpoints behind the flow above