@@ -6,7 +6,7 @@ services: cognitive-services
6
6
manager : nitinme
7
7
ms.service : azure-ai-agent-service
8
8
ms.topic : how-to
9
- ms.date : 02/25 /2025
9
+ ms.date : 04/07 /2025
10
10
author : aahill
11
11
ms.author : aahi
12
12
zone_pivot_groups : selection-fabric-data-agent
@@ -25,7 +25,7 @@ You need to first build and publish a Fabric data agent and then connect your Fa
25
25
26
26
| Azure AI foundry support | Python SDK | C# SDK | JavaScript SDK | REST API | Basic agent setup | Standard agent setup |
27
27
| ---------| ---------| ---------| ---------| ---------| ---------| ---------|
28
- | ✔️ | ✔️ | - | ✔️ | ✔️ | ✔️ | ✔️ |
28
+ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
29
29
30
30
## Prerequisites
31
31
* You have created and published a Fabric data agent endpoint
@@ -60,14 +60,36 @@ You need to first build and publish a Fabric data agent and then connect your Fa
60
60
61
61
Create a client object, which will contain the connection string for connecting to your AI project and other resources.
62
62
63
+ # [ C#] ( #tab/csharp )
64
+
65
+ ``` java
66
+ var connectionString = System . Environment . GetEnvironmentVariable(" PROJECT_CONNECTION_STRING" );
67
+ var modelDeploymentName = System . Environment . GetEnvironmentVariable(" MODEL_DEPLOYMENT_NAME" );
68
+ var fabricConnectionName = System . Environment . GetEnvironmentVariable(" FABRIC_CONNECTION_NAME" );
69
+
70
+ var projectClient = new AIProjectClient (connectionString, new DefaultAzureCredential ());
71
+
72
+ AgentsClient agentClient = projectClient. GetAgentsClient ();
73
+ ```
74
+
63
75
# [ Python] ( #tab/python )
64
76
65
77
``` python
66
78
import os
67
79
from azure.ai.projects import AIProjectClient
68
80
from azure.identity import DefaultAzureCredential
69
81
from azure.ai.projects.models import FabricTool
82
+
83
+ # Create an Azure AI Client from a connection string, copied from your Azure AI Foundry project.
84
+ # At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>"
85
+ # Customer needs to login to Azure subscription via Azure CLI and set the environment variables
86
+
87
+ credential = DefaultAzureCredential()
88
+ project_client = AIProjectClient.from_connection_string(
89
+ credential = credential, conn_str = os.environ[" PROJECT_CONNECTION_STRING" ]
90
+ )
70
91
```
92
+
71
93
# [ JavaScript] ( #tab/javascript )
72
94
73
95
``` javascript
@@ -96,6 +118,25 @@ Follow the [REST API Quickstart](../../quickstart.md?pivots=rest-api) to set the
96
118
97
119
To make the Microsoft Fabric tool available to your agent, use a connection to initialize the tool and attach it to the agent. You can find your connection in the ** connected resources** section of your project in the Azure AI Foundry portal.
98
120
121
+ # [ C#] ( #tab/csharp )
122
+
123
+ ``` csharp
124
+ ConnectionResponse fabricConnection = projectClient .GetConnectionsClient ().GetConnection (fabricConnectionName );
125
+ var connectionId = fabricConnection .Id ;
126
+
127
+ ToolConnectionList connectionList = new ()
128
+ {
129
+ ConnectionList = { new ToolConnection (connectionId ) }
130
+ };
131
+ MicrosoftFabricToolDefinition fabricTool = new (connectionList );
132
+
133
+ Agent agent = agentClient .CreateAgent (
134
+ model : modelDeploymentName ,
135
+ name : " my-assistant" ,
136
+ instructions : " You are a helpful assistant." ,
137
+ tools : [fabricTool ]);
138
+
139
+ ```
99
140
# [ Python] ( #tab/python )
100
141
101
142
``` python
@@ -166,6 +207,18 @@ curl $AZURE_AI_AGENTS_ENDPOINT/assistants?api-version=2024-12-01-preview \
166
207
167
208
## Step 3: Create a thread
168
209
210
+ # [ C#] ( #tab/csharp )
211
+
212
+ ``` csharp
213
+ AgentThread thread = agentClient .CreateThread ();
214
+
215
+ // Create message to thread
216
+ ThreadMessage message = agentClient .CreateMessage (
217
+ thread .Id ,
218
+ MessageRole .User ,
219
+ " What are the top 3 weather events with highest property damage?" );
220
+ ```
221
+
169
222
# [ Python] ( #tab/python )
170
223
171
224
``` python
@@ -224,6 +277,58 @@ curl $AZURE_AI_AGENTS_ENDPOINT/threads/thread_abc123/messages?api-version=2024-1
224
277
225
278
Create a run and observe that the model uses the Fabric data agent tool to provide a response to the user's question.
226
279
280
+ # [ C#] ( #tab/csharp )
281
+
282
+ ``` csharp
283
+ // Run the agent
284
+ ThreadRun run = agentClient .CreateRun (thread , agent );
285
+ do
286
+ {
287
+ Thread .Sleep (TimeSpan .FromMilliseconds (500 ));
288
+ run = agentClient .GetRun (thread .Id , run .Id );
289
+ }
290
+ while (run .Status == RunStatus .Queued
291
+ || run .Status == RunStatus .InProgress );
292
+
293
+ Assert .AreEqual (
294
+ RunStatus .Completed ,
295
+ run .Status ,
296
+ run .LastError ? .Message );
297
+
298
+ PageableList < ThreadMessage > messages = agentClient .GetMessages (
299
+ threadId : thread .Id ,
300
+ order : ListSortOrder .Ascending
301
+ );
302
+
303
+ foreach (ThreadMessage threadMessage in messages )
304
+ {
305
+ Console .Write ($" {threadMessage .CreatedAt : yyyy - MM - dd HH : mm : ss } - {threadMessage .Role ,10 }: " );
306
+ foreach (MessageContent contentItem in threadMessage .ContentItems )
307
+ {
308
+ if (contentItem is MessageTextContent textItem )
309
+ {
310
+ string response = textItem .Text ;
311
+ if (textItem .Annotations != null )
312
+ {
313
+ foreach (MessageTextAnnotation annotation in textItem .Annotations )
314
+ {
315
+ if (annotation is MessageTextUrlCitationAnnotation urlAnnotation )
316
+ {
317
+ response = response .Replace (urlAnnotation .Text , $" [{urlAnnotation .UrlCitation .Title }]({urlAnnotation .UrlCitation .Url })" );
318
+ }
319
+ }
320
+ }
321
+ Console .Write ($" Agent response: {response }" );
322
+ }
323
+ else if (contentItem is MessageImageFileContent imageFileItem )
324
+ {
325
+ Console .Write ($" <image from ID: {imageFileItem .FileId }" );
326
+ }
327
+ Console .WriteLine ();
328
+ }
329
+ }
330
+ ```
331
+
227
332
# [ Python] ( #tab/python )
228
333
229
334
``` python
0 commit comments