microsoft/autogen · error · NotSupportedException
response.Choices.Count != 1
Error message
response.Choices.Count != 1
What it means
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.
Source
Thrown at dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs:148
ToolCallMessage toolCallMessage when (toolCallMessage.From is null || toolCallMessage.From == agent.Name) => ProcessToolCallMessage(toolCallMessage, agent),
ToolCallResultMessage toolCallResultMessage => ProcessToolCallResultMessage(toolCallResultMessage, agent),
AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage => ProcessFunctionCallMiddlewareMessage(aggregateMessage, agent), // message type support for functioncall middleware
_ => [m],
};
}
});
}
private IMessage PostProcessMessage(ChatCompletionResponse response, IAgent from)
{
if (response.Choices is null)
{
throw new ArgumentNullException("response.Choices");
}
if (response.Choices?.Count != 1)
{
throw new NotSupportedException("response.Choices.Count != 1");
}
var choice = response.Choices[0];
var finishReason = choice.FinishReason ?? throw new ArgumentNullException("choice.FinishReason");
if (finishReason == Choice.FinishReasonEnum.Stop || finishReason == Choice.FinishReasonEnum.Length)
{
return new TextMessage(Role.Assistant, choice.Message?.Content ?? throw new ArgumentNullException("choice.Message.Content"), from: from.Name);
}
else if (finishReason == Choice.FinishReasonEnum.ToolCalls)
{
var functionContents = choice.Message?.ToolCalls ?? throw new ArgumentNullException("choice.Message.ToolCalls");
var toolCalls = functionContents.Select(f => new ToolCall(f.Function.Name, f.Function.Arguments) { ToolCallId = f.Id }).ToList();
return new ToolCallMessage(toolCalls, from: from.Name);
}
else
{
throw new NotSupportedException($"FinishReason {finishReason} is not supported");View on GitHub (pinned to 027ecf0a37)
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.
Example fix
// before
var request = new ChatCompletionRequest { Model = "mistral-large-latest", Messages = msgs, N = 3 };
// after
var request = new ChatCompletionRequest { Model = "mistral-large-latest", Messages = msgs }; // n defaults to 1 Defensive patterns
Strategy: validation
Validate before calling
if (response.Choices is { Count: 1 })
{
// safe to map
}
else
{
// log raw response; likely blocked generation or n>1 config
} Try / catch
try { var reply = await mistralAgent.SendAsync(msg); } catch (NotSupportedException ex) when (ex.Message.Contains("Choices.Count != 1")) { /* retry with simplified prompt or report */ } Prevention
- Never request n > 1 completions through this connector
- Log full responses for empty-choices cases
- Handle blocked-content responses at the orchestration layer
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- response.Choices
- choice.FinishReason
- FinishReason {finishReason} is not supported
- VarObject {response.VarObject} is not supported
- Role {textMessage.Role} is not supported
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/715b0c2a2a941beb.
Report an issue: GitHub.