Skip to content

Commit e993c25

Browse files
authored
Merge pull request #4995 from petehauge/update-samples-May16
Update samples with latest SDK details - ask mode approved merge
2 parents e8f7405 + 528d945 commit e993c25

File tree

3 files changed

+85
-26
lines changed

3 files changed

+85
-26
lines changed

articles/ai-services/agents/how-to/tools/azure-ai-search-samples.md

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ PersistentAgentsClient agentClient = new(projectEndpoint, new DefaultAzureCreden
165165
Using the AI Search Connection ID, configure the Azure AI Search tool to use your Azure AI Search index.
166166

167167
```csharp
168-
AzureAISearchResource searchResource = new(
168+
AzureAISearchToolResource searchResource = new(
169169
indexConnectionId: azureAiSearchConnectionId,
170170
indexName: "sample_index",
171171
topK: 5,
@@ -185,9 +185,10 @@ Change the model to the one deployed in your project. You can find the model nam
185185
PersistentAgent agent = agentClient.Administration.CreateAgent(
186186
model: modelDeploymentName,
187187
name: "my-agent",
188-
instructions: "You are a helpful agent.",
188+
instructions: "Use the index provided to answer questions.",
189189
tools: [new AzureAISearchToolDefinition()],
190-
toolResources: toolResource);
190+
toolResources: toolResource
191+
);
191192

192193
```
193194

@@ -199,7 +200,7 @@ Now that the agent is created, ask it questions about the data in your Azure AI
199200
PersistentAgentThread thread = agentClient.Threads.CreateThread();
200201

201202
// Create message and run the agent
202-
ThreadMessage message = agentClient.Messages.CreateMessage(
203+
PersistentThreadMessage message = agentClient.Messages.CreateMessage(
203204
thread.Id,
204205
MessageRole.User,
205206
"What is the temperature rating of the cozynights sleeping bag?");
@@ -228,13 +229,13 @@ if (run.Status != RunStatus.Completed)
228229
}
229230

230231
// Retrieve the messages from the agent client
231-
Pageable<ThreadMessage> messages = agentClient.Messages.GetMessages(
232+
Pageable<PersistentThreadMessage> messages = agentClient.Messages.GetMessages(
232233
threadId: thread.Id,
233234
order: ListSortOrder.Ascending
234235
);
235236

236237
// Process messages in order
237-
foreach (ThreadMessage threadMessage in messages)
238+
foreach (PersistentThreadMessage threadMessage in messages)
238239
{
239240
Console.Write($"{threadMessage.CreatedAt:yyyy-MM-dd HH:mm:ss} - {threadMessage.Role,10}: ");
240241
foreach (MessageContent contentItem in threadMessage.ContentItems)
@@ -249,11 +250,11 @@ foreach (ThreadMessage threadMessage in messages)
249250
// If we have Text URL citation annotations, reformat the response to show title & URL for citations
250251
foreach (MessageTextAnnotation annotation in textItem.Annotations)
251252
{
252-
if (annotation is MessageTextUrlCitationAnnotation urlAnnotation)
253+
if (annotation is MessageTextUriCitationAnnotation urlAnnotation)
253254
{
254255
annotatedText = annotatedText.Replace(
255256
urlAnnotation.Text,
256-
$" [see {urlAnnotation.UrlCitation.Title}] ({urlAnnotation.UrlCitation.Url})");
257+
$" [see {urlAnnotation.UriCitation.Title}] ({urlAnnotation.UriCitation.Uri})");
257258
}
258259
}
259260
Console.Write(annotatedText);
@@ -270,14 +271,45 @@ foreach (ThreadMessage threadMessage in messages)
270271
Console.WriteLine();
271272
}
272273
}
274+
```
275+
276+
## Optionally output the run steps used by the agent
277+
278+
```csharp
279+
// Retrieve the run steps used by the agent and print those to the console
280+
Console.WriteLine("Run Steps used by Agent:");
281+
Pageable<RunStep> runSteps = agentClient.Runs.GetRunSteps(run);
282+
283+
foreach (var step in runSteps)
284+
{
285+
Console.WriteLine($"Step ID: {step.Id}, Total Tokens: {step.Usage.TotalTokens}, Status: {step.Status}, Type: {step.Type}");
286+
287+
if (step.StepDetails is RunStepMessageCreationDetails messageCreationDetails)
288+
{
289+
Console.WriteLine($" Message Creation Id: {messageCreationDetails.MessageCreation.MessageId}");
290+
}
291+
else if (step.StepDetails is RunStepToolCallDetails toolCallDetails)
292+
{
293+
// We know this agent only has the AI Search tool, so we can cast it directly
294+
foreach (RunStepAzureAISearchToolCall toolCall in toolCallDetails.ToolCalls)
295+
{
296+
Console.WriteLine($" Tool Call Details: {toolCall.GetType()}");
297+
298+
foreach (var result in toolCall.AzureAISearch)
299+
{
300+
Console.WriteLine($" {result.Key}: {result.Value}");
301+
}
302+
}
303+
}
304+
}
305+
273306
```
274307
## Clean up resources
275308

276309
Clean up the resources from this sample.
277310

278311
```csharp
279-
280-
// Delete thread and agent
312+
// Clean up resources
281313
agentClient.Threads.DeleteThread(thread.Id);
282314
agentClient.Administration.DeleteAgent(agent.Id);
283315

