-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathProgram.cs
More file actions
37 lines (29 loc) · 1.34 KB
/
Program.cs
File metadata and controls
37 lines (29 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
var endpoint = config["AzureOpenAI:Endpoint"] ?? throw new InvalidOperationException(
"Missing 'AzureOpenAI:Endpoint'. Run: dotnet user-secrets set \"AzureOpenAI:Endpoint\" \"https://<your-resource>.openai.azure.com/\"");
var deploymentName = config["AzureOpenAI:Deployment"] ?? "gpt-5-mini";
IChatClient chatClient =
new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
.GetChatClient(deploymentName)
.AsIChatClient();
AIAgent writer = chatClient.AsAIAgent(
name: "Writer",
instructions: "Write stories that are engaging and creative.");
// Create a specialized editor agent
AIAgent editor = chatClient.AsAIAgent(
name: "Editor",
instructions: "Make the story more engaging, fix grammar, and enhance the plot.");
// Create a workflow that connects writer to editor
Workflow workflow =
AgentWorkflowBuilder
.BuildSequential(writer, editor);
AIAgent workflowAgent = workflow.AsAIAgent();
AgentResponse workflowResponse =
await workflowAgent.RunAsync("Write a short story about a haunted house.");
Console.WriteLine(workflowResponse.Text);