-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish implementation including initial manual testing
- Loading branch information
1 parent
72168b5
commit f87497b
Showing
13 changed files
with
223 additions
and
45 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,34 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Checker.cs | ||
|
||
using Microsoft.AutoGen.Contracts; | ||
using Microsoft.AutoGen.Core; | ||
using Microsoft.Extensions.Hosting; | ||
using TerminationF = System.Func<int, bool>; | ||
|
||
namespace GettingStartedGrpcSample; | ||
|
||
[TypeSubscription("default")] | ||
public class Checker( | ||
AgentId id, | ||
IAgentRuntime runtime, | ||
IHostApplicationLifetime hostApplicationLifetime, | ||
TerminationF runUntilFunc | ||
) : | ||
BaseAgent(id, runtime, "Modifier", null), | ||
IHandle<Events.CountUpdate> | ||
{ | ||
public async ValueTask HandleAsync(Events.CountUpdate item, MessageContext messageContext) | ||
{ | ||
if (!runUntilFunc(item.NewCount)) | ||
{ | ||
Console.WriteLine($"\nChecker:\n{item.NewCount} passed the check, continue."); | ||
await this.PublishMessageAsync(new Events.CountMessage { Content = item.NewCount }, new TopicId("default")); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"\nChecker:\n{item.NewCount} failed the check, stopping."); | ||
hostApplicationLifetime.StopApplication(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
dotnet/samples/GettingStartedGrpc/GettingStartedGrpc.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,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>getting_started</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.AutoGen\Contracts\Microsoft.AutoGen.Contracts.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.AutoGen\Core\Microsoft.AutoGen.Core.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.AutoGen\Core.Grpc\Microsoft.AutoGen.Core.Grpc.csproj" /> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup> | ||
<Protobuf Include="message.proto" GrpcServices="Client" Link="Protos\message.proto" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Grpc.Tools" PrivateAssets="All" /> | ||
</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,29 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Modifier.cs | ||
|
||
using Microsoft.AutoGen.Contracts; | ||
using Microsoft.AutoGen.Core; | ||
|
||
using ModifyF = System.Func<int, int>; | ||
|
||
namespace GettingStartedGrpcSample; | ||
|
||
[TypeSubscription("default")] | ||
public class Modifier( | ||
AgentId id, | ||
IAgentRuntime runtime, | ||
ModifyF modifyFunc | ||
) : | ||
BaseAgent(id, runtime, "Modifier", null), | ||
IHandle<Events.CountMessage> | ||
{ | ||
|
||
public async ValueTask HandleAsync(Events.CountMessage item, MessageContext messageContext) | ||
{ | ||
int newValue = modifyFunc(item.Content); | ||
Console.WriteLine($"\nModifier:\nModified {item.Content} to {newValue}"); | ||
|
||
var updateMessage = new Events.CountUpdate { NewCount = newValue }; | ||
await this.PublishMessageAsync(updateMessage, topic: new TopicId("default")); | ||
} | ||
} |
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,36 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Program.cs | ||
using GettingStartedGrpcSample; | ||
using Microsoft.AutoGen.Contracts; | ||
using Microsoft.AutoGen.Core; | ||
using Microsoft.AutoGen.Core.Grpc; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using ModifyF = System.Func<int, int>; | ||
using TerminationF = System.Func<int, bool>; | ||
|
||
ModifyF modifyFunc = (int x) => x - 1; | ||
TerminationF runUntilFunc = (int x) => | ||
{ | ||
return x <= 1; | ||
}; | ||
|
||
AgentsAppBuilder appBuilder = new AgentsAppBuilder(); | ||
appBuilder.AddGrpcAgentWorker("http://localhost:50051"); | ||
|
||
appBuilder.Services.TryAddSingleton(modifyFunc); | ||
appBuilder.Services.TryAddSingleton(runUntilFunc); | ||
|
||
appBuilder.AddAgent<Checker>("Checker"); | ||
appBuilder.AddAgent<Modifier>("Modifier"); | ||
|
||
var app = await appBuilder.BuildAsync(); | ||
await app.StartAsync(); | ||
|
||
// Send the initial count to the agents app, running on the `local` runtime, and pass through the registered services via the application `builder` | ||
await app.PublishMessageAsync(new GettingStartedGrpcSample.Events.CountMessage | ||
{ | ||
Content = 10 | ||
}, new TopicId("default")); | ||
|
||
// Run until application shutdown | ||
await app.WaitForShutdownAsync(); |
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,11 @@ | ||
syntax = "proto3"; | ||
|
||
option csharp_namespace = "GettingStartedGrpcSample.Events"; | ||
|
||
message CountMessage { | ||
int32 content = 1; | ||
} | ||
|
||
message CountUpdate { | ||
int32 new_count = 1; | ||
} |
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
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
Oops, something went wrong.