-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds AgentHost project (to be containerized), which will be used as a…
… container from the hello sample.
- Loading branch information
1 parent
4073dd4
commit 40cf2ca
Showing
15 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
8 changes: 8 additions & 0 deletions
8
dotnet/samples/Hello-distributed/AppHost/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
dotnet/samples/Hello-distributed/Backend/Agents/HelloAgent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
12 changes: 12 additions & 0 deletions
12
dotnet/samples/Hello-distributed/Backend/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
dotnet/samples/Hello-distributed/Backend/Protos/messages.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
dotnet/samples/Hello-distributed/Backend/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Hello world sample using the packaged agent host |
18 changes: 18 additions & 0 deletions
18
dotnet/src/Microsoft.AutoGen/AgentHost/Microsoft.AutoGen.AgentHost.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
12 changes: 12 additions & 0 deletions
12
dotnet/src/Microsoft.AutoGen/AgentHost/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
dotnet/src/Microsoft.AutoGen/AgentHost/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |