Skip to content

Commit 50dea76

Browse files
move publishEventAsync override to agentBaseExtension and keep IAgentBase simple
1 parent 100f893 commit 50dea76

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

dotnet/src/Microsoft.AutoGen/Abstractions/IAgentBase.cs

-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ public interface IAgentBase
1616
Task StoreAsync(AgentState state, CancellationToken cancellationToken = default);
1717
Task<T> ReadAsync<T>(AgentId agentId, CancellationToken cancellationToken = default) where T : IMessage, new();
1818
ValueTask PublishEventAsync(CloudEvent item, CancellationToken cancellationToken = default);
19-
ValueTask PublishEventAsync(string topic, IMessage evt, CancellationToken cancellationToken = default);
2019
List<string> Subscribe(string topic);
2120
}

dotnet/src/Microsoft.AutoGen/Agents/AgentBase.cs

-4
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,6 @@ public virtual Task HandleObject(object item)
265265
// otherwise, complain
266266
throw new InvalidOperationException($"No handler found for type {item.GetType().FullName}");
267267
}
268-
public async ValueTask PublishEventAsync(string topic, IMessage evt, CancellationToken cancellationToken = default)
269-
{
270-
await PublishEventAsync(evt.ToCloudEvent(topic), cancellationToken).ConfigureAwait(false);
271-
}
272268

273269
public virtual Task Handle(CloudEvent item)
274270
{

dotnet/src/Microsoft.AutoGen/Agents/AgentBaseExtensions.cs

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// AgentBaseExtensions.cs
33

44
using System.Diagnostics;
5+
using Google.Protobuf;
6+
using Microsoft.AutoGen.Abstractions;
57

68
namespace Microsoft.AutoGen.Agents;
79

@@ -112,4 +114,9 @@ public static async Task InvokeWithActivityAsync<TState>(this AgentBase agent, F
112114
activity?.Stop();
113115
}
114116
}
117+
118+
public static async ValueTask PublishEventAsync(this AgentBase agent, string topic, IMessage evt, CancellationToken cancellationToken = default)
119+
{
120+
await agent.PublishEventAsync(evt.ToCloudEvent(topic), cancellationToken).ConfigureAwait(false);
121+
}
115122
}

0 commit comments

Comments
 (0)