@@ -4,7 +4,7 @@ author: aahill
4
4
ms.author : aahi
5
5
ms.service : azure-ai-agent-service
6
6
ms.topic : include
7
- ms.date : 11/13/2024
7
+ ms.date : 01/15/2025
8
8
---
9
9
10
10
| [ 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
32
32
Install the .NET package to your project. For example if you're using the .NET CLI, run the following command.
33
33
34
34
``` 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
36
37
```
37
38
38
39
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_
59
60
60
61
#nullable disable
61
62
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 ;
67
64
68
65
namespace Azure .AI .Projects .Tests ;
69
66
70
- public partial class Sample_Agent_Basics : SamplesBase < AIProjectsTestEnvironment >
67
+ public class Sample_Agent
71
68
{
72
- [Test ]
73
- public async Task BasicExample ()
69
+ static async Task Main ()
74
70
{
75
71
var connectionString = Environment .GetEnvironmentVariable (" AZURE_AI_CONNECTION_STRING" );
76
72
77
73
AgentsClient client = new AgentsClient (connectionString , new DefaultAzureCredential ());
78
- #endregion
79
74
80
75
// Step 1: Create an agent
81
- #region Snippet:OverviewCreateAgent
82
76
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 ." ,
86
80
tools : new List <ToolDefinition > { new CodeInterpreterToolDefinition () });
87
81
Agent agent = agentResponse .Value ;
88
- #endregion
89
82
90
83
// Intermission: agent should now be listed
91
84
92
85
Response < PageableList < Agent >> agentListResponse = await client .GetAgentsAsync ();
93
86
94
87
// // Step 2: Create a thread
95
- #region Snippet:OverviewCreateThread
96
88
Response < AgentThread > threadResponse = await client .CreateThreadAsync ();
97
89
AgentThread thread = threadResponse .Value ;
98
- #endregion
99
90
100
91
// Step 3: Add a message to a thread
101
- #region Snippet:OverviewCreateMessage
102
92
Response < ThreadMessage > messageResponse = await client .CreateMessageAsync (
103
93
thread .Id ,
104
94
MessageRole .User ,
105
95
" I need to solve the equation `3x + 11 = 14`. Can you help me?" );
106
96
ThreadMessage message = messageResponse .Value ;
107
- #endregion
108
97
109
98
// Intermission: message is now correlated with thread
110
99
// Intermission: listing messages will retrieve the message just added
111
100
112
101
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);
114
103
115
104
// Step 4: Run the agent
116
- #region Snippet:OverviewCreateRun
117
105
Response < ThreadRun > runResponse = await client .CreateRunAsync (
118
106
thread .Id ,
119
107
agent .Id ,
120
- additionalInstructions : " Please address the user as Jane Doe. The user has a premium account. " );
108
+ additionalInstructions : " " );
121
109
ThreadRun run = runResponse .Value ;
122
- #endregion
123
110
124
- #region Snippet:OverviewWaitForRun
125
111
do
126
112
{
127
113
await Task .Delay (TimeSpan .FromMilliseconds (500 ));
128
114
runResponse = await client .GetRunAsync (thread .Id , runResponse .Value .Id );
129
115
}
130
116
while (runResponse .Value .Status == RunStatus .Queued
131
117
|| runResponse .Value .Status == RunStatus .InProgress );
132
- #endregion
133
118
134
- #region Snippet:OverviewListUpdatedMessages
135
119
Response < PageableList < ThreadMessage >> afterRunMessagesResponse
136
120
= await client .GetMessagesAsync (thread .Id );
137
121
IReadOnlyList < ThreadMessage > messages = afterRunMessagesResponse .Value .Data ;
@@ -153,7 +137,6 @@ public partial class Sample_Agent_Basics : SamplesBase<AIProjectsTestEnvironment
153
137
Console .WriteLine ();
154
138
}
155
139
}
156
- #endregion
157
140
}
158
141
}
159
142
```
0 commit comments