improve subscriptions (#4304)

This commit is contained in:
Ryan Sweet 2024-11-22 05:57:11 -08:00 committed by GitHub
parent eb67e4ac93
commit 97fd6cc1e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,8 +6,13 @@ namespace Microsoft.AutoGen.Agents;
internal sealed class SubscriptionsGrain([PersistentState("state", "PubSubStore")] IPersistentState<SubscriptionsState> state) : Grain, ISubscriptionsGrain
{
private readonly Dictionary<string, List<string>> _subscriptions = new();
public ValueTask<Dictionary<string, List<string>>> GetSubscriptions(string agentType)
public ValueTask<Dictionary<string, List<string>>> GetSubscriptions(string? agentType = null)
{
//if agentType is null, return all subscriptions else filter on agentType
if (agentType != null)
{
return new ValueTask<Dictionary<string, List<string>>>(_subscriptions.Where(x => x.Value.Contains(agentType)).ToDictionary(x => x.Key, x => x.Value));
}
return new ValueTask<Dictionary<string, List<string>>>(_subscriptions);
}
public ValueTask Subscribe(string agentType, string topic)