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
The streaming post-processor converts each StreamingChatMessageContent into a TextMessageUpdate, but only supports choice index 0. If the execution settings request multiple choices (ChoiceCount/n > 1), streamed chunks for choices 1+ carry ChoiceIndex > 0 and this InvalidOperationException is thrown.
Source
Thrown at dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs:106
_ => throw new InvalidOperationException("Unsupported content type"),
});
if (items.Count() == 1)
{
return items.First();
}
else
{
return new MultiModalMessage(Role.Assistant, items, from: messageEnvelope.From);
}
}
private IMessage PostProcessMessage(IMessage<StreamingChatMessageContent> streamingMessage)
{
var chatMessageContent = streamingMessage.Content;
if (chatMessageContent.ChoiceIndex > 0)
{
throw new InvalidOperationException("Only one choice is supported in streaming response");
}
return new TextMessageUpdate(Role.Assistant, chatMessageContent.Content, streamingMessage.From);
}
private IEnumerable<ChatMessageContent> ProcessMessage(IEnumerable<IMessage> messages, IAgent agent)
{
return messages.SelectMany(m =>
{
if (m is IMessage<ChatMessageContent> chatMessageContent)
{
return [chatMessageContent.Content];
}
if (m.From == agent.Name)
{
return ProcessMessageForSelf(m);
}
else
{View on GitHub (pinned to 027ecf0a37)
Solutions
- Set ResultsPerPrompt = 1 (default) in the prompt execution settings used with streaming.
- If multiple choices are required, consume IAsyncEnumerable<StreamingChatMessageContent> directly and filter by ChoiceIndex instead of using the connector.
- Catch InvalidOperationException around the streaming loop and fail with a configuration message pointing at ResultsPerPrompt.
Example fix
// before
var settings = new OpenAIPromptExecutionSettings { ResultsPerPrompt = 3 };
await foreach (var update in agent.StreamAsync(msg, settings)) { }
// after
var settings = new OpenAIPromptExecutionSettings { ResultsPerPrompt = 1 };
await foreach (var update in agent.StreamAsync(msg, settings)) { } Defensive patterns
Strategy: validation
Validate before calling
if (executionSettings.ResultsPerPrompt is > 1 && useStreaming)
throw new InvalidOperationException("Streaming through this connector requires ResultsPerPrompt == 1."); Try / catch
catch (InvalidOperationException ex) when (ex.Message.Contains("Only one choice"))
{
logger.LogError("Set ResultsPerPrompt=1 or stream manually filtering by ChoiceIndex");
throw;
} Prevention
- Keep one shared execution-settings factory that pins ResultsPerPrompt = 1 for agents.
- When N-best sampling is needed, consume SK streaming updates directly and filter ChoiceIndex.
When it happens
Trigger: OpenAIPromptExecutionSettings.ResultsPerPrompt (or equivalent ChoiceCount) greater than 1 while streaming a Semantic Kernel agent through this connector.
Common situations: Reusing execution settings tuned for best-of-N sampling; copying SK samples that set ResultsPerPrompt; switching an agent from non-streaming to streaming without reviewing choice settings.
Related errors
- Please set OPENAI_API_KEY environment variable.
- Please set OPENAI_API_KEY environment variable.
- Please set OPENAI_API_KEY environment variable.
- The recent update is not a TextMessage
- The content has more than one choice. Please try another inp
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/7014af123acdc854.
Report an issue: GitHub.