44 lines
1.3 KiB
C#
Raw Normal View History

// Copyright (c) Microsoft Corporation. All rights reserved.
2025-01-27 17:26:21 -05:00
// Program.cs
#region snippet_Program
#region snippet_Program_funcs
using GettingStartedSample;
2025-01-27 17:26:21 -05:00
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Core;
using Microsoft.Extensions.DependencyInjection.Extensions;
using ModifyF = System.Func<int, int>;
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;
};
#endregion snippet_Program_funcs
2025-01-27 17:26:21 -05:00
#region snippet_Program_builder
AgentsAppBuilder appBuilder = new AgentsAppBuilder();
appBuilder.UseInProcessRuntime();
appBuilder.Services.TryAddSingleton(modifyFunc);
appBuilder.Services.TryAddSingleton(runUntilFunc);
2025-01-27 17:26:21 -05:00
appBuilder.AddAgent<Checker>("Checker");
appBuilder.AddAgent<Modifier>("Modifier");
var app = await appBuilder.BuildAsync();
await app.StartAsync();
#endregion snippet_Program_builder
2025-01-27 17:26:21 -05:00
#region snippet_Program_publish
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
await app.WaitForShutdownAsync();
#endregion snippet_Program_publish
#endregion snippet_Program