From 2ba7732220039e047e5aad6e222926dfdecd367b Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Mon, 27 Jan 2025 14:43:41 -0500 Subject: [PATCH] add subscriptions to host builder --- .../Core/PythonEquiv/AgentRuntimeExtensions.cs | 2 +- .../Core/PythonEquiv/AgentsApp.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentRuntimeExtensions.cs b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentRuntimeExtensions.cs index caee18a43..4b3858c78 100644 --- a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentRuntimeExtensions.cs +++ b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentRuntimeExtensions.cs @@ -69,7 +69,7 @@ public static class AgentRuntimeExtensions return subscriptions.ToArray(); } - public static async ValueTask RegisterImplicitAgentSubscriptionsAsync(this IAgentRuntime runtime, AgentType type) where TAgent : IHostableAgent + public static async ValueTask RegisterImplicitAgentSubscriptionsAsync(this IAgentRuntime runtime, AgentType type, bool skipClassSubscriptions = false, bool skipDirectMessageSubscription = false) where TAgent : IHostableAgent { var subscriptions = BindSubscriptionsForAgentType(type); foreach (var subscription in subscriptions) diff --git a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentsApp.cs b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentsApp.cs index 4c238078a..1a383e3df 100644 --- a/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentsApp.cs +++ b/dotnet/src/Microsoft.AutoGen/Core/PythonEquiv/AgentsApp.cs @@ -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(string name, bool registerDefaultTopics = true) where TAgent : IHostableAgent + public void AddAgent(string name, bool skipClassSubscriptions = false, bool skipDirectMessageSubscription = false) where TAgent : IHostableAgent { - this.AgentTypeRegistrations.Add(app => app.AgentRuntime.RegisterAgentTypeAsync(name, app.Services)); - if (registerDefaultTopics) - { - //TODO: this.AgentTypeRegistrations.Add(app => app.AgentRuntime.RegisterDefaultTopicsAsync(name)); - } + this.AgentTypeRegistrations.Add(async app => { + var agentType = await app.AgentRuntime.RegisterAgentTypeAsync(name, app.Services); + await app.AgentRuntime.RegisterImplicitAgentSubscriptionsAsync(name, skipClassSubscriptions, skipDirectMessageSubscription); + return agentType; + }); } public async ValueTask BuildAsync()