{"record":{"id":"715b0c2a2a941beb","repo":"microsoft/autogen","slug":"response-choices-count-1","errorCode":null,"errorMessage":"response.Choices.Count != 1","messagePattern":"response\\.Choices\\.Count != 1","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs","lineNumber":148,"sourceCode":"                    ToolCallMessage toolCallMessage when (toolCallMessage.From is null || toolCallMessage.From == agent.Name) => ProcessToolCallMessage(toolCallMessage, agent),\n                    ToolCallResultMessage toolCallResultMessage => ProcessToolCallResultMessage(toolCallResultMessage, agent),\n                    AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage => ProcessFunctionCallMiddlewareMessage(aggregateMessage, agent), // message type support for functioncall middleware\n                    _ => [m],\n                };\n            }\n        });\n    }\n\n    private IMessage PostProcessMessage(ChatCompletionResponse response, IAgent from)\n    {\n        if (response.Choices is null)\n        {\n            throw new ArgumentNullException(\"response.Choices\");\n        }\n\n        if (response.Choices?.Count != 1)\n        {\n            throw new NotSupportedException(\"response.Choices.Count != 1\");\n        }\n\n        var choice = response.Choices[0];\n        var finishReason = choice.FinishReason ?? throw new ArgumentNullException(\"choice.FinishReason\");\n\n        if (finishReason == Choice.FinishReasonEnum.Stop || finishReason == Choice.FinishReasonEnum.Length)\n        {\n            return new TextMessage(Role.Assistant, choice.Message?.Content ?? throw new ArgumentNullException(\"choice.Message.Content\"), from: from.Name);\n        }\n        else if (finishReason == Choice.FinishReasonEnum.ToolCalls)\n        {\n            var functionContents = choice.Message?.ToolCalls ?? throw new ArgumentNullException(\"choice.Message.ToolCalls\");\n            var toolCalls = functionContents.Select(f => new ToolCall(f.Function.Name, f.Function.Arguments) { ToolCallId = f.Id }).ToList();\n            return new ToolCallMessage(toolCalls, from: from.Name);\n        }\n        else\n        {\n            throw new NotSupportedException($\"FinishReason {finishReason} is not supported\");","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs#L130-L166","documentation":"After the null check, MistralChatMessageConnector.PostProcessMessage insists that Choices.Count equals 1 — the connector maps exactly one choice to one AutoGen message and cannot represent n>1 or n=0 completions, so any other count throws NotSupportedException.","triggerScenarios":"A completion response with zero choices (blocked/empty generation) or multiple choices (if n > 1 was requested or the API returned extra candidates) reaching PostProcessMessage.","commonSituations":"Requesting n > 1 completions from a Mistral model; safety-filtered or empty responses with an empty choices array; API error payloads that deserialize to a Choices collection of size 0.","solutions":["Do not request multiple completions (n > 1) when using this connector — it only supports a single choice.","Log the raw response; if Choices is empty, investigate the blocking/error reason in the payload (content filter, invalid prompt).","Catch NotSupportedException at the orchestration layer and retry with a simplified prompt if the emptiness is transient."],"exampleFix":"// before\nvar request = new ChatCompletionRequest { Model = \"mistral-large-latest\", Messages = msgs, N = 3 };\n\n// after\nvar request = new ChatCompletionRequest { Model = \"mistral-large-latest\", Messages = msgs }; // n defaults to 1","handlingStrategy":"validation","validationCode":"if (response.Choices is { Count: 1 })\n{\n    // safe to map\n}\nelse\n{\n    // log raw response; likely blocked generation or n>1 config\n}","typeGuard":null,"tryCatchPattern":"try { var reply = await mistralAgent.SendAsync(msg); } catch (NotSupportedException ex) when (ex.Message.Contains(\"Choices.Count != 1\")) { /* retry with simplified prompt or report */ }","preventionTips":["Never request n > 1 completions through this connector","Log full responses for empty-choices cases","Handle blocked-content responses at the orchestration layer"],"tags":["mistral","response-parsing","choices","not-supported"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}