-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example01_AssistantAgent.cs
36 lines (32 loc) · 1.38 KB
/
Example01_AssistantAgent.cs
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
using AutoGen.Core;
using AutoGen.SemanticKernel.Extension;
using FluentAssertions;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
namespace AutoGen.BasicSamples;
public static class Example01_AssistantAgent
{
public static async Task RunAsync(IKernelBuilder kernelBuilder, OpenAIPromptExecutionSettings settings)
{
// create assistant agent
var assistantAgent = kernelBuilder.Build().ToSemanticKernelAgent(
name: "assistant",
systemMessage: "You convert what user said to all uppercase.",
settings: settings)
.RegisterMessageConnector()
.RegisterPrintMessage();
// talk to the assistant agent
var reply = await assistantAgent.SendAsync("hello world");
reply.Should().BeOfType<TextMessage>();
reply.GetContent().Should().Be("HELLO WORLD");
// to carry on the conversation, pass the previous conversation history to the next call
var conversationHistory = new List<IMessage>
{
new TextMessage(Role.User, "hello world"), // first message
reply, // reply from assistant agent
};
reply = await assistantAgent.SendAsync("hello world again", conversationHistory);
reply.Should().BeOfType<TextMessage>();
reply.GetContent().Should().Be("HELLO WORLD AGAIN");
}
}