add subscriptions to host builder

This commit is contained in:
Jack Gerrits
2025-01-27 14:43:41 -05:00
committed by Jack Gerrits
parent fe8faa9133
commit 2ba7732220
2 changed files with 8 additions and 8 deletions

View File

@@ -69,7 +69,7 @@ public static class AgentRuntimeExtensions
return subscriptions.ToArray();
}
public static async ValueTask RegisterImplicitAgentSubscriptionsAsync<TAgent>(this IAgentRuntime runtime, AgentType type) where TAgent : IHostableAgent
public static async ValueTask RegisterImplicitAgentSubscriptionsAsync<TAgent>(this IAgentRuntime runtime, AgentType type, bool skipClassSubscriptions = false, bool skipDirectMessageSubscription = false) where TAgent : IHostableAgent
{
var subscriptions = BindSubscriptionsForAgentType<TAgent>(type);
foreach (var subscription in subscriptions)

View File

@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// App.cs
// AgentsApp.cs
using Microsoft.AutoGen.Contracts.Python;
using Microsoft.Extensions.DependencyInjection;
@@ -18,13 +18,13 @@ public class AgentsAppBuilder
this.builder = baseBuilder ?? new HostApplicationBuilder();
}
public void AddAgent<TAgent>(string name, bool registerDefaultTopics = true) where TAgent : IHostableAgent
public void AddAgent<TAgent>(string name, bool skipClassSubscriptions = false, bool skipDirectMessageSubscription = false) where TAgent : IHostableAgent
{
this.AgentTypeRegistrations.Add(app => app.AgentRuntime.RegisterAgentTypeAsync<TAgent>(name, app.Services));
if (registerDefaultTopics)
{
//TODO: this.AgentTypeRegistrations.Add(app => app.AgentRuntime.RegisterDefaultTopicsAsync<TAgent>(name));
}
this.AgentTypeRegistrations.Add(async app => {
var agentType = await app.AgentRuntime.RegisterAgentTypeAsync<TAgent>(name, app.Services);
await app.AgentRuntime.RegisterImplicitAgentSubscriptionsAsync<TAgent>(name, skipClassSubscriptions, skipDirectMessageSubscription);
return agentType;
});
}
public async ValueTask<AgentsApp> BuildAsync()