Skip to content

Commit

Permalink
move publishEventAsync override to agentBaseExtension and keep IAgent…
Browse files Browse the repository at this point in the history
…Base simple
  • Loading branch information
LittleLittleCloud committed Nov 26, 2024
1 parent 100f893 commit 50dea76
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 0 additions & 1 deletion dotnet/src/Microsoft.AutoGen/Abstractions/IAgentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ public interface IAgentBase
Task StoreAsync(AgentState state, CancellationToken cancellationToken = default);
Task<T> ReadAsync<T>(AgentId agentId, CancellationToken cancellationToken = default) where T : IMessage, new();
ValueTask PublishEventAsync(CloudEvent item, CancellationToken cancellationToken = default);
ValueTask PublishEventAsync(string topic, IMessage evt, CancellationToken cancellationToken = default);
List<string> Subscribe(string topic);
}
4 changes: 0 additions & 4 deletions dotnet/src/Microsoft.AutoGen/Agents/AgentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ public virtual Task HandleObject(object item)
// otherwise, complain
throw new InvalidOperationException($"No handler found for type {item.GetType().FullName}");
}
public async ValueTask PublishEventAsync(string topic, IMessage evt, CancellationToken cancellationToken = default)
{
await PublishEventAsync(evt.ToCloudEvent(topic), cancellationToken).ConfigureAwait(false);
}

public virtual Task Handle(CloudEvent item)
{
Expand Down
7 changes: 7 additions & 0 deletions dotnet/src/Microsoft.AutoGen/Agents/AgentBaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// AgentBaseExtensions.cs

using System.Diagnostics;
using Google.Protobuf;
using Microsoft.AutoGen.Abstractions;

namespace Microsoft.AutoGen.Agents;

Expand Down Expand Up @@ -112,4 +114,9 @@ public static async Task InvokeWithActivityAsync<TState>(this AgentBase agent, F
activity?.Stop();
}
}

public static async ValueTask PublishEventAsync(this AgentBase agent, string topic, IMessage evt, CancellationToken cancellationToken = default)
{
await agent.PublishEventAsync(evt.ToCloudEvent(topic), cancellationToken).ConfigureAwait(false);
}
}

0 comments on commit 50dea76

Please sign in to comment.