mirror of
https://github.com/microsoft/autogen.git
synced 2025-10-09 15:07:19 +00:00

adopts the new Microsoft.Extensions.AI abstractions adds a base InferenceAgent fixes a lot of pain points in the runtime wrt startup/shutdown fixes some uncaught exceptions in the grpc stream reading adds an example for running the backend service in its own process adds an example of an agent that connects to OpenAI/Ollama adds an example of wrapping an agent app in .NET Aspire upgrades some dependencies and removes some others Known bugs: #3922
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using Microsoft.AutoGen.Abstractions;
|
|
using Microsoft.AutoGen.Agents;
|
|
using Microsoft.Extensions.AI;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Hello;
|
|
[TopicSubscription("HelloAgents")]
|
|
public class HelloAIAgent(
|
|
IAgentContext context,
|
|
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
|
|
IChatClient client) : HelloAgent(
|
|
context,
|
|
typeRegistry),
|
|
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
|
|
}.ToCloudEvent(this.AgentId.Key);
|
|
await PublishEvent(evt).ConfigureAwait(false);
|
|
var goodbye = new ConversationClosed
|
|
{
|
|
UserId = this.AgentId.Key,
|
|
UserMessage = "Goodbye"
|
|
}.ToCloudEvent(this.AgentId.Key);
|
|
await PublishEvent(goodbye).ConfigureAwait(false);
|
|
}
|
|
}
|