diff --git a/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs b/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs index 16250367cd..096471811c 100644 --- a/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs @@ -129,7 +129,7 @@ private static async Task Main() private static async Task ExecuteWorkflowAsync(Workflow workflow, string input) { // Configure whether to show agent thinking in real-time - const bool ShowAgentThinking = false; + const bool ShowAgentThinking = true; // Execute in streaming mode to see real-time progress await using StreamingRun run = await InProcessExecution.StreamAsync(workflow, input); @@ -230,14 +230,23 @@ public override async ValueTask HandleAsync(string message, IWorkflowContext con /// Executor that synchronizes agent output and prepares it for the next stage. /// This demonstrates how executors can process agent outputs and forward to the next agent. /// -internal sealed class JailbreakSyncExecutor() : Executor("JailbreakSync") +/// +/// The AIAgentHostExecutor sends response.Messages which has runtime type List<ChatMessage>. +/// The message router uses exact type matching via message.GetType(). +/// +internal sealed class JailbreakSyncExecutor() : Executor>("JailbreakSync") { - public override async ValueTask HandleAsync(ChatMessage message, IWorkflowContext context, CancellationToken cancellationToken = default) + public override async ValueTask HandleAsync(List message, IWorkflowContext context, CancellationToken cancellationToken = default) { Console.WriteLine(); // New line after agent streaming Console.ForegroundColor = ConsoleColor.Magenta; - string fullAgentResponse = message.Text?.Trim() ?? "UNKNOWN"; + // Combine all response messages (typically just one for simple agents) + string fullAgentResponse = string.Join("\n", message.Select(m => m.Text?.Trim() ?? "")).Trim(); + if (string.IsNullOrEmpty(fullAgentResponse)) + { + fullAgentResponse = "UNKNOWN"; + } Console.WriteLine($"[{this.Id}] Full Agent Response:"); Console.WriteLine(fullAgentResponse); @@ -278,17 +287,24 @@ public override async ValueTask HandleAsync(ChatMessage message, IWorkflowContex /// /// Executor that outputs the final result and marks the end of the workflow. /// -internal sealed class FinalOutputExecutor() : Executor("FinalOutput") +/// +/// The AIAgentHostExecutor sends response.Messages which has runtime type List<ChatMessage>. +/// The message router uses exact type matching via message.GetType(). +/// +internal sealed class FinalOutputExecutor() : Executor, string>("FinalOutput") { - public override ValueTask HandleAsync(ChatMessage message, IWorkflowContext context, CancellationToken cancellationToken = default) + public override ValueTask HandleAsync(List message, IWorkflowContext context, CancellationToken cancellationToken = default) { + // Combine all response messages (typically just one for simple agents) + string combinedText = string.Join("\n", message.Select(m => m.Text ?? "")).Trim(); + Console.WriteLine(); // New line after agent streaming Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\n[{this.Id}] Final Response:"); - Console.WriteLine($"{message.Text}"); + Console.WriteLine($"{combinedText}"); Console.WriteLine("\n[End of Workflow]"); Console.ResetColor(); - return ValueTask.FromResult(message.Text ?? string.Empty); + return ValueTask.FromResult(combinedText); } }