microsoft/autogen · error · InvalidOperationException

Only one choice is supported in streaming response

Error message

Only one choice is supported in streaming response

What it means

Thrown inside SemanticKernelAgent.GenerateStreamingReplyAsync when a streamed StreamingChatMessageContent arrives with ChoiceIndex > 0. The streaming path yields every chunk as a single IMessage stream and has no channel for parallel choices, so any second-choice chunk aborts the enumeration.

Source

Thrown at dotnet/src/AutoGen.SemanticKernel/SemanticKernelAgent.cs:92

        return new MessageEnvelope<ChatMessageContent>(reply[0], from: this.Name);
    }

    public async IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(
        IEnumerable<IMessage> messages,
        GenerateReplyOptions? options = null,
        [EnumeratorCancellation] CancellationToken cancellationToken = default)
    {
        var chatHistory = BuildChatHistory(messages);
        var option = BuildOption(options);
        var chatService = GetChatCompletionService();
        var response = chatService.GetStreamingChatMessageContentsAsync(chatHistory, option, _kernel, cancellationToken);

        await foreach (var content in response)
        {
            if (content.ChoiceIndex > 0)
            {
                throw new InvalidOperationException("Only one choice is supported in streaming response");
            }

            yield return new MessageEnvelope<StreamingChatMessageContent>(content, from: this.Name);
        }
    }

    private ChatHistory BuildChatHistory(IEnumerable<IMessage> messages)
    {
        var chatMessageContents = ProcessMessage(messages);
        // if there's no system message in chatMessageContents, add one to the beginning
        if (!chatMessageContents.Any(c => c.Role == AuthorRole.System))
        {
            chatMessageContents = new[] { new ChatMessageContent(AuthorRole.System, _systemMessage) }.Concat(chatMessageContents);
        }

        return new ChatHistory(chatMessageContents);
    }

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Ensure ResultsPerPrompt is 1 (or unset) in the options used for GenerateStreamingReplyAsync
  2. Use the non-streaming GenerateReplyAsync only after verifying single-choice settings; better, keep streaming but with one choice
  3. Test the connector configuration directly with GetStreamingChatMessageContentsAsync to confirm a single choice is returned

Example fix

// before
var options = new GenerateReplyOptions { ResultsPerPrompt = 2 };
await foreach (var chunk in skAgent.GenerateStreamingReplyAsync(msgs, options)) { ... }

// after
var options = new GenerateReplyOptions { ResultsPerPrompt = 1 };
await foreach (var chunk in skAgent.GenerateStreamingReplyAsync(msgs, options)) { ... }
Defensive patterns

Strategy: validation

Validate before calling

if (options?.ResultsPerPrompt is > 1)
    throw new ArgumentOutOfRangeException(nameof(options), "Streaming SK agent supports exactly one choice.");

await foreach (var chunk in skAgent.GenerateStreamingReplyAsync(messages, options)) { /* ... */ }

Try / catch

try { await foreach (var c in skAgent.GenerateStreamingReplyAsync(msgs, opt)) Yield(c); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Only one choice"))
{
    opt = opt is null ? null : new GenerateReplyOptions { Temperature = opt.Temperature, ResultsPerPrompt = 1 };
    // restart stream with corrected options
}

Prevention

When it happens

Trigger: Calling GenerateStreamingReplyAsync with ResultsPerPrompt/ChoiceCount greater than 1 so the connector emits interleaved chunks for choices 0 and 1.

Common situations: Streaming with n>1 sampling options copied from another agent, or a connector/model upgrade that began honoring the choice count in streaming responses.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/b4af9a689467dde6. Report an issue: GitHub.