Skip to content

.Net - Agent Orchestration #11542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 57 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
877dba1
Checkpoint
crickman Mar 27, 2025
5a63c9f
Merge branch 'main' into agent-orchestration
crickman Mar 27, 2025
6e04c10
Checkpoint
crickman Mar 27, 2025
1a6af45
Checkpoint
crickman Apr 13, 2025
1afef9a
Checkpoint
crickman Apr 13, 2025
c9b3a6f
Group Chat
crickman Apr 13, 2025
33c4e41
Group Chat
crickman Apr 13, 2025
d2c5db9
More
crickman Apr 13, 2025
e9b2dcd
Warnings
crickman Apr 13, 2025
0f41db1
Resolve merge from main
crickman Apr 14, 2025
27b7fcb
Typos
crickman Apr 14, 2025
4ff8429
Update term
crickman Apr 14, 2025
eca2c62
Rename orchestrations
crickman Apr 14, 2025
65abcf0
Replace `Trace` with `ILogger`
crickman Apr 16, 2025
7aba6bb
Log tuning
crickman Apr 16, 2025
3a5d2f4
Namespace clean-up
crickman Apr 16, 2025
274f951
Clean-up patterns
crickman Apr 16, 2025
872a761
Stable?
crickman Apr 18, 2025
f54b0f8
Typos
crickman Apr 18, 2025
fc06f0a
Typos
crickman Apr 18, 2025
5e95e69
Typos
crickman Apr 18, 2025
e5c0dd5
Headers
crickman Apr 18, 2025
a105a84
Headers
crickman Apr 18, 2025
76dfbcf
RegEx
crickman Apr 18, 2025
ad5d8c8
Headers
crickman Apr 18, 2025
a6137c3
Naming
crickman Apr 18, 2025
a3ca06c
Mark preview
crickman Apr 18, 2025
7a1d8ca
Headers
crickman Apr 18, 2025
c3931c7
Scope
crickman Apr 18, 2025
e7bdf3b
Clean-up
crickman Apr 20, 2025
eb405ad
Merge branch 'main' into agent-runtime
crickman Apr 20, 2025
a8ef1a3
Resolve merge from main
crickman Apr 20, 2025
9c3a999
Namespaces
crickman Apr 20, 2025
6afe1fa
Namespace ordering
crickman Apr 20, 2025
3e673ae
A couple more
crickman Apr 20, 2025
5c131ff
Remove namespace
crickman Apr 20, 2025
d3375ae
Comment cleanup
crickman Apr 20, 2025
66c7944
Naming
crickman Apr 20, 2025
e730ff1
Logging
crickman Apr 20, 2025
ad59e47
Merge branch 'main' into agent-orchestration
crickman Apr 20, 2025
ffb4bf6
Clean dependencies
crickman Apr 20, 2025
711cacf
Checkpoint
crickman Apr 21, 2025
1b7e488
Clean-up
crickman Apr 21, 2025
78d15f4
Whitespace
crickman Apr 21, 2025
5a47a9d
Clean-it
crickman Apr 21, 2025
ce35f0d
Once more
crickman Apr 21, 2025
c92c5ca
Package version sync
crickman Apr 21, 2025
79afea5
Clean
crickman Apr 21, 2025
689ab47
Resolve merge from main
crickman Apr 21, 2025
fcd39db
Header comment
crickman Apr 21, 2025
bdad5f0
Typos
crickman Apr 21, 2025
913bd21
Typos
crickman Apr 21, 2025
ccf9548
Typos
crickman Apr 21, 2025
264558b
Typo config
crickman Apr 22, 2025
3381f72
Merge branch 'main' into agent-orchestration
crickman Apr 22, 2025
559c189
Merge branch 'main' into agent-orchestration
crickman Apr 22, 2025
0dc5630
Comments and logging
crickman Apr 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/_typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dall = "dall" # OpenAI model name
pn = "pn" # Kiota parameter
nin = "nin" # MongoDB "not in" operator
asend = "asend" # Async generator method
magentic = "magentic" # Agent orchestration demo

