@@ -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
170170BingGroundingToolDefinition bingGroundingTool = new BingGroundingToolDefinition (
171- new BingGroundingSearchConfigurationList (
171+ new BingGroundingSearchToolParameters (
172172 [
173173 new BingGroundingSearchConfiguration (bingConnectionId )
174174 ]
@@ -179,7 +179,7 @@ BingGroundingToolDefinition bingGroundingTool = new BingGroundingToolDefinition(
179179PersistentAgent 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(
190190PersistentAgentThread 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-
198197ThreadRun run = agentClient .Runs .CreateRun (thread , agent );
199198
200199```
@@ -204,7 +203,6 @@ ThreadRun run = agentClient.Runs.CreateRun(thread, agent);
204203First, 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
209207do
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
269298Clean up the resources from this sample.
270299
271300``` csharp
272-
273301// Delete thread and agent
274302agentClient .Threads .DeleteThread (threadId : thread .Id );
275303agentClient .Administration .DeleteAgent (agentId : agent .Id );
276-
277304```
278305
279306::: zone-end
0 commit comments