-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
Copy pathHelloAIAgent.cs
31 lines (28 loc) · 1.11 KB
/
HelloAIAgent.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// HelloAIAgent.cs
using Microsoft.AutoGen.Abstractions;
using Microsoft.AutoGen.Agents;
using Microsoft.Extensions.AI;
namespace Hello;
[TopicSubscription("HelloAgents")]
public class HelloAIAgent(
IAgentRuntime context,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
IHostApplicationLifetime hostApplicationLifetime,
IChatClient client) : HelloAgent(
context,
typeRegistry,
hostApplicationLifetime),
IHandle<NewMessageReceived>
{
// This Handle supercedes the one in the base class
public new async Task Handle(NewMessageReceived item)
{
var prompt = "Please write a limerick greeting someone with the name " + item.Message;
var response = await client.CompleteAsync(prompt);
var evt = new Output { Message = response.Message.Text };
await PublishMessageAsync(evt).ConfigureAwait(false);
var goodbye = new ConversationClosed { UserId = this.AgentId.Key, UserMessage = "Goodbye" };
await PublishMessageAsync(goodbye).ConfigureAwait(false);
}
}