2025-01-27 18:22:42 -05:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
2025-01-27 17:26:21 -05:00
|
|
|
// Program.cs
|
|
|
|
|
|
|
|
using Microsoft.AutoGen.Contracts;
|
2025-01-27 19:27:01 -05:00
|
|
|
using Microsoft.AutoGen.Core;
|
2025-01-27 18:22:42 -05:00
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
using Samples;
|
|
|
|
using ModifyF = System.Func<int, int>;
|
2025-01-27 19:27:01 -05:00
|
|
|
using TerminationF = System.Func<int, bool>;
|
2025-01-27 17:26:21 -05:00
|
|
|
|
|
|
|
ModifyF modifyFunc = (int x) => x - 1;
|
|
|
|
TerminationF runUntilFunc = (int x) =>
|
|
|
|
{
|
|
|
|
return x <= 1;
|
|
|
|
};
|
|
|
|
|
2025-01-27 18:22:42 -05:00
|
|
|
AgentsAppBuilder appBuilder = new AgentsAppBuilder();
|
|
|
|
appBuilder.Services.TryAddSingleton(modifyFunc);
|
|
|
|
appBuilder.Services.TryAddSingleton(runUntilFunc);
|
2025-01-27 17:26:21 -05:00
|
|
|
|
2025-01-27 18:22:42 -05:00
|
|
|
appBuilder.AddAgent<Checker>("Checker");
|
|
|
|
appBuilder.AddAgent<Modifier>("Modifier");
|
|
|
|
var app = await appBuilder.BuildAsync();
|
2025-01-27 17:26:21 -05:00
|
|
|
|
|
|
|
// 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
|
2025-01-27 18:22:42 -05:00
|
|
|
await app.WaitForShutdownAsync();
|