You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -146,112 +146,161 @@ This ensures proper resource management and prevents unnecessary resource consum
146
146
147
147
:::zone pivot="csharp"
148
148
149
-
## Create a client and agent
149
+
## Create a project client
150
150
151
-
First, set up the configuration using `appsettings.json`, create a `PersistentAgentsClient`, and then create a `PersistentAgent` with the Code Interpreter tool enabled.
151
+
Create a client object, which will contain the project endpoint for connecting to your AI project and other resources.
To make the Grounding with Bing search 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](https://ai.azure.com/?cid=learnDocs).
## Wait for the agent to complete and print the output
192
202
193
-
Then, create a `ThreadRun` for the thread and agent. Poll the run's status until it completes or requires action.
203
+
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.
194
204
195
205
```csharp
196
-
ThreadRunrun=client.Runs.CreateRun(
197
-
thread.Id,
198
-
agent.Id,
199
-
additionalInstructions: "Please address the user as Jane Doe. The user has a premium account.");
200
-
206
+
// Wait for the agent to finish running
201
207
do
202
208
{
203
209
Thread.Sleep(TimeSpan.FromMilliseconds(500));
204
-
run=client.Runs.GetRun(thread.Id, run.Id);
210
+
run=agentClient.Runs.GetRun(thread.Id, run.Id);
205
211
}
206
212
while (run.Status==RunStatus.Queued
207
-
||run.Status==RunStatus.InProgress
208
-
||run.Status==RunStatus.RequiresAction);
209
-
```
213
+
||run.Status==RunStatus.InProgress);
210
214
211
-
## Process the results and handle files
215
+
// Confirm that the run completed successfully
216
+
if (run.Status!=RunStatus.Completed)
217
+
{
218
+
thrownewException("Run did not complete successfully, error: "+run.LastError?.Message);
219
+
}
220
+
```
212
221
213
-
Once the run is finished, retrieve all messages from the thread. Iterate through the messages to display text content and handle any generated image files by saving them locally and opening them.
222
+
Then, retrieve and process the messages from the completed run.
0 commit comments