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

12345678910111213141516171819202122232425262728
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Program.cs
  3. using Microsoft.AutoGen.Agents;
  4. using Microsoft.AutoGen.Contracts;
  5. using Microsoft.AutoGen.Core;
  6. using Microsoft.AutoGen.Core.Grpc;
  7. using Samples;
  8. var appBuilder = new AgentsAppBuilder(); // Create app builder
  9. // if we are using distributed, we need the AGENT_HOST var defined and then we will use the grpc runtime
  10. if (Environment.GetEnvironmentVariable("AGENT_HOST") != null)
  11. {
  12. appBuilder.AddGrpcAgentWorker(
  13. Environment.GetEnvironmentVariable("AGENT_HOST"))
  14. .AddAgent<HelloAgent>("HelloAgent");
  15. }
  16. else
  17. {
  18. // Set up app builder for in-process runtime, allow message delivery to self, and add the Hello agent
  19. appBuilder.UseInProcessRuntime(deliverToSelf: true).AddAgent<HelloAgent>("HelloAgent");
  20. }
  21. var app = await appBuilder.BuildAsync(); // Build the app
  22. // Create a custom message type from proto and define message
  23. var message = new NewMessageReceived { Message = "Hello World!" };
  24. await app.PublishMessageAsync(message, new TopicId("HelloTopic", "HelloAgents/dotnet")).ConfigureAwait(false); // Publish custom message (handler has been set in HelloAgent)
  25. //await app.PublishMessageAsync(message, new TopicId("HelloTopic")).ConfigureAwait(false); // Publish custom message (handler has been set in HelloAgent)
  26. await app.WaitForShutdownAsync().ConfigureAwait(false); // Wait for shutdown from agent