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.3 kB

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