Skip to content

Conversation

@rezaghadimim
Copy link

Motivation and Context

This change is required because previously JailbreakSyncExecutor and FinalOutputExecutor only accepted a single ChatMessage. That limitation caused the sample workflow described in issue #2696 to break — after the AI agent step, subsequent executors were skipped. With this update, those executors now accept List (one of the officially supported input types), which restores correct workflow chaining and prevents silent failures.

Description

  • Updated input type for JailbreakSyncExecutor and FinalOutputExecutor from ChatMessage to List.

  • Adjusted sample usage and test cases to pass lists instead of single messages.

  • No other functional changes were made to executor logic.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

…hatMessage> instead of ChatMessage

- previous single ChatMessage caused the sample to fail
Copilot AI review requested due to automatic review settings December 9, 2025 07:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical workflow chaining issue in the 07_MixedWorkflowAgentsAndExecutors sample by updating JailbreakSyncExecutor and FinalOutputExecutor to accept List<ChatMessage> instead of single ChatMessage objects. This change enables proper workflow continuation after AI agent steps, preventing executors from being silently skipped.

Key Changes:

  • Changed input type from ChatMessage to List<ChatMessage> for both executors
  • Updated message extraction logic to use LastOrDefault() to retrieve the last assistant message from the list
  • Maintained existing executor behavior while supporting the correct workflow message passing pattern

@rezaghadimim
Copy link
Author

rezaghadimim commented Dec 9, 2025 via email

internal sealed class JailbreakSyncExecutor() : Executor<List<ChatMessage>>("JailbreakSync")
{
public override async ValueTask HandleAsync(ChatMessage message, IWorkflowContext context, CancellationToken cancellationToken = default)
public override async ValueTask HandleAsync(List<ChatMessage> message, IWorkflowContext context, CancellationToken cancellationToken = default)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming the parameter messages would be better as it is not a list

internal sealed class FinalOutputExecutor() : Executor<List<ChatMessage>, string>("FinalOutput")
{
public override ValueTask<string> HandleAsync(ChatMessage message, IWorkflowContext context, CancellationToken cancellationToken = default)
public override ValueTask<string> HandleAsync(List<ChatMessage> message, IWorkflowContext context, CancellationToken cancellationToken = default)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than string.Empty should this be UNKNOWN?

public override ValueTask<string> HandleAsync(ChatMessage message, IWorkflowContext context, CancellationToken cancellationToken = default)
public override ValueTask<string> HandleAsync(List<ChatMessage> message, IWorkflowContext context, CancellationToken cancellationToken = default)
{
var lastMessage = message.LastOrDefault(m => m.Role.Equals(ChatRole.Assistant), new ChatMessage(ChatRole.Assistant, string.Empty));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above?

@markwallace-microsoft
Copy link
Member

There is another PR with a similar fix for this issue: #2182

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants