mirror of
https://github.com/microsoft/autogen.git
synced 2025-06-26 22:30:10 +00:00

<img width="1840" alt="Screenshot 2025-01-30 at 6 26 02 PM" src="https://github.com/user-attachments/assets/5b4c9ebf-0880-4b2e-aa1f-f2b956922b49" />
31 lines
876 B
C#
31 lines
876 B
C#
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Modifier.cs
|
|
#region snippet_Modifier
|
|
using Microsoft.AutoGen.Contracts;
|
|
using Microsoft.AutoGen.Core;
|
|
|
|
using ModifyF = System.Func<int, int>;
|
|
|
|
namespace GettingStartedSample;
|
|
|
|
[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"));
|
|
}
|
|
}
|
|
#endregion snippet_Modifier
|