Skip to content

Commit fefaf44

Browse files
committed
add cert config to agenthost
1 parent 03ad20a commit fefaf44

File tree

7 files changed

+27
-16
lines changed

7 files changed

+27
-16
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,5 @@ notebook/result.png
193193
samples/apps/autogen-studio/autogenstudio/models/test/
194194

195195
notebook/coding
196+
197+
certs/**

dotnet/Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<PackageVersion Include="Grpc.Tools" Version="2.67.0" />
3939
<PackageVersion Include="Grpc.Net.Client" Version="2.65.0" />
4040
<PackageVersion Include="Google.Protobuf" Version="3.28.2" />
41+
<PackageVersion Include="Grpc.AspNetCore.Server.Reflection" Version="2.66.0" />
4142
<PackageVersion Include="Microsoft.AspNetCore.App" Version="8.0.4" />
4243
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8" />
4344
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />

dotnet/samples/Hello-distributed/AppHost/Program.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
var builder = DistributedApplication.CreateBuilder(args);
55

66
var agentHost = builder.AddContainer("agent-host", "autogen-host")
7-
.WithEnvironment("ASPNETCORE_URLS", "http://+:5001")
8-
.WithHttpEndpoint(targetPort: 5001);
7+
.WithEnvironment("ASPNETCORE_URLS", "https://+;http://+")
8+
.WithEnvironment("ASPNETCORE_HTTPS_PORTS", "5001")
9+
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Password", "mysecurepass")
10+
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Path", "/https/devcert.pfx")
11+
.WithBindMount("./certs", "/https/",true)
12+
.WithHttpsEndpoint(targetPort: 5001);
913

10-
var agentHostHttp = agentHost.GetEndpoint("http");
14+
var agentHostHttps = agentHost.GetEndpoint("https");
1115

1216
builder.AddProject<Projects.Backend>("backend")
13-
.WithEnvironment("AGENT_HOST", $"{agentHostHttp.Property(EndpointProperty.Url)}")
17+
.WithEnvironment("AGENT_HOST", $"{agentHostHttps.Property(EndpointProperty.Url)}")
1418
.WithEnvironment("OpenAI__Key", builder.Configuration["OpenAI:Key"])
1519
.WithEnvironment("OpenAI__Endpoint", builder.Configuration["OpenAI:Endpoint"])
1620
.WaitFor(agentHost);
+11-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
# Hello world sample using the packaged agent host
1+
# Hello world sample using the packaged agent host
2+
3+
To run this sample, we'll need to generate self-signed certificate, as the gRPC server on the agenthost is configured to use HTTPS.
4+
5+
Run the following commands from `\dotnet\samples\Hello-distributed\AppHost`
6+
7+
```bash
8+
mkdir certs
9+
dotnet dev-certs https -ep ./certs/devcert.pfx -p mysecurepass
10+
dotnet dev-certs https --trust
11+
```

dotnet/src/Microsoft.AutoGen/Agents/Services/AgentWorkerHostingExtensions.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@ public static class AgentWorkerHostingExtensions
1515
{
1616
public static WebApplicationBuilder AddAgentService(this WebApplicationBuilder builder, bool local = false, bool useGrpc = true)
1717
{
18-
if (local)
19-
{
20-
//TODO: make configuration more flexible
2118
builder.WebHost.ConfigureKestrel(serverOptions =>
2219
{
23-
serverOptions.ListenLocalhost(5001, listenOptions =>
20+
serverOptions.ListenAnyIP(5001, listenOptions =>
2421
{
2522
listenOptions.Protocols = HttpProtocols.Http2;
23+
listenOptions.UseHttps();
2624
});
2725
});
2826
builder.AddOrleans(local);
29-
}
30-
else
31-
{
32-
builder.AddOrleans();
33-
}
3427

3528
builder.Services.TryAddSingleton(DistributedContextPropagator.Current);
3629

dotnet/src/Microsoft.AutoGen/Agents/Services/Grpc/GrpcAgentWorkerHostBuilderExtension.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static IHostApplicationBuilder AddGrpcAgentWorker(this IHostApplicationBu
2525
EnableMultipleHttp2Connections = true,
2626
KeepAlivePingDelay = TimeSpan.FromSeconds(20),
2727
KeepAlivePingTimeout = TimeSpan.FromSeconds(10),
28-
KeepAlivePingPolicy = HttpKeepAlivePingPolicy.WithActiveRequests
28+
KeepAlivePingPolicy = HttpKeepAlivePingPolicy.WithActiveRequests,
2929
};
3030

3131
var methodConfig = new MethodConfig

dotnet/src/Microsoft.AutoGen/Extensions/ServiceDefaults/Extensions.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati
6060
.WithTracing(tracing =>
6161
{
6262
tracing.AddAspNetCoreInstrumentation()
63-
//.AddGrpcClientInstrumentation()
63+
//.
64+
//Instrumentation()
6465
.AddHttpClientInstrumentation()
6566
.AddSource("Microsoft.Orleans.Application")
6667
.AddSource("AutoGen.Agent");

0 commit comments

Comments
 (0)