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
@@ -5,7 +5,7 @@ description: Find code samples to enable code interpreter for Azure AI Agents.
5
5
author: aahill
6
6
ms.author: aahi
7
7
manager: nitinme
8
-
ms.date: 06/30/2025
8
+
ms.date: 08/11/2025
9
9
ms.service: azure-ai-agent-service
10
10
ms.topic: how-to
11
11
ms.custom:
@@ -146,161 +146,112 @@ This ensures proper resource management and prevents unnecessary resource consum
146
146
147
147
:::zone pivot="csharp"
148
148
149
-
## Create a project client
149
+
## Create a client and agent
150
150
151
-
Create a client object, which will contain the project endpoint for connecting to your AI project and other resources.
151
+
First, set up the configuration using `appsettings.json`, create a `PersistentAgentsClient`, and then create a `PersistentAgent` with the Code Interpreter tool enabled.
## Create an Agent with the Grounding with Bing search tool enabled
167
-
168
-
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).
"Hi, Agent! Draw a graph for a line with a slope of 4 and y-intercept of 9.");
199
189
```
200
190
201
-
## Wait for the agent to complete and print the output
191
+
## Create and monitor a run
202
192
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.
193
+
Then, create a `ThreadRun` for the thread and agent. Poll the run's status until it completes or requires action.
204
194
205
195
```csharp
206
-
// Wait for the agent to finish running
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
+
207
201
do
208
202
{
209
203
Thread.Sleep(TimeSpan.FromMilliseconds(500));
210
-
run=agentClient.Runs.GetRun(thread.Id, run.Id);
204
+
run=client.Runs.GetRun(thread.Id, run.Id);
211
205
}
212
206
while (run.Status==RunStatus.Queued
213
-
||run.Status==RunStatus.InProgress);
214
-
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
-
}
207
+
||run.Status==RunStatus.InProgress
208
+
||run.Status==RunStatus.RequiresAction);
220
209
```
221
210
222
-
Then, retrieve and process the messages from the completed run.
211
+
## Process the results and handle files
212
+
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.
0 commit comments