@@ -136,14 +136,13 @@ using Azure.Core;
136
136
using Azure .Core .TestFramework ;
137
137
using NUnit .Framework ;
138
138
139
- var connectionString = TestEnvironment .AzureAICONNECTIONSTRING ;
139
+ var connectionString = System .Environment .GetEnvironmentVariable (" PROJECT_CONNECTION_STRING" );
140
+ var modelDeploymentName = System .Environment .GetEnvironmentVariable (" MODEL_DEPLOYMENT_NAME" );
141
+ var bingConnectionName = System .Environment .GetEnvironmentVariable (" BING_CONNECTION_NAME" );
140
142
141
- var clientOptions = new AIProjectClientOptions ();
142
-
143
- // Adding the custom headers policy
144
- clientOptions .AddPolicy (new CustomHeadersPolicy (), HttpPipelinePosition .PerCall );
145
- var projectClient = new AIProjectClient (connectionString , new DefaultAzureCredential (), clientOptions );
143
+ var projectClient = new AIProjectClient (connectionString , new DefaultAzureCredential ());
146
144
145
+ AgentsClient agentClient = projectClient .GetAgentsClient ();
147
146
```
148
147
149
148
# [ JavaScript] ( #tab/javascript )
@@ -202,23 +201,20 @@ with project_client:
202
201
# [ C#] ( #tab/csharp )
203
202
204
203
``` csharp
205
- GetConnectionResponse bingConnection = await projectClient .GetConnectionsClient ().GetConnectionAsync ( TestEnvironment . BINGCONNECTIONNAME );
204
+ ConnectionResponse bingConnection = projectClient .GetConnectionsClient ().GetConnection ( bingConnectionName );
206
205
var connectionId = bingConnection .Id ;
207
206
208
- AgentsClient agentClient = projectClient .GetAgentsClient ();
209
-
210
- ToolConnectionList connectionList = new ToolConnectionList
207
+ ToolConnectionList connectionList = new ()
211
208
{
212
209
ConnectionList = { new ToolConnection (connectionId ) }
213
210
};
214
- BingGroundingToolDefinition bingGroundingTool = new BingGroundingToolDefinition (connectionList );
215
-
216
- Response < Agent > agentResponse = await agentClient .CreateAgentAsync (
217
- model : " gpt-4o" ,
218
- name : " my-assistant" ,
219
- instructions : " You are a helpful assistant." ,
220
- tools : new List <ToolDefinition > { bingGroundingTool });
221
- Agent agent = agentResponse .Value ;
211
+ BingGroundingToolDefinition bingGroundingTool = new (connectionList );
212
+
213
+ Agent agent = agentClient .CreateAgent (
214
+ model : modelDeploymentName ,
215
+ name : " my-assistant" ,
216
+ instructions : " You are a helpful assistant." ,
217
+ tools : [bingGroundingTool ]);
222
218
```
223
219
224
220
# [ JavaScript] ( #tab/javascript )
@@ -285,16 +281,13 @@ print(f"Created message, ID: {message.id}")
285
281
# [ C#] ( #tab/csharp )
286
282
287
283
``` csharp
288
- // Create thread for communication
289
- Response < AgentThread > threadResponse = await agentClient .CreateThreadAsync ();
290
- AgentThread thread = threadResponse .Value ;
284
+ AgentThread thread = agentClient .CreateThread ();
291
285
292
286
// Create message to thread
293
- Response < ThreadMessage > messageResponse = await agentClient .CreateMessageAsync (
287
+ ThreadMessage message = agentClient .CreateMessage (
294
288
thread .Id ,
295
289
MessageRole .User ,
296
290
" How does wikipedia explain Euler's Identity?" );
297
- ThreadMessage message = messageResponse .Value ;
298
291
```
299
292
300
293
# [ JavaScript] ( #tab/javascript )
@@ -312,6 +305,7 @@ await client.agents.createMessage(
312
305
```
313
306
314
307
# [ REST API] ( #tab/rest )
308
+
315
309
### Create a thread
316
310
317
311
``` console
@@ -367,30 +361,46 @@ print(f"Messages: {messages}")
367
361
# [ C#] ( #tab/csharp )
368
362
369
363
``` csharp
370
- // Run the agent
371
- Response < ThreadRun > runResponse = await agentClient .CreateRunAsync (thread , agent );
372
364
365
+ // Run the agent
366
+ ThreadRun run = agentClient .CreateRun (thread , agent );
373
367
do
374
368
{
375
- await Task . Delay (TimeSpan .FromMilliseconds (500 ));
376
- runResponse = await agentClient .GetRunAsync (thread .Id , runResponse . Value .Id );
369
+ Thread . Sleep (TimeSpan .FromMilliseconds (500 ));
370
+ run = agentClient .GetRun (thread .Id , run .Id );
377
371
}
378
- while (runResponse .Value .Status == RunStatus .Queued
379
- || runResponse .Value .Status == RunStatus .InProgress );
372
+ while (run .Status == RunStatus .Queued
373
+ || run .Status == RunStatus .InProgress );
374
+
375
+ Assert .AreEqual (
376
+ RunStatus .Completed ,
377
+ run .Status ,
378
+ run .LastError ? .Message );
380
379
381
- Response < PageableList < ThreadMessage >> afterRunMessagesResponse
382
- = await agentClient .GetMessagesAsync (thread .Id );
383
- IReadOnlyList < ThreadMessage > messages = afterRunMessagesResponse .Value .Data ;
380
+ PageableList < ThreadMessage > messages = agentClient .GetMessages (
381
+ threadId : thread .Id ,
382
+ order : ListSortOrder .Ascending
383
+ );
384
384
385
- // Note: messages iterate from newest to oldest, with the messages[0] being the most recent
386
385
foreach (ThreadMessage threadMessage in messages )
387
386
{
388
387
Console .Write ($" {threadMessage .CreatedAt : yyyy - MM - dd HH : mm : ss } - {threadMessage .Role ,10 }: " );
389
388
foreach (MessageContent contentItem in threadMessage .ContentItems )
390
389
{
391
390
if (contentItem is MessageTextContent textItem )
392
391
{
393
- Console .Write (textItem .Text );
392
+ string response = textItem .Text ;
393
+ if (textItem .Annotations != null )
394
+ {
395
+ foreach (MessageTextAnnotation annotation in textItem .Annotations )
396
+ {
397
+ if (annotation is MessageTextUrlCitationAnnotation urlAnnotation )
398
+ {
399
+ response = response .Replace (urlAnnotation .Text , $" [{urlAnnotation .UrlCitation .Title }]({urlAnnotation .UrlCitation .Url })" );
400
+ }
401
+ }
402
+ }
403
+ Console .Write ($" Agent response: {response }" );
394
404
}
395
405
else if (contentItem is MessageImageFileContent imageFileItem )
396
406
{
@@ -399,6 +409,9 @@ foreach (ThreadMessage threadMessage in messages)
399
409
Console .WriteLine ();
400
410
}
401
411
}
412
+
413
+ agentClient .DeleteThread (threadId : thread .Id );
414
+ agentClient .DeleteAgent (agentId : agent .Id );
402
415
```
403
416
404
417
# [ JavaScript] ( #tab/javascript )
0 commit comments