[default.extend-identifiers]
ags = "ags" # Azure Graph Service
Expand Down
18 changes: 9 additions & 9 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<ItemGroup>
<PackageVersion Include="Aspire.Azure.AI.OpenAI" Version="9.1.0-preview.1.25121.10" />
<PackageVersion Include="Aspire.Azure.Search.Documents" Version="9.1.0" />
<PackageVersion Include="Aspire.Hosting.Azure.Search" Version="9.1.0" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.2.0" />
<PackageVersion Include="Aspire.Hosting.Azure.CognitiveServices" Version="9.1.0" />
<PackageVersion Include="Aspire.Hosting.Azure.Search" Version="9.1.0" />
<PackageVersion Include="AWSSDK.BedrockAgent" Version="4.0.0-preview.13" />
<PackageVersion Include="AWSSDK.BedrockAgentRuntime" Version="4.0.0-preview.13" />
<PackageVersion Include="AWSSDK.BedrockRuntime" Version="4.0.0-preview.13" />
Expand All @@ -29,24 +29,22 @@
<PackageVersion Include="EntityFramework" Version="6.5.1" />
<PackageVersion Include="FastBertTokenizer" Version="1.0.28" />
<PackageVersion Include="Google.Apis.Auth" Version="1.69.0" />
<PackageVersion Include="Google.Apis.CustomSearchAPI.v1" Version="1.68.0.3520" />
<PackageVersion Include="Google.Protobuf" Version="3.27.0" />
<PackageVersion Include="Grpc.AspNetCore" Version="2.70.0" />
<PackageVersion Include="Grpc.AspNetCore.Server" Version="2.70.0" />
<PackageVersion Include="Grpc.AspNetCore.Server.Reflection" Version="2.70.0" />
<PackageVersion Include="Grpc.AspNetCore.Web" Version="2.70.0" />
<PackageVersion Include="Grpc.Net.Client" Version="2.70.0" />
<PackageVersion Include="Grpc.Tools" Version="2.71.0" />
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.10" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.14" />
<PackageVersion Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" Version="1.0.1" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.5.1" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.12.19" />
<PackageVersion Include="Handlebars.Net.Helpers" Version="2.4.10" />
<PackageVersion Include="Handlebars.Net" Version="2.1.6" />
<PackageVersion Include="HtmlAgilityPack" Version="1.11.72" />
<PackageVersion Include="JsonSchema.Net" Version="5.4.2" />
<PackageVersion Include="Markdig" Version="0.40.0" />
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.14" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
Expand All @@ -62,7 +60,11 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
<PackageVersion Include="Microsoft.Bcl.TimeProvider" Version="8.0.1" />
<PackageVersion Include="Microsoft.Identity.Client" Version="4.67.2" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.5.1" />
<PackageVersion Include="Microsoft.ML.OnnxRuntime" Version="1.21.0" />
<PackageVersion Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" Version="1.0.1" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.12.19" />
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.10" />
<PackageVersion Include="MSTest.TestFramework" Version="3.8.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Npgsql" Version="8.0.6" />
Expand Down Expand Up @@ -144,8 +146,6 @@
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.6.23" />
<PackageVersion Include="Microsoft.OpenApi.ApiManifest" Version="0.5.6-preview" />
<PackageVersion Include="Microsoft.Plugins.Manifest" Version="1.0.0-rc3" />
<PackageVersion Include="Google.Apis.CustomSearchAPI.v1" Version="1.68.0.3520" />
<PackageVersion Include="Grpc.Net.Client" Version="2.70.0" />
<PackageVersion Include="protobuf-net" Version="3.2.45" />
<PackageVersion Include="protobuf-net.Reflection" Version="3.2.12" />
<PackageVersion Include="YamlDotNet" Version="15.3.0" />
Expand Down
9 changes: 9 additions & 0 deletions dotnet/SK-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Runtime.InProcess", "src\Ag
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Runtime.InProcess.Tests", "src\Agents\Runtime\InProcess.Tests\Runtime.InProcess.Tests.csproj", "{DA6B4ED4-ED0B-D25C-889C-9F940E714891}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agents.Orchestration", "src\Agents\Orchestration\Agents.Orchestration.csproj", "{D1A02387-FA60-22F8-C2ED-4676568B6CC3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1508,6 +1510,12 @@ Global
{DA6B4ED4-ED0B-D25C-889C-9F940E714891}.Publish|Any CPU.Build.0 = Release|Any CPU
{DA6B4ED4-ED0B-D25C-889C-9F940E714891}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA6B4ED4-ED0B-D25C-889C-9F940E714891}.Release|Any CPU.Build.0 = Release|Any CPU
{D1A02387-FA60-22F8-C2ED-4676568B6CC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1A02387-FA60-22F8-C2ED-4676568B6CC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1A02387-FA60-22F8-C2ED-4676568B6CC3}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
{D1A02387-FA60-22F8-C2ED-4676568B6CC3}.Publish|Any CPU.Build.0 = Publish|Any CPU
{D1A02387-FA60-22F8-C2ED-4676568B6CC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1A02387-FA60-22F8-C2ED-4676568B6CC3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1713,6 +1721,7 @@ Global
{A4F05541-7D23-A5A9-033D-382F1E13D0FE} = {A70ED5A7-F8E1-4A57-9455-3C05989542DA}
{CCC909E4-5269-A31E-0BFD-4863B4B29BBB} = {A70ED5A7-F8E1-4A57-9455-3C05989542DA}
{DA6B4ED4-ED0B-D25C-889C-9F940E714891} = {A70ED5A7-F8E1-4A57-9455-3C05989542DA}
{D1A02387-FA60-22F8-C2ED-4676568B6CC3} = {6823CD5E-2ABE-41EB-B865-F86EC13F0CF9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FBDC56A3-86AD-4323-AA0F-201E59123B83}
Expand Down
6 changes: 3 additions & 3 deletions dotnet/nuget.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>

<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
Expand All @@ -11,5 +11,5 @@
<package pattern="*" />
</packageSource>
</packageSourceMapping>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<IsTestProject>true</IsTestProject>
<RootNamespace></RootNamespace>
<!-- Suppress: "Declare types in namespaces", "Require ConfigureAwait", "Experimental" -->
<NoWarn>$(NoWarn);CS8618,IDE0009,IDE1006,CA1051,CA1050,CA1707,CA1054,CA2007,VSTHRD111,CS1591,RCS1110,RCS1243,CA5394,SKEXP0001,SKEXP0010,SKEXP0020,SKEXP0040,SKEXP0050,SKEXP0060,SKEXP0070,SKEXP0101,SKEXP0110,OPENAI001</NoWarn>
<NoWarn>$(NoWarn);IDE1006;IDE0009;CS8618;CA1051;CA1050;CA1707;CA1054;CA2007;CA5394;VSTHRD111;CS1591;NU1605;RCS1110;RCS1243;SKEXP0001;SKEXP0010;SKEXP0020;SKEXP0040;SKEXP0050;SKEXP0060;SKEXP0070;SKEXP0101;SKEXP0110;OPENAI001</NoWarn>
<OutputType>Library</OutputType>
<UserSecretsId>5ee045b0-aea3-4f08-8d31-32d1a6f8fed0</UserSecretsId>
</PropertyGroup>
Expand Down Expand Up @@ -46,6 +46,8 @@
<ProjectReference Include="..\..\src\Agents\Core\Agents.Core.csproj" />
<ProjectReference Include="..\..\src\Agents\OpenAI\Agents.OpenAI.csproj" />
<ProjectReference Include="..\..\src\Agents\Bedrock\Agents.Bedrock.csproj" />
<ProjectReference Include="..\..\src\Agents\Orchestration\Agents.Orchestration.csproj" />
<ProjectReference Include="..\..\src\Agents\Runtime\InProcess\Runtime.InProcess.csproj" />
<ProjectReference Include="..\..\src\Agents\Yaml\Agents.Yaml.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.AzureOpenAI\Connectors.AzureOpenAI.csproj" />
<ProjectReference Include="..\..\src\SemanticKernel.Abstractions\SemanticKernel.Abstractions.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.Orchestration;
using Microsoft.SemanticKernel.Agents.Orchestration.Concurrent;
using Microsoft.SemanticKernel.Agents.Runtime.InProcess;

namespace GettingStarted.Orchestration;

/// <summary>
/// Demonstrates how to use the <see cref="ConcurrentOrchestration{TInput, TOutput}"/>.
/// </summary>
public class Step01_Concurrent(ITestOutputHelper output) : BaseOrchestrationTest(output)
{
[Fact]
public async Task SimpleConcurrentAsync()
{
// Define the agents
ChatCompletionAgent agent1 = this.CreateAgent("Analyze the previous message to determine count of words. ALWAYS report the count using numeric digits formatted as:\nWords: <digits>");
ChatCompletionAgent agent2 = this.CreateAgent("Analyze the previous message to determine count of vowels. ALWAYS report the count using numeric digits formatted as:\nVowels: <digits>");
ChatCompletionAgent agent3 = this.CreateAgent("Analyze the previous message to determine count of onsonants. ALWAYS report the count using numeric digits formatted as:\nConsonants: <digits>");

// Define the pattern
InProcessRuntime runtime = new();
ConcurrentOrchestration orchestration = new(runtime, agent1, agent2, agent3) { LoggerFactory = this.LoggerFactory };

// Start the runtime
await runtime.StartAsync();
string input = "The quick brown fox jumps over the lazy dog";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string[]> result = await orchestration.InvokeAsync(input);

string[] output = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds));
Console.WriteLine($"\n# RESULT:\n{string.Join("\n", output.Select(text => $"\t{text}"))}");

await runtime.RunUntilIdleAsync();
}

