mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Overhaul orchestration library with new approach (#199)
This commit is contained in:
@@ -43,10 +43,9 @@ public class ConcurrentOrchestration_Intro(ITestOutputHelper output) : Orchestra
|
||||
// Run the orchestration
|
||||
string input = "What is temperature?";
|
||||
Console.WriteLine($"\n# INPUT: {input}\n");
|
||||
OrchestrationResult<string[]> result = await orchestration.InvokeAsync(input);
|
||||
AgentRunResponse result = await orchestration.RunAsync(input);
|
||||
|
||||
string[] output = await result;
|
||||
Console.WriteLine($"\n# RESULT:\n{string.Join("\n\n", output.Select(text => $"{text}"))}");
|
||||
Console.WriteLine($"\n# RESULT:\n{string.Join("\n\n", result.Messages.Select(r => $"{r.Text}"))}");
|
||||
|
||||
this.DisplayHistory(monitor.History);
|
||||
}
|
||||
|
||||
+2
-9
@@ -32,21 +32,14 @@ public class ConcurrentOrchestration_With_StructuredOutput(ITestOutputHelper out
|
||||
description: "An expert in entity recognition");
|
||||
|
||||
// Define the orchestration with transform
|
||||
StructuredOutputTransform<Analysis> outputTransform = new(this.CreateChatClient());
|
||||
ConcurrentOrchestration<string, Analysis> orchestration =
|
||||
new(agent1, agent2, agent3)
|
||||
{
|
||||
LoggerFactory = this.LoggerFactory,
|
||||
ResultTransform = outputTransform.TransformAsync,
|
||||
};
|
||||
ConcurrentOrchestration orchestration = new(agent1, agent2, agent3) { LoggerFactory = this.LoggerFactory };
|
||||
|
||||
// Run the orchestration
|
||||
const string resourceId = "Hamlet_full_play_summary.txt";
|
||||
string input = Resources.Read(resourceId);
|
||||
Console.WriteLine($"\n# INPUT: @{resourceId}\n");
|
||||
OrchestrationResult<Analysis> result = await orchestration.InvokeAsync(input);
|
||||
|
||||
Analysis output = await result;
|
||||
var output = await orchestration.RunAsync<Analysis>(this.CreateChatClient(), input);
|
||||
Console.WriteLine($"\n# RESULT:\n{JsonSerializer.Serialize(output, s_options)}");
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ public class GroupChatOrchestration_Intro(ITestOutputHelper output) : Orchestrat
|
||||
|
||||
string input = "Create a slogon for a new eletric SUV that is affordable and fun to drive.";
|
||||
Console.WriteLine($"\n# INPUT: {input}\n");
|
||||
OrchestrationResult<string> result = await orchestration.InvokeAsync(input);
|
||||
Console.WriteLine($"\n# RESULT: {await result}");
|
||||
AgentRunResponse result = await orchestration.RunAsync(input);
|
||||
Console.WriteLine($"\n# RESULT: {result}");
|
||||
|
||||
this.DisplayHistory(monitor.History);
|
||||
}
|
||||
|
||||
+2
-2
@@ -132,8 +132,8 @@ public class GroupChatOrchestration_With_AIManager(ITestOutputHelper output) : O
|
||||
|
||||
// Run the orchestration
|
||||
Console.WriteLine($"\n# INPUT: {topic}\n");
|
||||
OrchestrationResult<string> result = await orchestration.InvokeAsync(topic);
|
||||
Console.WriteLine($"\n# RESULT: {await result}");
|
||||
AgentRunResponse result = await orchestration.RunAsync(topic);
|
||||
Console.WriteLine($"\n# RESULT: {result}");
|
||||
|
||||
this.DisplayHistory(monitor.History);
|
||||
}
|
||||
|
||||
+2
-2
@@ -69,8 +69,8 @@ public class GroupChatOrchestration_With_HumanInTheLoop(ITestOutputHelper output
|
||||
// Run the orchestration
|
||||
string input = "Create a slogon for a new eletric SUV that is affordable and fun to drive.";
|
||||
Console.WriteLine($"\n# INPUT: {input}\n");
|
||||
OrchestrationResult<string> result = await orchestration.InvokeAsync(input);
|
||||
Console.WriteLine($"\n# RESULT: {await result}");
|
||||
AgentRunResponse result = await orchestration.RunAsync(input);
|
||||
Console.WriteLine($"\n# RESULT: {result}");
|
||||
|
||||
this.DisplayHistory(monitor.History);
|
||||
}
|
||||
|
||||
@@ -80,9 +80,9 @@ public class HandoffOrchestration_Intro(ITestOutputHelper output) : Orchestratio
|
||||
|
||||
// Run the orchestration
|
||||
Console.WriteLine($"\n# INPUT:\n{task}\n");
|
||||
OrchestrationResult<string> result = await orchestration.InvokeAsync(task);
|
||||
AgentRunResponse result = await orchestration.RunAsync(task);
|
||||
|
||||
Console.WriteLine($"\n# RESULT: {await result}");
|
||||
Console.WriteLine($"\n# RESULT: {result}");
|
||||
|
||||
this.DisplayHistory(monitor.History);
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Agents.Orchestration;
|
||||
using Microsoft.Extensions.AI;
|
||||
@@ -44,7 +45,7 @@ public class HandoffOrchestration_With_StructuredInput(ITestOutputHelper output)
|
||||
OrchestrationMonitor monitor = new();
|
||||
|
||||
// Define the orchestration
|
||||
HandoffOrchestration<GithubIssue, string> orchestration =
|
||||
HandoffOrchestration orchestration =
|
||||
new(OrchestrationHandoffs
|
||||
.StartWith(triageAgent)
|
||||
.Add(triageAgent, dotnetAgent, pythonAgent))
|
||||
@@ -80,8 +81,8 @@ public class HandoffOrchestration_With_StructuredInput(ITestOutputHelper output)
|
||||
|
||||
// Run the orchestration
|
||||
Console.WriteLine($"\n# INPUT:\n{input.Id}: {input.Title}\n");
|
||||
OrchestrationResult<string> result = await orchestration.InvokeAsync(input);
|
||||
Console.WriteLine($"\n# RESULT: {await result}");
|
||||
AgentRunResponse result = await orchestration.RunAsync(JsonSerializer.Serialize(input));
|
||||
Console.WriteLine($"\n# RESULT: {result}");
|
||||
Console.WriteLine($"\n# LABELS: {string.Join(",", githubPlugin.Labels["12345"])}\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -65,8 +65,8 @@ public class SequentialOrchestration_Intro(ITestOutputHelper output) : Orchestra
|
||||
// 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);
|
||||
Console.WriteLine($"\n# RESULT: {await result}");
|
||||
AgentRunResponse result = await orchestration.RunAsync(input);
|
||||
Console.WriteLine($"\n# RESULT: {result}");
|
||||
|
||||
this.DisplayHistory(monitor.History);
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using Microsoft.Agents.Orchestration;
|
||||
using Microsoft.Extensions.AI;
|
||||
using Microsoft.Extensions.AI.Agents;
|
||||
|
||||
namespace Orchestration;
|
||||
@@ -28,7 +29,7 @@ public class SequentialOrchestration_With_Cancellation(ITestOutputHelper output)
|
||||
string input = "42";
|
||||
Console.WriteLine($"\n# INPUT: {input}\n");
|
||||
|
||||
OrchestrationResult<string> result = await orchestration.InvokeAsync(input);
|
||||
OrchestratingAgentResponse result = await orchestration.RunAsync([new ChatMessage(ChatRole.User, input)]);
|
||||
|
||||
result.Cancel();
|
||||
await Task.Delay(TimeSpan.FromSeconds(3));
|
||||
|
||||
Reference in New Issue
Block a user