Jacob Alber 43e9c266c1
feat: Enable queueing and step mode in InProcessRuntime (#5239)
Moves the semantics of message delivery in .NET to be closer to Python
(up to vagaries of differences in Threading)

* Creates a message delivery queue in InProcessRuntime
* Creates Start/Stop/WaitForIdle APIs on InProcessRuntime
* Creates API to step individual messages
* Updates InProcessRuntime to play well with IHost as an IHostedService
2025-01-28 20:28:05 +00:00

34 lines
1019 B
C#

// Copyright (c) Microsoft Corporation. All rights reserved.
// Program.cs
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Core;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Samples;
using ModifyF = System.Func<int, int>;
using TerminationF = System.Func<int, bool>;
ModifyF modifyFunc = (int x) => x - 1;
TerminationF runUntilFunc = (int x) =>
{
return x <= 1;
};
AgentsAppBuilder appBuilder = new AgentsAppBuilder();
appBuilder.Services.TryAddSingleton(modifyFunc);
appBuilder.Services.TryAddSingleton(runUntilFunc);
appBuilder.AddAgent<Checker>("Checker");
appBuilder.AddAgent<Modifier>("Modifier");
var app = await appBuilder.BuildAsync();
await app.StartAsync();
// Send the initial count to the agents app, running on the `local` runtime, and pass through the registered services via the application `builder`
await app.PublishMessageAsync(new CountMessage
{
Content = 10
}, new TopicId("default"));
// Run until application shutdown
await app.WaitForShutdownAsync();