[Fact]
public async Task NestedConcurrentAsync()
{
// Define the agents
ChatCompletionAgent agent1 = this.CreateAgent("When the input is a number, N, respond with a number that is N + 1");
ChatCompletionAgent agent2 = this.CreateAgent("When the input is a number, N, respond with a number that is N + 2");
ChatCompletionAgent agent3 = this.CreateAgent("When the input is a number, N, respond with a number that is N + 3");
ChatCompletionAgent agent4 = this.CreateAgent("When the input is a number, N, respond with a number that is N + 4");

// Define the pattern
InProcessRuntime runtime = new();

ConcurrentOrchestration<ConcurrentMessages.Request, ConcurrentMessages.Result> orchestrationLeft = CreateNested(runtime, agent1, agent2);
ConcurrentOrchestration<ConcurrentMessages.Request, ConcurrentMessages.Result> orchestrationRight = CreateNested(runtime, agent3, agent4);
ConcurrentOrchestration orchestrationMain = new(runtime, orchestrationLeft, orchestrationRight) { LoggerFactory = this.LoggerFactory };

// Start the runtime
await runtime.StartAsync();
string input = "1";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string[]> result = await orchestrationMain.InvokeAsync(input);

string[] output = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds));
Console.WriteLine($"\n# RESULT:\n{string.Join("\n", output.Select(text => $"\t{text}"))}");

