Skip to content

Commit 44dcf40

Browse files
committed
updating csharp code
1 parent 75a90bb commit 44dcf40

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

articles/ai-services/agents/includes/quickstart-csharp.md

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: aahill
44
ms.author: aahi
55
ms.service: azure-ai-agent-service
66
ms.topic: include
7-
ms.date: 11/13/2024
7+
ms.date: 01/15/2025
88
---
99

1010
| [Reference documentation](/dotnet/api/overview/azure/ai.projects-readme) | [Samples](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/ai/Azure.AI.Projects/tests/Samples) | [Library source code](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/ai/Azure.AI.Projects) | [Package (NuGet)](https://www.nuget.org/packages/Azure.AI.Projects/) |
@@ -32,7 +32,8 @@ ms.date: 11/13/2024
3232
Install the .NET package to your project. For example if you're using the .NET CLI, run the following command.
3333

3434
```console
35-
dotnet add package Azure.AI.Projects --version 1.0.0-beta.1
35+
dotnet add package Azure.AI.Projects
36+
dotnet add package Azure.Identity
3637
```
3738

3839
Use the following code to create and run an agent. To run this code, you will need to create a connection string using information from your project. This string is in the format:
@@ -59,79 +60,62 @@ Set this connection string as an environment variable named `PROJECT_CONNECTION_
5960
6061
#nullable disable
6162

62-
using System;
63-
using System.Collections.Generic;
64-
using System.Threading.Tasks;
65-
using Azure.Core.TestFramework;
66-
using NUnit.Framework;
63+
using Azure.Identity;
6764

6865
namespace Azure.AI.Projects.Tests;
6966

70-
public partial class Sample_Agent_Basics : SamplesBase<AIProjectsTestEnvironment>
67+
public class Sample_Agent
7168
{
72-
[Test]
73-
public async Task BasicExample()
69+
static async Task Main()
7470
{
7571
var connectionString = Environment.GetEnvironmentVariable("AZURE_AI_CONNECTION_STRING");
7672

7773
AgentsClient client = new AgentsClient(connectionString, new DefaultAzureCredential());
78-
#endregion
7974

8075
// Step 1: Create an agent
81-
#region Snippet:OverviewCreateAgent
8276
Response<Agent> agentResponse = await client.CreateAgentAsync(
83-
model: "gpt-4o",
84-
name: "Math Tutor",
85-
instructions: "You are a personal math tutor. Write and run code to answer math questions.",
77+
model: "gpt-4o-mini",
78+
name: "My Agent",
79+
instructions: "You are a helpful agent.",
8680
tools: new List<ToolDefinition> { new CodeInterpreterToolDefinition() });
8781
Agent agent = agentResponse.Value;
88-
#endregion
8982

9083
// Intermission: agent should now be listed
9184
9285
Response<PageableList<Agent>> agentListResponse = await client.GetAgentsAsync();
9386

9487
//// Step 2: Create a thread
95-
#region Snippet:OverviewCreateThread
9688
Response<AgentThread> threadResponse = await client.CreateThreadAsync();
9789
AgentThread thread = threadResponse.Value;
98-
#endregion
9990

10091
// Step 3: Add a message to a thread
101-
#region Snippet:OverviewCreateMessage
10292
Response<ThreadMessage> messageResponse = await client.CreateMessageAsync(
10393
thread.Id,
10494
MessageRole.User,
10595
"I need to solve the equation `3x + 11 = 14`. Can you help me?");
10696
ThreadMessage message = messageResponse.Value;
107-
#endregion
10897

10998
// Intermission: message is now correlated with thread
11099
// Intermission: listing messages will retrieve the message just added
111100
112101
Response<PageableList<ThreadMessage>> messagesListResponse = await client.GetMessagesAsync(thread.Id);
113-
Assert.That(messagesListResponse.Value.Data[0].Id == message.Id);
102+
//Assert.That(messagesListResponse.Value.Data[0].Id == message.Id);
114103
115104
// Step 4: Run the agent
116-
#region Snippet:OverviewCreateRun
117105
Response<ThreadRun> runResponse = await client.CreateRunAsync(
118106
thread.Id,
119107
agent.Id,
120-
additionalInstructions: "Please address the user as Jane Doe. The user has a premium account.");
108+
additionalInstructions: "");
121109
ThreadRun run = runResponse.Value;
122-
#endregion
123110

124-
#region Snippet:OverviewWaitForRun
125111
do
126112
{
127113
await Task.Delay(TimeSpan.FromMilliseconds(500));
128114
runResponse = await client.GetRunAsync(thread.Id, runResponse.Value.Id);
129115
}
130116
while (runResponse.Value.Status == RunStatus.Queued
131117
|| runResponse.Value.Status == RunStatus.InProgress);
132-
#endregion
133118

134-
#region Snippet:OverviewListUpdatedMessages
135119
Response<PageableList<ThreadMessage>> afterRunMessagesResponse
136120
= await client.GetMessagesAsync(thread.Id);
137121
IReadOnlyList<ThreadMessage> messages = afterRunMessagesResponse.Value.Data;
@@ -153,7 +137,6 @@ public partial class Sample_Agent_Basics : SamplesBase<AIProjectsTestEnvironment
153137
Console.WriteLine();
154138
}
155139
}
156-
#endregion
157140
}
158141
}
159142
```

0 commit comments

Comments
 (0)