{"record":{"id":"ce6a932d07fd5dde","repo":"microsoft/autogen","slug":"only-one-choice-is-supported-in-streaming-response-ce6a93","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.OpenAI/Agent/OpenAIChatAgent.cs","lineNumber":111,"sourceCode":"        var chatHistory = this.CreateChatMessages(messages);\n        var settings = this.CreateChatCompletionsOptions(options);\n        var reply = await this.chatClient.CompleteChatAsync(chatHistory, settings, cancellationToken);\n        return new MessageEnvelope<ChatCompletion>(reply.Value, from: this.Name);\n    }\n\n    public async IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(\n        IEnumerable<IMessage> messages,\n        GenerateReplyOptions? options = null,\n        [EnumeratorCancellation] CancellationToken cancellationToken = default)\n    {\n        var chatHistory = this.CreateChatMessages(messages);\n        var settings = this.CreateChatCompletionsOptions(options);\n        var response = this.chatClient.CompleteChatStreamingAsync(chatHistory, settings, cancellationToken);\n        await foreach (var update in response.WithCancellation(cancellationToken))\n        {\n            if (update.ContentUpdate.Count > 1)\n            {\n                throw new InvalidOperationException(\"Only one choice is supported in streaming response\");\n            }\n\n            yield return new MessageEnvelope<StreamingChatCompletionUpdate>(update, from: this.Name);\n        }\n    }\n\n    private IEnumerable<ChatMessage> CreateChatMessages(IEnumerable<IMessage> messages)\n    {\n        var oaiMessages = messages.Select(m => m switch\n        {\n            IMessage<ChatMessage> chatMessage => chatMessage.Content,\n            _ => throw new ArgumentException(\"Invalid message type\")\n        });\n\n        // add system message if there's no system message in messages\n        if (!oaiMessages.Any(m => m is SystemChatMessage) && systemMessage is not null)\n        {\n            oaiMessages = new[] { new SystemChatMessage(systemMessage) }.Concat(oaiMessages);","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI/Agent/OpenAIChatAgent.cs#L93-L129","documentation":"InvalidOperationException thrown in OpenAIChatAgent.GenerateStreamingReplyAsync when a StreamingChatCompletionUpdate contains more than one content part (update.ContentUpdate.Count > 1). The agent yields updates as simple envelopes and downstream middleware assumes a single content part per chunk, so multi-part streaming updates (e.g. interleaved text and image parts) are rejected.","triggerScenarios":"Streaming from a model whose chunks carry multiple ChatMessageContentPart items in one update — typically multimodal/image-output models or audio+text streams — via OpenAIChatAgent in AutoGen.OpenAI.","commonSituations":"Using gpt-4o-audio-preview or image-generation-capable models through this agent; enabling multiple modalities in ChatCompletionOptions while streaming; API/SDK changes that split content into multiple parts per chunk.","solutions":["Restrict the request to text-only output (remove audio/image options from ChatCompletionOptions)","Use non-streaming GenerateReplyAsync if the model legitimately produces multi-part content","Bypass OpenAIChatAgent and consume ChatClient.CompleteChatStreamingAsync directly to handle multi-part updates yourself"],"exampleFix":"// before\nawait foreach (var msg in agent.GenerateStreamingReplyAsync(messages)) { } // multi-part chunk throws\n\n// after\nvar reply = await agent.GenerateReplyAsync(messages); // non-streaming path","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message == \"Only one choice is supported in streaming response\") { /* fall back to non-streaming GenerateReplyAsync */ }","preventionTips":["Don't enable audio/image output options with this streaming agent","Use non-streaming calls for multimodal-capable models","Consume ChatClient.CompleteChatStreamingAsync directly if you need raw multi-part chunks"],"tags":["autogen","dotnet","openai","streaming","multimodal"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}