await runtime.RunUntilIdleAsync();
}

[Fact]
public async Task SingleActorAsync()
{
// Define the agents
ChatCompletionAgent agent = this.CreateAgent("When the input is a number, N, respond with a number that is N + 1");

// Define the pattern
InProcessRuntime runtime = new();
ConcurrentOrchestration orchestration = new(runtime, agent) { LoggerFactory = this.LoggerFactory };

// Start the runtime
await runtime.StartAsync();
string input = "1";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string[]> result = await orchestration.InvokeAsync(input);

string[] output = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds));
Console.WriteLine($"\n# RESULT:\n{string.Join("\n", output.Select(text => $"\t{text}"))}");

await runtime.RunUntilIdleAsync();
}

[Fact]
public async Task SingleNestedActorAsync()
{
// Define the agents
ChatCompletionAgent agent = this.CreateAgent("When the input is a number, N, respond with a number that is N + 1");

// Define the pattern
InProcessRuntime runtime = new();
ConcurrentOrchestration<ConcurrentMessages.Request, ConcurrentMessages.Result> orchestrationInner = CreateNested(runtime, agent);
ConcurrentOrchestration orchestrationOuter = new(runtime, orchestrationInner) { LoggerFactory = this.LoggerFactory };

// Start the runtime
await runtime.StartAsync();
string input = "1";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string[]> result = await orchestrationOuter.InvokeAsync(input);

string[] output = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds));
Console.WriteLine($"\n# RESULT:\n{string.Join("\n", output.Select(text => $"\t{text}"))}");

await runtime.RunUntilIdleAsync();
}

