Skip to content

A programming framework for agentic AI

Rysweet 4702 add microsoftautogenagenthost package (#4703)

Ryan Sweet0bfc0652ae30
diff --git a/dotnet/AutoGen.sln b/dotnet/AutoGen.sln
index 98548d512..d0707a89a 100644
--- a/dotnet/AutoGen.sln
+++ b/dotnet/AutoGen.sln
@@ -112,8 +112,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevTeam.Shared", "samples\d
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hello", "Hello", "{7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backend", "samples\Hello\Backend\Backend.csproj", "{C428C6E5-B0E5-4DA6-B0F7-43013D2ECE69}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hello.AppHost", "samples\Hello\Hello.AppHost\Hello.AppHost.csproj", "{09A373A0-8169-409F-8C37-3FBC1654B122}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloAIAgents", "samples\Hello\HelloAIAgents\HelloAIAgents.csproj", "{A20B9894-F352-4338-872A-F215A241D43D}"
@@ -142,6 +140,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Runtime.G
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Agents", "src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj", "{3892C83E-7F5D-41DF-A88C-4854EAD38856}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Autogen.AgentHost", "src\Microsoft.AutoGen\AgentHost\Microsoft.Autogen.AgentHost.csproj", "{4CB42139-DEE4-40B9-AA81-1E4CCAA2F338}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -316,10 +316,6 @@ Global
{01F5D7C3-41EB-409C-9B77-A945C07FA7E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01F5D7C3-41EB-409C-9B77-A945C07FA7E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01F5D7C3-41EB-409C-9B77-A945C07FA7E8}.Release|Any CPU.Build.0 = Release|Any CPU
- {C428C6E5-B0E5-4DA6-B0F7-43013D2ECE69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {C428C6E5-B0E5-4DA6-B0F7-43013D2ECE69}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {C428C6E5-B0E5-4DA6-B0F7-43013D2ECE69}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {C428C6E5-B0E5-4DA6-B0F7-43013D2ECE69}.Release|Any CPU.Build.0 = Release|Any CPU
{09A373A0-8169-409F-8C37-3FBC1654B122}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09A373A0-8169-409F-8C37-3FBC1654B122}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09A373A0-8169-409F-8C37-3FBC1654B122}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -372,6 +368,10 @@ Global
{3892C83E-7F5D-41DF-A88C-4854EAD38856}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3892C83E-7F5D-41DF-A88C-4854EAD38856}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3892C83E-7F5D-41DF-A88C-4854EAD38856}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4CB42139-DEE4-40B9-AA81-1E4CCAA2F338}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4CB42139-DEE4-40B9-AA81-1E4CCAA2F338}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4CB42139-DEE4-40B9-AA81-1E4CCAA2F338}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4CB42139-DEE4-40B9-AA81-1E4CCAA2F338}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -423,7 +423,6 @@ Global
{EDA3EF83-FC7F-4BCF-945D-B893620EE4B1} = {05B9C173-6441-4DCA-9AC4-E897EF75F331}
{01F5D7C3-41EB-409C-9B77-A945C07FA7E8} = {05B9C173-6441-4DCA-9AC4-E897EF75F331}
{7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45} = {686480D7-8FEC-4ED3-9C5D-CEBE1057A7ED}
- {C428C6E5-B0E5-4DA6-B0F7-43013D2ECE69} = {7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45}
{09A373A0-8169-409F-8C37-3FBC1654B122} = {7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45}
{A20B9894-F352-4338-872A-F215A241D43D} = {7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45}
{8F7560CF-EEBB-4333-A69F-838CA40FD85D} = {7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45}
@@ -437,6 +436,7 @@ Global
{9653676C-147D-4CBE-BB53-A30FD3634F4C} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{8457B68C-CC86-4A3F-8559-C1AE199EC366} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{3892C83E-7F5D-41DF-A88C-4854EAD38856} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
+ {4CB42139-DEE4-40B9-AA81-1E4CCAA2F338} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B}
diff --git a/dotnet/samples/Hello/Backend/Backend.csproj b/dotnet/samples/Hello/Backend/Backend.csproj
deleted file mode 100644
index f2432eaad..000000000
--- a/dotnet/samples/Hello/Backend/Backend.csproj
+++ /dev/null
@@ -1,15 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
- <ItemGroup>
- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime.Grpc\Microsoft.AutoGen.Runtime.Grpc.csproj" />
- </ItemGroup>
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <TargetFramework>net8.0</TargetFramework>
- <ImplicitUsings>enable</ImplicitUsings>
- <Nullable>enable</Nullable>
- </PropertyGroup>
-
- <ItemGroup>
- <PackageReference Include="Microsoft.Extensions.Hosting" />
- </ItemGroup>
-</Project>
diff --git a/dotnet/samples/Hello/Backend/README.md b/dotnet/samples/Hello/Backend/README.md
deleted file mode 100644
index 45c7ddee1..000000000
--- a/dotnet/samples/Hello/Backend/README.md
+++ /dev/null
@@ -1,12 +0,0 @@
-# Backend Example
-
-This example demonstrates how to create a simple backend service for the agent runtime using ASP.NET Core.
-
-To Run it, simply run the following command in the terminal:
-
-```bash
-dotnet run
-```
-
-Or you can run it using Visual Studio Code by pressing `F5`.
-
diff --git a/dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj b/dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj
index 370d13fb3..aa714b1b7 100644
--- a/dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj
+++ b/dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj
@@ -18,7 +18,7 @@
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\Backend\Backend.csproj" />
+ <ProjectReference Include="../../../src/Microsoft.AutoGen/AgentHost/Microsoft.Autogen.AgentHost.csproj" />
<ProjectReference Include="..\HelloAgent\HelloAgent.csproj" />
</ItemGroup>
</Project>
diff --git a/dotnet/samples/Hello/Hello.AppHost/Program.cs b/dotnet/samples/Hello/Hello.AppHost/Program.cs
index f261f1eae..8230a5b7c 100644
--- a/dotnet/samples/Hello/Hello.AppHost/Program.cs
+++ b/dotnet/samples/Hello/Hello.AppHost/Program.cs
@@ -4,7 +4,7 @@
using Microsoft.Extensions.Hosting;
var builder = DistributedApplication.CreateBuilder(args);
-var backend = builder.AddProject<Projects.Backend>("backend").WithExternalHttpEndpoints();
+var backend = builder.AddProject<Projects.Microsoft_Autogen_AgentHost>("backend").WithExternalHttpEndpoints();
var client = builder.AddProject<Projects.HelloAgent>("HelloAgentsDotNET")
.WithReference(backend)
.WithEnvironment("AGENT_HOST", backend.GetEndpoint("https"))
diff --git a/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Services/Host.cs b/dotnet/src/Microsoft.AutoGen/AgentHost/Host.cs
similarity index 95%
rename from dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Services/Host.cs
rename to dotnet/src/Microsoft.AutoGen/AgentHost/Host.cs
index c9662da34..1ecf42c79 100644
--- a/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Services/Host.cs
+++ b/dotnet/src/Microsoft.AutoGen/AgentHost/Host.cs
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Host.cs
-
+using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
diff --git a/dotnet/src/Microsoft.AutoGen/AgentHost/Microsoft.Autogen.AgentHost.csproj b/dotnet/src/Microsoft.AutoGen/AgentHost/Microsoft.Autogen.AgentHost.csproj
new file mode 100644
index 000000000..33b051ad9
--- /dev/null
+++ b/dotnet/src/Microsoft.AutoGen/AgentHost/Microsoft.Autogen.AgentHost.csproj
@@ -0,0 +1,21 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+ <PropertyGroup>
+ <TargetFramework>net8.0</TargetFramework>
+ <Nullable>enable</Nullable>
+ <ContainerRepository>autogen-host</ContainerRepository>
+ <ContainerFamily>alpine</ContainerFamily>
+ <EnableSdkContainerSupport>true</EnableSdkContainerSupport>
+ </PropertyGroup>
+ <ItemGroup>
+ <ContainerEnvironmentVariable Include="ASPNETCORE_HTTP_PORTS" Value="5001" />
+ <ContainerPort Include="5001" Type="tcp" />
+ </ItemGroup>
+ <ItemGroup>
+ <PackageReference Include="Microsoft.Extensions.Hosting" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Runtime.Grpc\Microsoft.AutoGen.Runtime.Grpc.csproj" />
+ <ProjectReference Include="..\Extensions\Aspire\Microsoft.AutoGen.Extensions.Aspire.csproj" />
+ </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/dotnet/samples/Hello/Backend/Program.cs b/dotnet/src/Microsoft.AutoGen/AgentHost/Program.cs
similarity index 66%
rename from dotnet/samples/Hello/Backend/Program.cs
rename to dotnet/src/Microsoft.AutoGen/AgentHost/Program.cs
index 9cdda71b3..024ca0d43 100644
--- a/dotnet/samples/Hello/Backend/Program.cs
+++ b/dotnet/src/Microsoft.AutoGen/AgentHost/Program.cs
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Program.cs
+using Microsoft.Extensions.Hosting;
-var app = await Microsoft.AutoGen.Runtime.Grpc.Host.StartAsync(local: false, useGrpc: true);
+var app = await Microsoft.AutoGen.Runtime.Grpc.Host.StartAsync(local: false, useGrpc: true).ConfigureAwait(false);
await app.WaitForShutdownAsync();
diff --git a/dotnet/samples/Hello/Backend/Properties/launchSettings.json b/dotnet/src/Microsoft.AutoGen/AgentHost/Properties/launchSettings.json
similarity index 55%
rename from dotnet/samples/Hello/Backend/Properties/launchSettings.json
rename to dotnet/src/Microsoft.AutoGen/AgentHost/Properties/launchSettings.json
index db9c6bf2c..cfddee319 100644
--- a/dotnet/samples/Hello/Backend/Properties/launchSettings.json
+++ b/dotnet/src/Microsoft.AutoGen/AgentHost/Properties/launchSettings.json
@@ -1,12 +1,13 @@
{
"profiles": {
- "Backend": {
+ "AgentHost": {
"commandName": "Project",
+ "dotnetRunMessages": true,
"launchBrowser": true,
+ "applicationUrl": "https://localhost:50670;http://localhost:50673",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
- },
- "applicationUrl": "https://localhost:53071;http://localhost:53072"
+ }
}
}
-}
\ No newline at end of file
+}
diff --git a/dotnet/samples/Hello/Backend/appsettings.json b/dotnet/src/Microsoft.AutoGen/AgentHost/appsettings.json
similarity index 100%
rename from dotnet/samples/Hello/Backend/appsettings.json
rename to dotnet/src/Microsoft.AutoGen/AgentHost/appsettings.json
diff --git a/dotnet/src/Microsoft.AutoGen/Core/Agent.cs b/dotnet/src/Microsoft.AutoGen/Core/Agent.cs
index f7a2ac8f7..f2cb91fed 100644
--- a/dotnet/src/Microsoft.AutoGen/Core/Agent.cs
+++ b/dotnet/src/Microsoft.AutoGen/Core/Agent.cs
@@ -14,7 +14,7 @@ using Microsoft.Extensions.Logging;
namespace Microsoft.AutoGen.Core;
-public abstract class Agent : IDisposable, IHandle
+public abstract class Agent : IHandle
{
public static readonly ActivitySource s_source = new("AutoGen.Agent");
public AgentId AgentId => _runtime.AgentId;
@@ -344,9 +344,4 @@ public abstract class Agent : IDisposable, IHandle
{
await PublishEventAsync(evt.ToCloudEvent(topic), cancellationToken).ConfigureAwait(false);
}
-
- public void Dispose()
- {
- throw new NotImplementedException();
- }
}
diff --git a/dotnet/src/Microsoft.AutoGen/Extensions/Aspire/AspireHostingExtensions.cs b/dotnet/src/Microsoft.AutoGen/Extensions/Aspire/AspireHostingExtensions.cs
index 0e6781d74..c4588cd42 100644
--- a/dotnet/src/Microsoft.AutoGen/Extensions/Aspire/AspireHostingExtensions.cs
+++ b/dotnet/src/Microsoft.AutoGen/Extensions/Aspire/AspireHostingExtensions.cs
@@ -17,7 +17,7 @@ namespace Microsoft.Extensions.Hosting;
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
public static class AspireHostingExtensions
{
- public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder)
+ public static WebApplicationBuilder AddServiceDefaults(this WebApplicationBuilder builder)
{
builder.ConfigureOpenTelemetry();
diff --git a/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Microsoft.AutoGen.Runtime.Grpc.csproj b/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Microsoft.AutoGen.Runtime.Grpc.csproj
index 0d81a1e27..27474cef7 100644
--- a/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Microsoft.AutoGen.Runtime.Grpc.csproj
+++ b/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Microsoft.AutoGen.Runtime.Grpc.csproj
@@ -6,7 +6,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Contracts\Microsoft.AutoGen.Contracts.csproj" />
- <ProjectReference Include="..\Extensions\Aspire\Microsoft.AutoGen.Extensions.Aspire.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Orleans.Reminders" />
diff --git a/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/AgentWorkerHostingExtensions.cs b/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Services/AgentWorkerHostingExtensions.cs
similarity index 99%
rename from dotnet/src/Microsoft.AutoGen/Runtime.Grpc/AgentWorkerHostingExtensions.cs
rename to dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Services/AgentWorkerHostingExtensions.cs
index 4d92ebe22..bd2ecfa9a 100644
--- a/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/AgentWorkerHostingExtensions.cs
+++ b/dotnet/src/Microsoft.AutoGen/Runtime.Grpc/Services/AgentWorkerHostingExtensions.cs
@@ -8,7 +8,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
namespace Microsoft.AutoGen.Runtime.Grpc;
-
public static class AgentWorkerHostingExtensions
{
public static WebApplicationBuilder AddAgentService(this WebApplicationBuilder builder)