{"record":{"id":"7014af123acdc854","repo":"microsoft/autogen","slug":"only-one-choice-is-supported-in-streaming-response-7014af","errorCode":null,"errorMessage":"Only one choice is supported in streaming response","messagePattern":"Only one choice is supported in streaming response","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs","lineNumber":106,"sourceCode":"            _ => throw new InvalidOperationException(\"Unsupported content type\"),\n        });\n\n        if (items.Count() == 1)\n        {\n            return items.First();\n        }\n        else\n        {\n            return new MultiModalMessage(Role.Assistant, items, from: messageEnvelope.From);\n        }\n    }\n\n    private IMessage PostProcessMessage(IMessage<StreamingChatMessageContent> streamingMessage)\n    {\n        var chatMessageContent = streamingMessage.Content;\n        if (chatMessageContent.ChoiceIndex > 0)\n        {\n            throw new InvalidOperationException(\"Only one choice is supported in streaming response\");\n        }\n        return new TextMessageUpdate(Role.Assistant, chatMessageContent.Content, streamingMessage.From);\n    }\n\n    private IEnumerable<ChatMessageContent> ProcessMessage(IEnumerable<IMessage> messages, IAgent agent)\n    {\n        return messages.SelectMany(m =>\n        {\n            if (m is IMessage<ChatMessageContent> chatMessageContent)\n            {\n                return [chatMessageContent.Content];\n            }\n            if (m.From == agent.Name)\n            {\n                return ProcessMessageForSelf(m);\n            }\n            else\n            {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs#L88-L124","documentation":"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.","triggerScenarios":"OpenAIPromptExecutionSettings.ResultsPerPrompt (or equivalent ChoiceCount) greater than 1 while streaming a Semantic Kernel agent through this connector.","commonSituations":"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.","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."],"exampleFix":"// before\nvar settings = new OpenAIPromptExecutionSettings { ResultsPerPrompt = 3 };\nawait foreach (var update in agent.StreamAsync(msg, settings)) { }\n\n// after\nvar settings = new OpenAIPromptExecutionSettings { ResultsPerPrompt = 1 };\nawait foreach (var update in agent.StreamAsync(msg, settings)) { }","handlingStrategy":"validation","validationCode":"if (executionSettings.ResultsPerPrompt is > 1 && useStreaming)\n    throw new InvalidOperationException(\"Streaming through this connector requires ResultsPerPrompt == 1.\");","typeGuard":null,"tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message.Contains(\"Only one choice\"))\n{\n    logger.LogError(\"Set ResultsPerPrompt=1 or stream manually filtering by ChoiceIndex\");\n    throw;\n}","preventionTips":["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."],"tags":["semantic-kernel","streaming","configuration","autogen","csharp"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}