Ryan Sweet a19c848622
rysweet-4677-rename-agents-project-to-core-trim-dependencies (#4696)
* move optional base agents to separate package
* rename main sdk to Core
* reduce dependency graph
Co-authored-by: @rysweet 
Authored-by: @kostapetan 
Co-authored-by: @kopetan-ms
2024-12-13 11:55:43 -08:00

32 lines
1.1 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved.
// HelloAIAgent.cs
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Core;
using Microsoft.Extensions.AI;
namespace Hello;
[TopicSubscription("agents")]
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);
}
}