From 8b12b77f2fd778dcecc02560991f515169c5d5e3 Mon Sep 17 00:00:00 2001 From: Ryan Sweet Date: Tue, 8 Oct 2024 03:02:56 -0700 Subject: [PATCH] local client by default --- dotnet/src/Microsoft.AutoGen.Agents.Client/App.cs | 2 +- .../HostBuilderExtensions.cs | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/dotnet/src/Microsoft.AutoGen.Agents.Client/App.cs b/dotnet/src/Microsoft.AutoGen.Agents.Client/App.cs index c997d2ee9ac5..0d10bd2a0f25 100644 --- a/dotnet/src/Microsoft.AutoGen.Agents.Client/App.cs +++ b/dotnet/src/Microsoft.AutoGen.Agents.Client/App.cs @@ -7,7 +7,7 @@ public static class App public static async Task StartAsync(string name) where T : AgentBase { var clientBuilder = WebApplication.CreateBuilder(); - clientBuilder.AddLocalAgentWorker().AddAgent(name); + clientBuilder.AddAgentWorker().AddAgent(name); var clientApp = clientBuilder.Build(); await clientApp.StartAsync().ConfigureAwait(false); return clientApp; diff --git a/dotnet/src/Microsoft.AutoGen.Agents.Client/HostBuilderExtensions.cs b/dotnet/src/Microsoft.AutoGen.Agents.Client/HostBuilderExtensions.cs index 2db2030a9eb1..f00318688247 100644 --- a/dotnet/src/Microsoft.AutoGen.Agents.Client/HostBuilderExtensions.cs +++ b/dotnet/src/Microsoft.AutoGen.Agents.Client/HostBuilderExtensions.cs @@ -14,14 +14,8 @@ namespace Microsoft.AutoGen.Agents.Client; public static class HostBuilderExtensions { - public static AgentApplicationBuilder AddLocalAgentWorker(this IHostApplicationBuilder clientBuilder) - { - clientBuilder.Services.AddHostedService(); - clientBuilder.Services.AddSingleton(); - clientBuilder.AddAgentWorker("https://localhost:5001"); - return new AgentApplicationBuilder(clientBuilder); - } - public static AgentApplicationBuilder AddAgentWorker(this IHostApplicationBuilder builder, string agentServiceAddress) + private const string _defaultAgentServiceAddress = "https://localhost:5001"; + public static AgentApplicationBuilder AddAgentWorker(this IHostApplicationBuilder builder, string agentServiceAddress =_defaultAgentServiceAddress, bool local = false) { builder.Services.AddGrpcClient(options => { @@ -55,6 +49,7 @@ public static AgentApplicationBuilder AddAgentWorker(this IHostApplicationBuilde }); }); builder.Services.TryAddSingleton(DistributedContextPropagator.Current); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(sp => sp.GetRequiredService()); builder.Services.AddKeyedSingleton("EventTypes", (sp, key) =>