diff --git a/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs b/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs index f665c1b817..821a90dc2d 100644 --- a/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs @@ -230,14 +230,15 @@ 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") +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"; + ChatMessage agentResponse = message.LastOrDefault(m => m.Role.Equals(ChatRole.Assistant), new ChatMessage(ChatRole.Assistant, string.Empty)); + string fullAgentResponse = agentResponse.Text?.Trim() ?? "UNKNOWN"; Console.WriteLine($"[{this.Id}] Full Agent Response:"); Console.WriteLine(fullAgentResponse); @@ -278,17 +279,21 @@ 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") +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) { + var lastMessage = message.LastOrDefault(m => m.Role.Equals(ChatRole.Assistant), new ChatMessage(ChatRole.Assistant, string.Empty)); Console.WriteLine(); // New line after agent streaming Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\n[{this.Id}] Final Response:"); - Console.WriteLine($"{message.Text}"); + // Safely print the assistant text - normalize null to empty string before printing and returning. + string assistantText = lastMessage.Text ?? string.Empty; + Console.WriteLine(assistantText); Console.WriteLine("\n[End of Workflow]"); Console.ResetColor(); - return ValueTask.FromResult(message.Text ?? string.Empty); + // Ensure we never return null + return ValueTask.FromResult(assistantText); } }