articles/ai-services/agents/how-to/tools/bing-code-samples.md

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ To make the Grounding with Bing search tool available to your agent, use a conne
168168
```csharp
169169
// Create the BingGroundingToolDefinition object used when creating the agent
170170
BingGroundingToolDefinition bingGroundingTool = new BingGroundingToolDefinition(
171-
new BingGroundingSearchConfigurationList(
171+
new BingGroundingSearchToolParameters(
172172
[
173173
new BingGroundingSearchConfiguration(bingConnectionId)
174174
]
@@ -179,7 +179,7 @@ BingGroundingToolDefinition bingGroundingTool = new BingGroundingToolDefinition(
179179
PersistentAgent agent = agentClient.Administration.CreateAgent(
180180
model: modelDeploymentName,
181181
name: "my-agent",
182-
instructions: "You are a helpful agent.",
182+
instructions: "Use the bing grounding tool to answer questions.",
183183
tools: [bingGroundingTool]
184184
);
185185
```
@@ -190,11 +190,10 @@ PersistentAgent agent = agentClient.Administration.CreateAgent(
190190
PersistentAgentThread thread = agentClient.Threads.CreateThread();
191191

192192
// Create message and run the agent
193-
ThreadMessage message = agentClient.Messages.CreateMessage(
193+
PersistentThreadMessage message = agentClient.Messages.CreateMessage(
194194
thread.Id,
195195
MessageRole.User,
196196
"How does wikipedia explain Euler's Identity?");
197-
198197
ThreadRun run = agentClient.Runs.CreateRun(thread, agent);
199198

200199
```
@@ -204,7 +203,6 @@ ThreadRun run = agentClient.Runs.CreateRun(thread, agent);
204203
First, wait for the agent to complete the run by polling its status. Observe that the model uses the Grounding with Bing Search tool to provide a response to the user's question.
205204

206205
```csharp
207-
208206
// Wait for the agent to finish running
209207
do
210208
{
@@ -225,13 +223,13 @@ Then, retrieve and process the messages from the completed run.
225223

226224
```csharp
227225
// Retrieve all messages from the agent client
228-
Pageable<ThreadMessage> messages = agentClient.Messages.GetMessages(
226+
Pageable<PersistentThreadMessage> messages = agentClient.Messages.GetMessages(
229227
threadId: thread.Id,
230228
order: ListSortOrder.Ascending
231229
);
232230

233231
// Process messages in order
234-
foreach (ThreadMessage threadMessage in messages)
232+
foreach (PersistentThreadMessage threadMessage in messages)
235233
{
236234
Console.Write($"{threadMessage.CreatedAt:yyyy-MM-dd HH:mm:ss} - {threadMessage.Role,10}: ");
237235
foreach (MessageContent contentItem in threadMessage.ContentItems)
@@ -245,10 +243,9 @@ foreach (ThreadMessage threadMessage in messages)
245243
{
246244
foreach (MessageTextAnnotation annotation in textItem.Annotations)
247245
{
248-
if (annotation is MessageTextUrlCitationAnnotation urlAnnotation)
246+
if (annotation is MessageTextUriCitationAnnotation urlAnnotation)
249247
{
250-
response = response.Replace(urlAnnotation.Text,
251-
$" [{urlAnnotation.UrlCitation.Title}]({urlAnnotation.UrlCitation.Url})");
248+
response = response.Replace(urlAnnotation.Text, $" [{urlAnnotation.UriCitation.Title}]({urlAnnotation.UriCitation.Uri})");
252249
}
253250
}
254251
}
@@ -264,16 +261,46 @@ foreach (ThreadMessage threadMessage in messages)
264261

265262
```
266263

264+
## Optionally output the run steps used by the agent
265+
266+
```csharp
267+
// Retrieve the run steps used by the agent and print those to the console
268+
Console.WriteLine("Run Steps used by Agent:");
269+
Pageable<RunStep> runSteps = agentClient.Runs.GetRunSteps(run);
270+
271+
foreach (var step in runSteps)
272+
{
273+
Console.WriteLine($"Step ID: {step.Id}, Total Tokens: {step.Usage.TotalTokens}, Status: {step.Status}, Type: {step.Type}");
274+
275+
if (step.StepDetails is RunStepMessageCreationDetails messageCreationDetails)
276+
{
277+
Console.WriteLine($" Message Creation Id: {messageCreationDetails.MessageCreation.MessageId}");
278+
}
279+
else if (step.StepDetails is RunStepToolCallDetails toolCallDetails)
280+
{
281+
// We know this agent only has the Bing Grounding tool, so we can cast it directly
282+
foreach (RunStepBingGroundingToolCall toolCall in toolCallDetails.ToolCalls)
283+
{
284+
Console.WriteLine($" Tool Call Details: {toolCall.GetType()}");
285+
286+
foreach (var result in toolCall.BingGrounding)
287+
{
288+
Console.WriteLine($" {result.Key}: {result.Value}");
289+
}
290+
}
291+
}
292+
}
293+
294+
```
295+
267296
## Clean up resources
268297

269298
Clean up the resources from this sample.
270299

271300
```csharp
272-
273301
// Delete thread and agent
274302
agentClient.Threads.DeleteThread(threadId: thread.Id);
275303
agentClient.Administration.DeleteAgent(agentId: agent.Id);
276-
277304
```
278305

279306
::: zone-end

articles/ai-services/agents/how-to/tools/file-search-upload-files.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Dictionary<string, string> fileIds = new()
205205
// Create a vector store with the file and wait for it to be processed.
206206
// If you do not specify a vector store, CreateMessage will create a vector
207207
// store with a default expiration policy of seven days after they were last active
208-
VectorStore vectorStore = agentClient.VectorStores.CreateVectorStore(
208+
PersistentAgentsVectorStore vectorStore = agentClient.VectorStores.CreateVectorStore(
209209
fileIds: new List<string> { uploadedAgentFile.Id },
210210
name: "my_vector_store");
211211

@@ -238,7 +238,7 @@ You can also attach files as Message attachments on your thread. Doing so create
238238
PersistentAgentThread thread = agentClient.Threads.CreateThread();
239239

240240
// Create message and run the agent
241-
ThreadMessage messageResponse = agentClient.Messages.CreateMessage(
241+
PersistentThreadMessage messageResponse = agentClient.Messages.CreateMessage(
242242
thread.Id,
243243
MessageRole.User,
244244
"Can you give me the documented codes for 'banana' and 'orange'?");
@@ -273,7 +273,7 @@ Once the run is complete, retrieve the messages from the thread and process them
273273

274274
```csharp
275275
// Retrieve all messages from the agent client
276-
Pageable<ThreadMessage> messages = agentClient.Messages.GetMessages(
276+
Pageable<PersistentThreadMessage> messages = agentClient.Messages.GetMessages(
277277
threadId: thread.Id,
278278
order: ListSortOrder.Ascending
279279
);
@@ -288,7 +288,7 @@ static string replaceReferences(Dictionary<string, string> fileIds, string fileI
288288
}
289289

290290
// Process messages in order
291-
foreach (ThreadMessage threadMessage in messages)
291+
foreach (PersistentThreadMessage threadMessage in messages)
292292
{
293293
Console.Write($"{threadMessage.CreatedAt:yyyy-MM-dd HH:mm:ss} - {threadMessage.Role,10}: ");
294294

0 commit comments

Comments
 (0)