Skip to content

Commit

Permalink
Adds AgentHost project (to be containerized), which will be used as a…
Browse files Browse the repository at this point in the history
… container from the hello sample.
  • Loading branch information
kostapetan committed Nov 14, 2024
1 parent 4073dd4 commit 40cf2ca
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 0 deletions.
24 changes: 24 additions & 0 deletions dotnet/AutoGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.ServiceDe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Agents.Tests", "test\Microsoft.AutoGen.Agents.Tests\Microsoft.AutoGen.Agents.Tests.csproj", "{394FDAF8-74F9-4977-94A5-3371737EB774}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hello-distributed", "Hello-distributed", "{80A6C47B-0567-49F6-843A-667B96FA4BB4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppHost", "samples\Hello-distributed\AppHost\AppHost.csproj", "{10C07AB6-45FE-4183-A6C6-D0656DB0F4BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backend", "samples\Hello-distributed\Backend\Backend.csproj", "{55D4813C-FD74-4957-8950-174EF6765A57}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.AgentHost", "src\Microsoft.AutoGen\AgentHost\Microsoft.AutoGen.AgentHost.csproj", "{FEA16F7A-9CFB-475D-9B96-0F498D5415E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -342,6 +350,18 @@ Global
{394FDAF8-74F9-4977-94A5-3371737EB774}.Debug|Any CPU.Build.0 = Debug|Any CPU
{394FDAF8-74F9-4977-94A5-3371737EB774}.Release|Any CPU.ActiveCfg = Release|Any CPU
{394FDAF8-74F9-4977-94A5-3371737EB774}.Release|Any CPU.Build.0 = Release|Any CPU
{10C07AB6-45FE-4183-A6C6-D0656DB0F4BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10C07AB6-45FE-4183-A6C6-D0656DB0F4BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10C07AB6-45FE-4183-A6C6-D0656DB0F4BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10C07AB6-45FE-4183-A6C6-D0656DB0F4BF}.Release|Any CPU.Build.0 = Release|Any CPU
{55D4813C-FD74-4957-8950-174EF6765A57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{55D4813C-FD74-4957-8950-174EF6765A57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55D4813C-FD74-4957-8950-174EF6765A57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{55D4813C-FD74-4957-8950-174EF6765A57}.Release|Any CPU.Build.0 = Release|Any CPU
{FEA16F7A-9CFB-475D-9B96-0F498D5415E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEA16F7A-9CFB-475D-9B96-0F498D5415E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEA16F7A-9CFB-475D-9B96-0F498D5415E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEA16F7A-9CFB-475D-9B96-0F498D5415E2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -402,6 +422,10 @@ Global
{64EF61E7-00A6-4E5E-9808-62E10993A0E5} = {7EB336C2-7C0A-4BC8-80C6-A3173AB8DC45}
{65059914-5527-4A00-9308-9FAF23D5E85A} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{394FDAF8-74F9-4977-94A5-3371737EB774} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{80A6C47B-0567-49F6-843A-667B96FA4BB4} = {686480D7-8FEC-4ED3-9C5D-CEBE1057A7ED}
{10C07AB6-45FE-4183-A6C6-D0656DB0F4BF} = {80A6C47B-0567-49F6-843A-667B96FA4BB4}
{55D4813C-FD74-4957-8950-174EF6765A57} = {80A6C47B-0567-49F6-843A-667B96FA4BB4}
{FEA16F7A-9CFB-475D-9B96-0F498D5415E2} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B}
Expand Down
23 changes: 23 additions & 0 deletions dotnet/samples/Hello-distributed/AppHost/AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>e8874200-80ab-41e3-bb56-b5bb93974eea</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting.Azure.ApplicationInsights" />
<PackageReference Include="Aspire.Hosting.Azure.CognitiveServices" />
<PackageReference Include="Aspire.Hosting.Orleans" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Backend\Backend.csproj" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions dotnet/samples/Hello-distributed/AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Program.cs

var builder = DistributedApplication.CreateBuilder(args);

builder.AddAzureProvisioning();

var agentHost = builder.AddContainer("agent-host", "autogen-host");
var agentHostHttps = agentHost.GetEndpoint("https");

builder.AddProject<Projects.Backend>("backend")
.WithEnvironment("AGENT_HOST", $"{agentHostHttps.Property(EndpointProperty.Url)}")
.WithEnvironment("OpenAI__Key", builder.Configuration["OpenAI:Key"])
.WithEnvironment("OpenAI__Endpoint", builder.Configuration["OpenAI:Endpoint"]);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
51 changes: 51 additions & 0 deletions dotnet/samples/Hello-distributed/Backend/Agents/HelloAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// HelloAgent.cs

using Microsoft.AutoGen.Abstractions;
using Microsoft.AutoGen.Agents;

namespace Backend.Agents;

[TopicSubscription("HelloAgents")]
public class HelloAgent(
IAgentRuntime context,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : AgentBase(
context,
typeRegistry),
ISayHello,
IHandleConsole,
IHandle<AppNewMessageReceived>,
IHandle<AppConversationClosed>
{
public async Task Handle(AppNewMessageReceived item)
{
var response = await SayHello(item.Message).ConfigureAwait(false);
var evt = new Output { Message = response };
await PublishMessageAsync(evt).ConfigureAwait(false);
var goodbye = new AppConversationClosed
{
UserId = AgentId.Key,
UserMessage = "Goodbye"
};
await PublishMessageAsync(goodbye).ConfigureAwait(false);
}
public async Task Handle(AppConversationClosed item)
{
var goodbye = $"********************* {item.UserId} said {item.UserMessage} ************************";
var evt = new AppOutput
{
Message = goodbye
};
await PublishMessageAsync(evt).ConfigureAwait(false);
}

public async Task<string> SayHello(string ask)
{
var response = $"\n\n\n\n***************Hello {ask}**********************\n\n\n\n";
return response;
}
}
public interface ISayHello
{
public Task<string> SayHello(string ask);
}
34 changes: 34 additions & 0 deletions dotnet/samples/Hello-distributed/Backend/Backend.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk.Web">


<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Microsoft.SemanticKernel" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Qdrant" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Memory" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Microsoft.Extensions.Azure" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Google.Protobuf" />
<PackageReference Include="Grpc.Tools" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\SemanticKernel\Microsoft.AutoGen.Extensions.SemanticKernel.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\ServiceDefaults\Microsoft.AutoGen.ServiceDefaults.csproj" />
</ItemGroup>

<ItemGroup>
<Protobuf Include=".\Protos\messages.proto" Link="Protos\messages.proto" />
</ItemGroup>


</Project>
38 changes: 38 additions & 0 deletions dotnet/samples/Hello-distributed/Backend/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Program.cs

using Backend.Agents;
using Microsoft.AutoGen.Agents;
using Microsoft.AutoGen.Extensions.SemanticKernel;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
builder.ConfigureSemanticKernel();

builder.Services.AddHttpClient();
builder.Services.AddControllers();
builder.Services.AddSwaggerGen();

builder.AddAgentWorker(builder.Configuration["AGENT_HOST"]!)
.AddAgent<HelloAgent>(nameof(HelloAgent))
;

builder.Services.AddSingleton<AgentWorker>();

var app = builder.Build();

app.MapDefaultEndpoints();
app.UseRouting()
.UseEndpoints(endpoints =>
{

}); ;

app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"DevTeam.Backend": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:50672;http://localhost:50674"
}
}
}
17 changes: 17 additions & 0 deletions dotnet/samples/Hello-distributed/Backend/Protos/messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";

package helloWorld;

option csharp_namespace = "Backend";

message AppOutput {
string message = 1;
}
message AppNewMessageReceived {
string message = 1;
}
message AppConversationClosed {
string user_id = 1;
string user_message = 2;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
1 change: 1 addition & 0 deletions dotnet/samples/Hello-distributed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hello world sample using the packaged agent host
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ContainerRepository>autogen-host</ContainerRepository>
<EnableSdkContainerSupport>true</EnableSdkContainerSupport>
<ImplicitUsings>enable</ImplicitUsings>
<!--orleans doesn't have strong name package-->
<NoWarn>$(NoWarn);CS8002</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../../src/Microsoft.AutoGen/Agents/Microsoft.AutoGen.Agents.csproj" />
<ProjectReference Include="../../../src/Microsoft.AutoGen/Extensions/ServiceDefaults/Microsoft.AutoGen.ServiceDefaults.csproj" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions dotnet/src/Microsoft.AutoGen/AgentHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Program.cs

using Microsoft.AutoGen.Agents;
var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
builder.AddLocalAgentService();

var app = builder.Build();

app.MapDefaultEndpoints();
app.MapAgentService();

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"DevTeam.AgentHost": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:50670;http://localhost:50673"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

0 comments on commit 40cf2ca

Please sign in to comment.