mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-04 15:41:15 +00:00

* add subscription response * fix send subscription response * add register agent type response * adding a test * working on shaping up a test * appsettins update for backend * another appsettings * fixup aspire hosting * enable AGENT_HOST var from aspire * add SendMessageAsync * remove broken test * test compiles and runs but is not (yet) correct * subscriptions grain wireup. * temp assert true. * remove DI for SubscriptionGrain * add xlang python code * add subscription response * rebond * Update to .NET 9.0 * Fix Backend project SDK * Package updates * get RegisterAgentTypeRequest working * fix exceptions * add error handling for requests * whoops * send cloud event message type * processing cloudevents * trying tosend proto data - doesn't work * trying to pack proto_data * fix (#4238) * pack the Message from agents_events * format - not sure why these? * format * cleanup, error handling, xlang sample publishes messages that can be heard by .NET and vice versa * format * sdk version * sdk vers * net8 * back to net8 * remove netstandard2 * fix used * remove unused * more cleanup * remove unneeded package * I'm terrible at writing tests * deserialize the cloud events and sent them as events * comment * cleanup * await * Delete dotnet/samples/Hello/Backend/Backend.csproj unneeded change * whoops * merge main python back into here * revert back to local * revert some of the helloAgents changes. * [.NET] Add happy path test for in-memory agent && Simplify HelloAgent example && some clean-up in extension APIs (#4227) * add happy path test * remove unnecessary namespace * fix build error * Update AgentBaseTests.cs * revert changes --------- * fix busted merge from main * addressing review comments * make internal * case sensitive rename step 1 * case sensitive rename step 2 * remove! --------- Co-authored-by: Peter Chang <petchang@microsoft.com> Co-authored-by: Reuben Bond <reuben.bond@gmail.com> Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com> Co-authored-by: Xiaoyun Zhang <bigmiao.zhang@gmail.com>
76 lines
2.4 KiB
C#
76 lines
2.4 KiB
C#
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Program.cs
|
|
|
|
using Microsoft.AutoGen.Abstractions;
|
|
using Microsoft.AutoGen.Agents;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
// step 1: create in-memory agent runtime
|
|
|
|
// step 2: register HelloAgent to that agent runtime
|
|
|
|
// step 3: start the agent runtime
|
|
|
|
// step 4: send a message to the agent
|
|
|
|
// step 5: wait for the agent runtime to shutdown
|
|
var app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived
|
|
{
|
|
Message = "World"
|
|
}, local: true);
|
|
//var app = await AgentsApp.StartAsync();
|
|
await app.WaitForShutdownAsync();
|
|
|
|
namespace Hello
|
|
{
|
|
[TopicSubscription("HelloAgents")]
|
|
public class HelloAgent(
|
|
IAgentRuntime context, IHostApplicationLifetime hostApplicationLifetime,
|
|
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : AgentBase(
|
|
context,
|
|
typeRegistry),
|
|
ISayHello,
|
|
IHandleConsole,
|
|
IHandle<NewMessageReceived>,
|
|
IHandle<ConversationClosed>,
|
|
IHandle<Shutdown>
|
|
{
|
|
public async Task Handle(NewMessageReceived item)
|
|
{
|
|
var response = await SayHello(item.Message).ConfigureAwait(false);
|
|
var evt = new Output { Message = response };
|
|
await PublishMessageAsync(evt).ConfigureAwait(false);
|
|
var goodbye = new ConversationClosed
|
|
{
|
|
UserId = this.AgentId.Key,
|
|
UserMessage = "Goodbye"
|
|
};
|
|
await PublishMessageAsync(goodbye).ConfigureAwait(false);
|
|
}
|
|
public async Task Handle(ConversationClosed item)
|
|
{
|
|
var goodbye = $"********************* {item.UserId} said {item.UserMessage} ************************";
|
|
var evt = new Output { Message = goodbye };
|
|
await PublishMessageAsync(evt).ConfigureAwait(true);
|
|
await PublishMessageAsync(new Shutdown()).ConfigureAwait(false);
|
|
}
|
|
|
|
public async Task Handle(Shutdown item)
|
|
{
|
|
Console.WriteLine("Shutting down...");
|
|
hostApplicationLifetime.StopApplication();
|
|
}
|
|
|
|
public async Task<string> SayHello(string ask)
|
|
{
|
|
var response = $"\n\n\n\n***************Hello {ask}**********************\n\n\n\n";
|
|
return response;
|
|
}
|
|
}
|
|
public interface ISayHello
|
|
{
|
|
public Task<string> SayHello(string ask);
|
|
}
|
|
}
|