|
11 | 11 | string endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set."); |
12 | 12 | string deploymentName = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; |
13 | 13 |
|
14 | | -const string JokerInstructions = "You are good at telling jokes."; |
| 14 | +const string JokerInstructionsV1 = "You are good at telling jokes."; |
| 15 | +const string JokerInstructionsV2 = "You are extremely hilarious at telling jokes."; |
15 | 16 | const string JokerName = "JokerAgent"; |
16 | 17 |
|
17 | 18 | // Get a client to create/retrieve/delete server side agents with Azure Foundry Agents. |
18 | 19 | AIProjectClient aiProjectClient = new(new Uri(endpoint), new AzureCliCredential()); |
19 | 20 |
|
20 | 21 | // Define the agent you want to create. (Prompt Agent in this case) |
21 | | -AgentVersionCreationOptions options = new(new PromptAgentDefinition(model: deploymentName) { Instructions = JokerInstructions }); |
| 22 | +AgentVersionCreationOptions options = new(new PromptAgentDefinition(model: deploymentName) { Instructions = JokerInstructionsV1 }); |
22 | 23 |
|
23 | 24 | // Azure.AI.Agents SDK creates and manages agent by name and versions. |
24 | 25 | // You can create a server side agent version with the Azure.AI.Agents SDK client below. |
|
32 | 33 | // You can retrieve an AIAgent for an already created server side agent version. |
33 | 34 | AIAgent jokerAgentV1 = aiProjectClient.GetAIAgent(agentVersion); |
34 | 35 |
|
35 | | -// You can also create another AIAgent version (V2) by providing the same name with a different definition. |
36 | | -AIAgent jokerAgentV2 = aiProjectClient.CreateAIAgent(name: JokerName, model: deploymentName, instructions: JokerInstructions + "V2"); |
| 36 | +// You can also create another AIAgent version (V2) by providing the same name with a different definition/instruction. |
| 37 | +AIAgent jokerAgentV2 = aiProjectClient.CreateAIAgent(name: JokerName, model: deploymentName, instructions: JokerInstructionsV2); |
37 | 38 |
|
38 | 39 | // You can also get the AIAgent latest version by just providing its name. |
39 | 40 | AIAgent jokerAgentLatest = aiProjectClient.GetAIAgent(name: JokerName); |
|
43 | 44 | Console.WriteLine($"Latest agent version id: {latestVersion.Id}"); |
44 | 45 |
|
45 | 46 | // Once you have the AIAgent, you can invoke it like any other AIAgent. |
46 | | -AgentThread thread = jokerAgentLatest.GetNewThread(); |
47 | | -Console.WriteLine(await jokerAgentLatest.RunAsync("Tell me a joke about a pirate.", thread)); |
48 | | - |
49 | | -// This will use the same thread to continue the conversation. |
50 | | -Console.WriteLine(await jokerAgentLatest.RunAsync("Now tell me a joke about a cat and a dog using last joke as the anchor.", thread)); |
| 47 | +Console.WriteLine(await jokerAgentLatest.RunAsync("Tell me a joke about a pirate.")); |
51 | 48 |
|
52 | 49 | // Cleanup by agent name removes both agent versions created (jokerAgentV1 + jokerAgentV2). |
53 | 50 | await aiProjectClient.Agents.DeleteAgentAsync(jokerAgentV1.Name); |
0 commit comments