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.

Modifier.cs 876 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Modifier.cs
  3. #region snippet_Modifier
  4. using Microsoft.AutoGen.Contracts;
  5. using Microsoft.AutoGen.Core;
  6. using ModifyF = System.Func<int, int>;
  7. namespace GettingStartedSample;
  8. [TypeSubscription("default")]
  9. public class Modifier(
  10. AgentId id,
  11. IAgentRuntime runtime,
  12. ModifyF modifyFunc
  13. ) :
  14. BaseAgent(id, runtime, "Modifier", null),
  15. IHandle<CountMessage>
  16. {
  17. public async ValueTask HandleAsync(CountMessage item, MessageContext messageContext)
  18. {
  19. int newValue = modifyFunc(item.Content);
  20. Console.WriteLine($"\nModifier:\nModified {item.Content} to {newValue}");
  21. CountUpdate updateMessage = new CountUpdate { NewCount = newValue };
  22. await this.PublishMessageAsync(updateMessage, topic: new TopicId("default"));
  23. }
  24. }
  25. #endregion snippet_Modifier