2025-01-27 17:26:21 -05:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
// Modifier.cs
|
|
|
|
|
|
|
|
using Microsoft.AutoGen.Contracts;
|
|
|
|
using Microsoft.AutoGen.Core;
|
|
|
|
|
|
|
|
using ModifyF = System.Func<int, int>;
|
|
|
|
|
|
|
|
namespace Samples;
|
|
|
|
|
|
|
|
[TypeSubscription("default")]
|
|
|
|
public class Modifier(
|
|
|
|
AgentId id,
|
|
|
|
IAgentRuntime runtime,
|
|
|
|
ModifyF modifyFunc
|
|
|
|
) :
|
|
|
|
BaseAgent(id, runtime, "Modifier", null),
|
|
|
|
IHandle<CountMessage>
|
|
|
|
{
|
|
|
|
|
|
|
|
public async ValueTask HandleAsync(CountMessage item, MessageContext messageContext)
|
|
|
|
{
|
|
|
|
int newValue = modifyFunc(item.Content);
|
|
|
|
Console.WriteLine($"\nModifier:\nModified {item.Content} to {newValue}");
|
|
|
|
|
|
|
|
CountUpdate updateMessage = new CountUpdate { NewCount = newValue };
|
|
|
|
await this.PublishMessageAsync(updateMessage, topic: new TopicId("default"));
|
|
|
|
}
|
2025-01-27 19:27:01 -05:00
|
|
|
}
|