microsoft/autogen · error · ArgumentNullException

response.Choices

Error message

response.Choices

What it means

MistralChatMessageConnector.PostProcessMessage requires the ChatCompletionResponse to contain a Choices collection before it can map a choice to an AutoGen message; a null Choices (explicitly null in the payload, e.g. an error or malformed body) triggers ArgumentNullException.

Source

Thrown at dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs:143

            else
            {
                return m switch
                {
                    TextMessage textMessage => ProcessTextMessage(textMessage, agent),
                    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();

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Check the HTTP status and raw body of the failing request (enable response logging) — a null Choices usually means an error payload, and the real cause (auth, quota) is in that body.
  2. Verify the Mistral API key and account quota.
  3. Confirm the model name is valid; invalid models can return error-shaped bodies.
  4. Update AutoGen.Mistral / Mistral SDK if the schema drifted.
Defensive patterns

Strategy: validation

Validate before calling

if (response.Choices is null)
{
    // inspect raw body: usually auth/quota error — do not proceed to the connector
}

Try / catch

try { var reply = await mistralAgent.SendAsync(msg); } catch (ArgumentNullException ex) when (ex.ParamName == "response.Choices") { /* check API key/quota/raw body */ }

Prevention

When it happens

Trigger: A Mistral chat-completion response whose JSON has "choices": null or omits it while deserializing to a non-null-but-default state — commonly the API returned an error object or an unexpected payload shape instead of a completion.

Common situations: Invalid API key / quota errors returned as JSON without choices; Mistral API schema changes; hitting a non-completion endpoint by misconfiguration; proxy returning a different error body.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/ec969ad7196cb763. Report an issue: GitHub.