private static ConcurrentOrchestration<ConcurrentMessages.Request, ConcurrentMessages.Result> CreateNested(InProcessRuntime runtime, params OrchestrationTarget[] targets)
{
return new(runtime, targets)
{
InputTransform = (ConcurrentMessages.Request input) => ValueTask.FromResult(input),
ResultTransform = (ConcurrentMessages.Result[] results) => ValueTask.FromResult(string.Join("\n", results.Select(result => $"{result.Message}")).ToResult()),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.Orchestration;
using Microsoft.SemanticKernel.Agents.Orchestration.Sequential;
using Microsoft.SemanticKernel.Agents.Runtime.InProcess;

namespace GettingStarted.Orchestration;

/// <summary>
/// Demonstrates how to use the <see cref="SequentialOrchestration{TInput, TOutput}"/>.
/// </summary>
public class Step02_Sequential(ITestOutputHelper output) : BaseOrchestrationTest(output)
{
[Fact]
public async Task SimpleSequentialAsync()
{
// Define the agents
ChatCompletionAgent agent1 = this.CreateAgent("Analyze the previous message to determine count of words. ALWAYS report the count using numeric digits formatted as:\nWords: <digits>");
ChatCompletionAgent agent2 = this.CreateAgent("Analyze the previous message to determine count of vowels. ALWAYS report the count using numeric digits formatted as:\nVowels: <digits>");
ChatCompletionAgent agent3 = this.CreateAgent("Analyze the previous message to determine count of onsonants. ALWAYS report the count using numeric digits formatted as:\nConsonants: <digits>");

// Define the pattern
InProcessRuntime runtime = new();
SequentialOrchestration orchestration = new(runtime, agent1, agent2, agent3) { LoggerFactory = this.LoggerFactory };

// Start the runtime
await runtime.StartAsync();
string input = "The quick brown fox jumps over the lazy dog";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string> result = await orchestration.InvokeAsync(input);
string text = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds));
Console.WriteLine($"\n# RESULT: {text}");

await runtime.RunUntilIdleAsync();
}

[Fact]
public async Task NestedSequentialAsync()
{
// Define the agents
ChatCompletionAgent agent1 = this.CreateAgent("When the input is a number, N, respond with a number that is N + 1");
ChatCompletionAgent agent2 = this.CreateAgent("When the input is a number, N, respond with a number that is N + 2");
ChatCompletionAgent agent3 = this.CreateAgent("When the input is a number, N, respond with a number that is N + 3");
ChatCompletionAgent agent4 = this.CreateAgent("When the input is a number, N, respond with a number that is N + 4");

// Define the pattern
InProcessRuntime runtime = new();

SequentialOrchestration<SequentialMessage, SequentialMessage> orchestrationLeft = CreateNested(runtime, agent1, agent2);
SequentialOrchestration<SequentialMessage, SequentialMessage> orchestrationRight = CreateNested(runtime, agent3, agent4);
SequentialOrchestration orchestrationMain = new(runtime, orchestrationLeft, orchestrationRight) { LoggerFactory = this.LoggerFactory };

// Start the runtime
await runtime.StartAsync();
string input = "1";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string> result = await orchestrationMain.InvokeAsync(input);

string output = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds));
Console.WriteLine($"\n# RESULT: {output}");

await runtime.RunUntilIdleAsync();
}

[Fact]
public async Task SingleActorAsync()
{
// Define the agents
ChatCompletionAgent agent = this.CreateAgent("When the input is a number, N, respond with a number that is N + 1");

// Define the pattern
InProcessRuntime runtime = new();
SequentialOrchestration orchestration = new(runtime, agent) { LoggerFactory = this.LoggerFactory };

// Start the runtime
await runtime.StartAsync();
string input = "1";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string> result = await orchestration.InvokeAsync(input);

string output = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds));
Console.WriteLine($"\n# RESULT: {output}");

await runtime.RunUntilIdleAsync();
}

[Fact]
public async Task SingleNestedActorAsync()
{
// Define the agents
ChatCompletionAgent agent = this.CreateAgent("When the input is a number, N, respond with a number that is N + 1");

// Define the pattern
InProcessRuntime runtime = new();
SequentialOrchestration<SequentialMessage, SequentialMessage> orchestrationInner = CreateNested(runtime, agent);
SequentialOrchestration orchestrationOuter = new(runtime, orchestrationInner) { LoggerFactory = this.LoggerFactory };

// Start the runtime
await runtime.StartAsync();
string input = "1";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string> result = await orchestrationOuter.InvokeAsync(input);

string output = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds));
Console.WriteLine($"\n# RESULT: {output}");

await runtime.RunUntilIdleAsync();
}

private static SequentialOrchestration<SequentialMessage, SequentialMessage> CreateNested(InProcessRuntime runtime, params OrchestrationTarget[] targets)
{
return new(runtime, targets)
{
InputTransform = (SequentialMessage input) => ValueTask.FromResult(input),
ResultTransform = (SequentialMessage results) => ValueTask.FromResult(results),
};
}
}
Loading
Loading