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

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