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

Merged
merged 129 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from 112 commits
Commits
Show all changes
129 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
56231d4
Merge branch 'main' into agent-orchestration
crickman Apr 23, 2025
a3de83d
Unit-tests and clean-up
crickman Apr 24, 2025
d93823e
Namespace
crickman Apr 24, 2025
efbf59b
Merge branch 'main' into agent-orchestration
crickman Apr 24, 2025
e0f3b74
Sync cleanup
crickman Apr 24, 2025
ebfab0b
Scope topic
crickman Apr 24, 2025
42ffb79
Add test reference
crickman Apr 24, 2025
34549f5
Fix test base
crickman Apr 24, 2025
a4dcbe4
Merge branch 'main' into agent-orchestration
crickman Apr 24, 2025
53787cf
Test update - description
crickman Apr 24, 2025
538045f
Handoff Orchestration
crickman Apr 25, 2025
0db496f
Resolve merge from main
crickman Apr 25, 2025
1dc6fcb
Fix final note
crickman Apr 25, 2025
c58e9bb
Merge branch 'main' into agent-orchestration
crickman Apr 25, 2025
1f6dcdc
Skip test
crickman Apr 25, 2025
37ae252
Merge branch 'main' into agent-orchestration
crickman Apr 29, 2025
3397091
Merge branch 'main' into agent-orchestration
crickman May 5, 2025
eeb8660
Merge branch 'main' into agent-orchestration
crickman May 7, 2025
bb315c6
Fix merge
crickman May 7, 2025
8a84c0a
Merge branch 'main' into agent-orchestration
crickman May 7, 2025
6675050
Checkpoint
crickman May 8, 2025
eaa4b45
Handoff Checkpoint
crickman May 9, 2025
d88e895
Merge branch 'main' into agent-orchestration
crickman May 9, 2025
a51b2cf
Typo
crickman May 9, 2025
e2c3b6a
Whitespace
crickman May 9, 2025
d501df8
Namespace
crickman May 9, 2025
2ee2f32
Orchestration name & namespace
crickman May 9, 2025
72d50ba
Cleanup
crickman May 9, 2025
76a211c
Update test
crickman May 9, 2025
843be9c
Complete
crickman May 9, 2025
fae03ff
Formatting
crickman May 9, 2025
5a1c367
Merge branch 'main' into agent-orchestration
crickman May 9, 2025
ffcf05c
Readme
crickman May 9, 2025
8d7975e
Straggler
crickman May 9, 2025
f711984
Test input
crickman May 9, 2025
958d334
Handoff update
crickman May 9, 2025
968ee0f
Handoff cleanup
crickman May 9, 2025
946982e
Merge branch 'main' into agent-orchestration
crickman May 9, 2025
2e763cb
Namespace
crickman May 9, 2025
301ec29
Final refactoring
crickman May 9, 2025
7752cc8
Merge branch 'main' into agent-orchestration
crickman May 12, 2025
eeb42a3
Fix test
crickman May 12, 2025
7c939bd
Rollback
crickman May 12, 2025
b29f169
Merge branch 'main' into agent-orchestration
crickman May 12, 2025
364446b
Handoff unit-tests
crickman May 13, 2025
a63e253
Update dotnet/samples/GettingStartedWithAgents/Orchestration/Step01a_…
crickman May 13, 2025
6a992c6
Update dotnet/samples/GettingStartedWithAgents/Orchestration/Step03a_…
crickman May 13, 2025
5845fed
Merge branch 'main' into agent-orchestration
crickman May 13, 2025
ff0f6f6
Comments
crickman May 13, 2025
4f076ea
Merge branch 'agent-orchestration' of https://github.com/microsoft/se…
crickman May 13, 2025
01e7337
Rename sample
crickman May 13, 2025
8eeaa1e
Update handoff sample
crickman May 13, 2025
eea5585
Merge branch 'main' into agent-orchestration
crickman May 13, 2025
b1fa1c8
Remove cruft
crickman May 13, 2025
c2ba05e
Content fix
crickman May 13, 2025
c72d708
Suppression
crickman May 13, 2025
71226ca
Revert timeout
crickman May 13, 2025
13245dc
Merge branch 'main' into agent-orchestration
crickman May 14, 2025
cb08e41
netstandard2.0
crickman May 14, 2025
9989c7f
Project clean-up
crickman May 14, 2025
950d100
Format
crickman May 14, 2025
9b68712
Experimental
crickman May 14, 2025
ab1bfe1
Clarify property names
crickman May 14, 2025
764f2ef
Format
crickman May 14, 2025
4c4d3e0
Merge branch 'main' into agent-orchestration
crickman May 14, 2025
528b09b
Merge branch 'main' into agent-orchestration
crickman May 15, 2025
5028184
Updated
crickman May 15, 2025
3549214
Merge branch 'agent-orchestration' of https://github.com/microsoft/se…
crickman May 15, 2025
752ebca
Merge branch 'main' into agent-orchestration
crickman May 15, 2025
94079de
Address suggestion
crickman May 15, 2025
b41f205
Merge branch 'agent-orchestration' of https://github.com/microsoft/se…
crickman May 15, 2025
049ce25
Update transform
crickman May 15, 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
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.2.1" />
<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.1" />
<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.13" />
<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.13" />
<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 @@ -145,8 +147,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
11 changes: 10 additions & 1 deletion dotnet/SK-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Runtime.InProcess.UnitTests
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectorData.UnitTests", "src\Connectors\VectorData.UnitTests\VectorData.UnitTests.csproj", "{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84}"
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 @@ -1511,6 +1513,12 @@ Global
{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84}.Publish|Any CPU.Build.0 = Debug|Any CPU
{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84}.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 All @@ -1536,7 +1544,7 @@ Global
{AFA81EB7-F869-467D-8A90-744305D80AAC} = {1B4CBDE0-10C2-4E7D-9CD0-FE7586C96ED1}
{627742DB-1E52-468A-99BD-6FF1A542D25B} = {831DDCA2-7D2C-4C31-80DB-6BDB3E1F7AE0}
{E3299033-EB81-4C4C-BCD9-E8DC40937969} = {831DDCA2-7D2C-4C31-80DB-6BDB3E1F7AE0}
{078F96B4-09E1-4E0E-B214-F71A4F4BF633} = {831DDCA2-7D2C-4C31-80DB-6BDB3E1F7AE0}
{078F96B4-09E1-4E0E-B214-F71A4F4BF633} = {9ECD1AA0-75B3-4E25-B0B5-9F0945B64974}
{F51017A9-15C8-472D-893C-080046D710A6} = {078F96B4-09E1-4E0E-B214-F71A4F4BF633}
{EC3BB6D1-2FB2-4702-84C6-F791DE533ED4} = {24503383-A8C4-4255-9998-28D70FE8E99A}
{4D226C2F-AE9F-4EFB-AF2D-45C8FE5CB34E} = {24503383-A8C4-4255-9998-28D70FE8E99A}
Expand Down Expand Up @@ -1716,6 +1724,7 @@ Global
{CCC909E4-5269-A31E-0BFD-4863B4B29BBB} = {A70ED5A7-F8E1-4A57-9455-3C05989542DA}
{DA6B4ED4-ED0B-D25C-889C-9F940E714891} = {A70ED5A7-F8E1-4A57-9455-3C05989542DA}
{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84} = {5A7028A7-4DDF-4E4F-84A9-37CE8F8D7E89}
{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,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,59 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel;
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"/>
/// for executing multiple agents on the same task in parallel.
/// </summary>
public class Step01_Concurrent(ITestOutputHelper output) : BaseOrchestrationTest(output)
{
[Fact]
public async Task ConcurrentTaskAsync()
{
// Define the agents
ChatCompletionAgent physicist =
this.CreateAgent(
instructions: "You are an expert in physics. You answer questions from a physics perspective.",
description: "An expert in physics");
ChatCompletionAgent chemist =
this.CreateAgent(
instructions: "You are an expert in chemistry. You answer questions from a chemistry perspective.",
description: "An expert in chemistry");

// Define the orchestration
OrchestrationMonitor monitor = new();
ConcurrentOrchestration orchestration =
new(physicist, chemist)
{
ResponseCallback = monitor.ResponseCallback,
LoggerFactory = this.LoggerFactory
};

// Start the runtime
InProcessRuntime runtime = new();
await runtime.StartAsync();

// Run the orchestration
string input = "What is temperature?";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string[]> result = await orchestration.InvokeAsync(input, runtime);

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

await runtime.RunUntilIdleAsync();

Console.WriteLine("\n\nORCHESTRATION HISTORY");
foreach (ChatMessageContent message in monitor.History)
{
this.WriteAgentChatMessage(message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Text.Json;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.Orchestration;
using Microsoft.SemanticKernel.Agents.Orchestration.Concurrent;
using Microsoft.SemanticKernel.Agents.Orchestration.Transforms;
using Microsoft.SemanticKernel.Agents.Runtime.InProcess;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Resources;

namespace GettingStarted.Orchestration;

/// <summary>
/// Demonstrates how to use the <see cref="ConcurrentOrchestration"/> with structured output.
/// </summary>
public class Step01a_ConcurrentWithStructuredOutput(ITestOutputHelper output) : BaseOrchestrationTest(output)
{
private static readonly JsonSerializerOptions s_options = new() { WriteIndented = true };

[Fact]
public async Task ConcurrentStructuredOutputAsync()
{
// Define the agents
ChatCompletionAgent agent1 =
this.CreateAgent(
instructions: "You are an expert in identifying themes in articles. Given an article, identify the main themes.",
description: "An expert in identifying themes in articles");
ChatCompletionAgent agent2 =
this.CreateAgent(
instructions: "You are an expert in sentiment analysis. Given an article, identify the sentiment.",
description: "An expert in sentiment analysis");
ChatCompletionAgent agent3 =
this.CreateAgent(
instructions: "You are an expert in entity recognition. Given an article, extract the entities.",
description: "An expert in entity recognition");

// Define the orchestration with transform
Kernel kernel = this.CreateKernelWithChatCompletion();
StructuredOutputTransform<Analysis> outputTransform =
new(kernel.GetRequiredService<IChatCompletionService>(),
new OpenAIPromptExecutionSettings { ResponseFormat = typeof(Analysis) });
ConcurrentOrchestration<string, Analysis> orchestration =
new(agent1, agent2, agent3)
{
LoggerFactory = this.LoggerFactory,
ResultTransform = outputTransform.TransformAsync,
};

// Start the runtime
InProcessRuntime runtime = new();
await runtime.StartAsync();

// Run the orchestration
const string resourceId = "Hamlet_full_play_summary.txt";
string input = EmbeddedResource.Read(resourceId);
Console.WriteLine($"\n# INPUT: @{resourceId}\n");
OrchestrationResult<Analysis> result = await orchestration.InvokeAsync(input, runtime);

Analysis output = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds * 2));
Console.WriteLine($"\n# RESULT:\n{JsonSerializer.Serialize(output, s_options)}");

await runtime.RunUntilIdleAsync();
}

private sealed class Analysis
{
public IList<string> Themes { get; set; } = [];
public IList<string> Sentiments { get; set; } = [];
public IList<string> Entities { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel;
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"/> for
/// executing multiple agents in sequence, i.e.the output of one agent is
/// the input to the next agent.
/// </summary>
public class Step02_Sequential(ITestOutputHelper output) : BaseOrchestrationTest(output)
{
[Fact]
public async Task SequentialTaskAsync()
{
// Define the agents
ChatCompletionAgent analystAgent =
this.CreateAgent(
name: "Analyst",
instructions:
"""
You are a marketing analyst. Given a product description, identify:
- Key features
- Target audience
- Unique selling points
""",
description: "A agent that extracts key concepts from a product description.");
ChatCompletionAgent writerAgent =
this.CreateAgent(
name: "copywriter",
instructions:
"""
You are a marketing copywriter. Given a block of text describing features, audience, and USPs,
compose a compelling marketing copy (like a newsletter section) that highlights these points.
Output should be short (around 150 words), output just the copy as a single text block.
""",
description: "An agent that writes a marketing copy based on the extracted concepts.");
ChatCompletionAgent editorAgent =
this.CreateAgent(
name: "editor",
instructions:
"""
You are an editor. Given the draft copy, correct grammar, improve clarity, ensure consistent tone,
give format and make it polished. Output the final improved copy as a single text block.
""",
description: "An agent that formats and proofreads the marketing copy.");

// Define the orchestration
OrchestrationMonitor monitor = new();
SequentialOrchestration orchestration =
new(analystAgent, writerAgent, editorAgent)
{
ResponseCallback = monitor.ResponseCallback,
LoggerFactory = this.LoggerFactory
};

// Start the runtime
InProcessRuntime runtime = new();
await runtime.StartAsync();

// Run the orchestration
string input = "An eco-friendly stainless steel water bottle that keeps drinks cold for 24 hours";
Console.WriteLine($"\n# INPUT: {input}\n");
OrchestrationResult<string> result = await orchestration.InvokeAsync(input, runtime);
string text = await result.GetValueAsync(TimeSpan.FromSeconds(ResultTimeoutInSeconds));
Console.WriteLine($"\n# RESULT: {text}");

await runtime.RunUntilIdleAsync();

Console.WriteLine("\n\nORCHESTRATION HISTORY");
foreach (ChatMessageContent message in monitor.History)
{
this.WriteAgentChatMessage(message);
}
}
}
Loading
Loading