-
Notifications
You must be signed in to change notification settings - Fork 5
/
Program.cs
122 lines (104 loc) · 4.53 KB
/
Program.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using AutoGen.Core;
using AutoGen.OpenAI;
using AutoGen.OpenAI.Extension;
using Util;
var chatClient = ChatClientProvider.Create("gpt-4o-mini");
// Create the needed agents
var onboardingPersonalInformationAgent = new OpenAIChatAgent(
chatClient: chatClient,
name: "Onboarding_Personal_Information_Agent",
systemMessage: """
You are a helpful customer onboarding agent,
you are here to help new customers get started with our product.
Your job is to gather customer's name and location.
Do not ask for other information. Return 'TERMINATE'
when you have gathered all the information.
""")
.RegisterMessageConnector()
.RegisterPrintMessage();
var onboardingTopicPreferenceAgent = new OpenAIChatAgent(
chatClient: chatClient,
name: "Onboarding_Topic_Preference_Agent",
systemMessage: """
You are a helpful customer onboarding agent,
you are here to help new customers get started with our product.
Your job is to gather customer's preferences on news topics.
Do not ask for other information.
Return 'TERMINATE' when you have gathered all the information.
""")
.RegisterMessageConnector()
.RegisterPrintMessage();
var customerEngagementAgent = new OpenAIChatAgent(
chatClient: chatClient,
name: "Customer_Engagement_Agent",
systemMessage: """
You are a helpful customer service agent
here to provide fun for the customer based on the user's
personal information and topic preferences.
This could include fun facts, jokes, or interesting stories.
Make sure to make it engaging and fun!
Return 'TERMINATE' when you are done.
""")
.RegisterMessageConnector()
.RegisterPrintMessage();
var summarizer = new OpenAIChatAgent(
chatClient: chatClient,
name: "Summarizer",
systemMessage: """
You are a helpful summarizer agent.
Your job is to summarize the conversation between the user and the customer service agent.
Return 'TERMINATE' when you are done.
""")
.RegisterMessageConnector()
.RegisterPrintMessage();
var user = new OpenAIChatAgent(
chatClient: chatClient,
name: "User",
systemMessage: """
Your name is John and you live in New York.
You are reaching out to customer service to find out something fun.
""")
.RegisterMessageConnector()
.RegisterPrintMessage();
// Creating Tasks
// In python AutoGen, you can use initiate_chats to create and run a sequential of tasks in json object
// In dotnet AutoGen, however, that feature is not available, so you need to manually create these tasks using code.
// Task 1. Onboard customer by gathering name and location
// (onboard_personal_information_agent -> user .. (repeat less than two times)) -> summarizer
var greetingMessage = new TextMessage(Role.Assistant, """
Hello, I'm here to help you get started with our product.
Could you tell me your name and location?
""", from: onboardingPersonalInformationAgent.Name);
var conversation = await onboardingPersonalInformationAgent.SendAsync(
receiver: user,
[greetingMessage],
maxRound: 2)
.ToListAsync();
var summarizePrompt = """
Return the customer information into as JSON object only: {'name': '', 'location': ''}
""";
var summary = await summarizer.SendAsync(summarizePrompt, conversation);
// Task 2. Gapther customer's preferences on news topics
// (onboarding_topic_preference_agent -> user .. (repeat one time)) -> summarizer
var topicPreferenceMessage = new TextMessage(Role.Assistant, """
Great! Could you tell me what topics you are interested in reading about?
""", from: onboardingTopicPreferenceAgent.Name);
conversation = await onboardingTopicPreferenceAgent.SendAsync(
receiver: user,
[topicPreferenceMessage],
maxRound: 1)
.ToListAsync();
// Keep summarizing
summary = await summarizer.SendAsync(chatHistory: new[] { summary }.Concat(conversation));
// Task 3. Engage the customer with fun facts, jokes, or interesting stories based on the user's personal information and topic preferences
// (user(find fun thing to read) -> customerEngagementAgent .. (repeat 1 time)) -> summarizer
var funFactMessage = new TextMessage(Role.User, """
Let's find something fun to read.
""", from: user.Name);
conversation = await user.SendAsync(
receiver: customerEngagementAgent,
chatHistory: conversation.Concat([funFactMessage]), // this time, we keep the previous conversation history
maxRound: 1)
.ToListAsync();
// Keep summarizing
summary = await summarizer.SendAsync(chatHistory: new[] { summary }.Concat(conversation));