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 841 B

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