A programming framework for agentic AI
Clean up the Hello sample, support Aspire 9.0, & fix shutdown in the sample (#4037)
Reuben Bond7d1857dae621
diff --git a/dotnet/samples/Hello/Backend/Backend.csproj b/dotnet/samples/Hello/Backend/Backend.csprojindex 60097b5d3..2f5a02ee5 100644--- a/dotnet/samples/Hello/Backend/Backend.csproj+++ b/dotnet/samples/Hello/Backend/Backend.csproj@@ -1,14 +1,16 @@-<Project Sdk="Microsoft.NET.Sdk">- <ItemGroup>- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />- </ItemGroup>- <ItemGroup>- <PackageReference Include="Microsoft.Extensions.Hosting" />- </ItemGroup>+<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable></PropertyGroup>++ <ItemGroup>+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />+ </ItemGroup>++ <ItemGroup>+ <PackageReference Include="Microsoft.Extensions.Hosting" />+ </ItemGroup></Project>diff --git a/dotnet/samples/Hello/Backend/Program.cs b/dotnet/samples/Hello/Backend/Program.csindex 9f55daf69..7abdb205a 100644--- a/dotnet/samples/Hello/Backend/Program.cs+++ b/dotnet/samples/Hello/Backend/Program.cs@@ -1,7 +1,5 @@// Copyright (c) Microsoft Corporation. All rights reserved.// Program.cs-using Microsoft.Extensions.Hosting;-var app = await Microsoft.AutoGen.Runtime.Host.StartAsync(local: true);await app.WaitForShutdownAsync();diff --git a/dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj b/dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csprojindex 3ecd30dee..88d23268c 100644--- a/dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj+++ b/dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj@@ -1,5 +1,4 @@<Project Sdk="Microsoft.NET.Sdk">-<PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework>@@ -10,12 +9,12 @@</PropertyGroup><ItemGroup>- <PackageReference Include="Aspire.Hosting.AppHost"/>- <PackageReference Include="Aspire.Hosting"/>+ <PackageReference Include="Aspire.Hosting.AppHost" />+ <PackageReference Include="Aspire.Hosting" /></ItemGroup>+<ItemGroup><ProjectReference Include="..\Backend\Backend.csproj" /><ProjectReference Include="..\HelloAgent\HelloAgent.csproj" /></ItemGroup>-</Project>diff --git a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.csindex ebde6d6d2..f7939da7d 100644--- a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs+++ b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs@@ -4,7 +4,6 @@using Microsoft.AutoGen.Abstractions;using Microsoft.AutoGen.Agents;using Microsoft.Extensions.AI;-using Microsoft.Extensions.DependencyInjection;namespace Hello;[TopicSubscription("HelloAgents")]diff --git a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csprojindex 73f1891b3..86bccb13b 100644--- a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj+++ b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj@@ -1,16 +1,4 @@-<Project Sdk="Microsoft.NET.Sdk">-- <ItemGroup>- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Abstractions\Microsoft.AutoGen.Abstractions.csproj" />- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\AIModelClientHostingExtensions\AIModelClientHostingExtensions.csproj" />- </ItemGroup>-- <ItemGroup>- <PackageReference Include="Microsoft.Extensions.Hosting" />- </ItemGroup>-+<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework>@@ -18,4 +6,14 @@<Nullable>enable</Nullable></PropertyGroup>+ <ItemGroup>+ <PackageReference Include="Microsoft.Extensions.Hosting" />+ </ItemGroup>++ <ItemGroup>+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Abstractions\Microsoft.AutoGen.Abstractions.csproj" />+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\AIModelClientHostingExtensions\AIModelClientHostingExtensions.csproj" />+ </ItemGroup></Project>diff --git a/dotnet/samples/Hello/HelloAIAgents/Program.cs b/dotnet/samples/Hello/HelloAIAgents/Program.csindex 9d1964bfd..ebede82bb 100644--- a/dotnet/samples/Hello/HelloAIAgents/Program.cs+++ b/dotnet/samples/Hello/HelloAIAgents/Program.cs@@ -2,11 +2,8 @@// Program.csusing Hello;-using Microsoft.AspNetCore.Builder;using Microsoft.AutoGen.Abstractions;using Microsoft.AutoGen.Agents;-using Microsoft.Extensions.DependencyInjection;-using Microsoft.Extensions.Hosting;// send a message to the agentvar builder = WebApplication.CreateBuilder();diff --git a/dotnet/samples/Hello/HelloAgent/HelloAgent.csproj b/dotnet/samples/Hello/HelloAgent/HelloAgent.csprojindex eb2ba96d6..8799eb727 100644--- a/dotnet/samples/Hello/HelloAgent/HelloAgent.csproj+++ b/dotnet/samples/Hello/HelloAgent/HelloAgent.csproj@@ -1,16 +1,4 @@-<Project Sdk="Microsoft.NET.Sdk">-- <ItemGroup>- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Abstractions\Microsoft.AutoGen.Abstractions.csproj" />- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />- </ItemGroup>-- <ItemGroup>- <PackageReference Include="Microsoft.Extensions.Hosting" />- <PackageReference Include="Aspire.Hosting.AppHost" />- </ItemGroup>-+<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework>@@ -18,4 +6,14 @@<Nullable>enable</Nullable></PropertyGroup>+ <ItemGroup>+ <PackageReference Include="Microsoft.Extensions.Hosting" />+ <PackageReference Include="Aspire.Hosting.AppHost" />+ </ItemGroup>++ <ItemGroup>+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Abstractions\Microsoft.AutoGen.Abstractions.csproj" />+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />+ </ItemGroup></Project>diff --git a/dotnet/samples/Hello/HelloAgent/Program.cs b/dotnet/samples/Hello/HelloAgent/Program.csindex fbe5d2f6d..02ad838de 100644--- a/dotnet/samples/Hello/HelloAgent/Program.cs+++ b/dotnet/samples/Hello/HelloAgent/Program.cs@@ -3,8 +3,6 @@using Microsoft.AutoGen.Abstractions;using Microsoft.AutoGen.Agents;-using Microsoft.Extensions.DependencyInjection;-using Microsoft.Extensions.Hosting;// step 1: create in-memory agent runtime@@ -27,7 +25,8 @@ namespace Hello[TopicSubscription("HelloAgents")]public class HelloAgent(IAgentContext context,- [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : AgentBase(+ [FromKeyedServices("EventTypes")] EventTypes typeRegistry,+ IHostApplicationLifetime hostApplicationLifetime) : AgentBase(context,typeRegistry),ISayHello,@@ -58,11 +57,11 @@ namespace HelloMessage = goodbye}.ToCloudEvent(this.AgentId.Key);await PublishEvent(evt).ConfigureAwait(false);- //sleep- await Task.Delay(10000).ConfigureAwait(false);- await AgentsApp.ShutdownAsync().ConfigureAwait(false);+ // Signal shutdown.+ hostApplicationLifetime.StopApplication();}+public async Task<string> SayHello(string ask){var response = $"\n\n\n\n***************Hello {ask}**********************\n\n\n\n";diff --git a/dotnet/samples/Hello/HelloAgentState/HelloAgentState.csproj b/dotnet/samples/Hello/HelloAgentState/HelloAgentState.csprojindex eb2ba96d6..8799eb727 100644--- a/dotnet/samples/Hello/HelloAgentState/HelloAgentState.csproj+++ b/dotnet/samples/Hello/HelloAgentState/HelloAgentState.csproj@@ -1,16 +1,4 @@-<Project Sdk="Microsoft.NET.Sdk">-- <ItemGroup>- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Abstractions\Microsoft.AutoGen.Abstractions.csproj" />- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />- <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />- </ItemGroup>-- <ItemGroup>- <PackageReference Include="Microsoft.Extensions.Hosting" />- <PackageReference Include="Aspire.Hosting.AppHost" />- </ItemGroup>-+<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework>@@ -18,4 +6,14 @@<Nullable>enable</Nullable></PropertyGroup>+ <ItemGroup>+ <PackageReference Include="Microsoft.Extensions.Hosting" />+ <PackageReference Include="Aspire.Hosting.AppHost" />+ </ItemGroup>++ <ItemGroup>+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Abstractions\Microsoft.AutoGen.Abstractions.csproj" />+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />+ <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Runtime\Microsoft.AutoGen.Runtime.csproj" />+ </ItemGroup></Project>diff --git a/dotnet/samples/Hello/HelloAgentState/Program.cs b/dotnet/samples/Hello/HelloAgentState/Program.csindex 66b888d6c..c1e00e4d6 100644--- a/dotnet/samples/Hello/HelloAgentState/Program.cs+++ b/dotnet/samples/Hello/HelloAgentState/Program.cs@@ -3,8 +3,6 @@using Microsoft.AutoGen.Abstractions;using Microsoft.AutoGen.Agents;-using Microsoft.Extensions.DependencyInjection;-using Microsoft.Extensions.Hosting;// send a message to the agentvar app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived