microsoft/autogen · error · InvalidOperationException

ResultsPerPrompt greater than 1 is not supported in this sem

Error message

ResultsPerPrompt greater than 1 is not supported in this semantic kernel agent

What it means

SemanticKernelChatCompletionAgent.GenerateReplyAsync invokes the SK ChatCompletionAgent and materializes all replies with ToArrayAsync. If more than one reply comes back, it throws InvalidOperationException because the method must return exactly one IMessage envelope.

Source

Thrown at dotnet/src/AutoGen.SemanticKernel/SemanticKernelChatCompletionAgent.cs:35

    public string Name { get; }
    private readonly ChatCompletionAgent _chatCompletionAgent;

    public SemanticKernelChatCompletionAgent(ChatCompletionAgent chatCompletionAgent)
    {
        this.Name = chatCompletionAgent.Name ?? throw new ArgumentNullException(nameof(chatCompletionAgent.Name));
        this._chatCompletionAgent = chatCompletionAgent;
    }

    public async Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null,
        CancellationToken cancellationToken = default)
    {
        var agentThread = new ChatHistoryAgentThread(BuildChatHistory(messages));
        var reply = await _chatCompletionAgent
            .InvokeAsync(agentThread, cancellationToken: cancellationToken)
            .ToArrayAsync(cancellationToken: cancellationToken);

        return reply.Length > 1
            ? throw new InvalidOperationException("ResultsPerPrompt greater than 1 is not supported in this semantic kernel agent")
            : new MessageEnvelope<ChatMessageContent>(reply[0], from: this.Name);
    }

    private ChatHistory BuildChatHistory(IEnumerable<IMessage> messages)
    {
        return new ChatHistory(ProcessMessage(messages));
    }

    private IEnumerable<ChatMessageContent> ProcessMessage(IEnumerable<IMessage> messages)
    {
        return messages.Select(m => m switch
        {
            IMessage<ChatMessageContent> cmc => cmc.Content,
            _ => throw new ArgumentException("Invalid message type")
        });
    }
}

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Ensure the ChatCompletionAgent's execution settings request exactly one choice (ChoiceCount/ResultsPerPrompt = 1 or unset)
  2. Upgrade AutoGen.SemanticKernel to a version matching your Microsoft.SemanticKernel package so InvokeAsync semantics line up
  3. If multiple replies are expected, call _chatCompletionAgent.InvokeAsync yourself instead of through this adapter

Example fix

// before
var skAgent = new ChatCompletionAgent
{
    Name = "assistant",
    Kernel = kernel,
    ExecutionSettings = new PromptExecutionSettings { ChoiceCount = 3 },
};

// after
var skAgent = new ChatCompletionAgent
{
    Name = "assistant",
    Kernel = kernel,
    ExecutionSettings = new PromptExecutionSettings(), // single choice
};
Defensive patterns

Strategy: validation

Validate before calling

// ensure execution settings request a single choice before invoking the adapter
var settings = kernel.GetPromptExecutionSettings<OpenAIPromptExecutionSettings>();
if (settings?.ChoiceCount is > 1)
    throw new ConfigurationException("SemanticKernelChatCompletionAgent requires ChoiceCount=1");

Try / catch

try { return await adapter.GenerateReplyAsync(messages, options); }
catch (InvalidOperationException ex) when (ex.Message.Contains("ResultsPerPrompt"))
{
    throw new ConfigurationException("Backing ChatCompletionAgent returned multiple replies; set ChoiceCount=1", ex);
}

Prevention

When it happens

Trigger: The underlying ChatCompletionAgent (or its execution settings / duplicated responses) returns multiple ChatMessageContent items in a single InvokeAsync enumeration — e.g. ChoiceCount/ResultsPerPrompt > 1, or an SK agent framework version that yields multiple items per invoke.

Common situations: Setting PromptExecutionSettings with ChoiceCount > 1 on the ChatCompletionAgent's Kernel, or upgrading Microsoft.SemanticKernel to a version where InvokeAsync emits additional system/tool items that count toward reply.Length.

Related errors


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