You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 1.1 kB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Program.cs
  3. using Microsoft.AutoGen.Contracts;
  4. using Microsoft.AutoGen.Core;
  5. using Microsoft.Extensions.DependencyInjection.Extensions;
  6. using Samples;
  7. using ModifyF = System.Func<int, int>;
  8. using TerminationF = System.Func<int, bool>;
  9. ModifyF modifyFunc = (int x) => x - 1;
  10. TerminationF runUntilFunc = (int x) =>
  11. {
  12. return x <= 1;
  13. };
  14. AgentsAppBuilder appBuilder = new AgentsAppBuilder();
  15. appBuilder.UseInProcessRuntime();
  16. appBuilder.Services.TryAddSingleton(modifyFunc);
  17. appBuilder.Services.TryAddSingleton(runUntilFunc);
  18. appBuilder.AddAgent<Checker>("Checker");
  19. appBuilder.AddAgent<Modifier>("Modifier");
  20. var app = await appBuilder.BuildAsync();
  21. await app.StartAsync();
  22. // Send the initial count to the agents app, running on the `local` runtime, and pass through the registered services via the application `builder`
  23. await app.PublishMessageAsync(new CountMessage
  24. {
  25. Content = 10
  26. }, new TopicId("default"));
  27. // Run until application shutdown
  28. await app.WaitForShutdownAsync();