{"record":{"id":"74ef703a488772dd","repo":"microsoft/autogen","slug":"resultsperprompt-greater-than-1-is-not-supported-i","errorCode":null,"errorMessage":"ResultsPerPrompt greater than 1 is not supported in this semantic kernel agent","messagePattern":"ResultsPerPrompt greater than 1 is not supported in this semantic kernel agent","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.SemanticKernel/SemanticKernelAgent.cs","lineNumber":72,"sourceCode":"        this.Name = name;\n        _systemMessage = systemMessage;\n        _modelServiceId = modelServiceId;\n        _settings = settings;\n    }\n\n    public string Name { get; }\n\n    public async Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)\n    {\n        var chatHistory = BuildChatHistory(messages);\n        var option = BuildOption(options);\n        var chatService = GetChatCompletionService();\n\n        var reply = await chatService.GetChatMessageContentsAsync(chatHistory, option, _kernel, cancellationToken);\n\n        if (reply.Count > 1)\n        {\n            throw new InvalidOperationException(\"ResultsPerPrompt greater than 1 is not supported in this semantic kernel agent\");\n        }\n\n        return new MessageEnvelope<ChatMessageContent>(reply[0], 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 = BuildChatHistory(messages);\n        var option = BuildOption(options);\n        var chatService = GetChatCompletionService();\n        var response = chatService.GetStreamingChatMessageContentsAsync(chatHistory, option, _kernel, cancellationToken);\n\n        await foreach (var content in response)\n        {\n            if (content.ChoiceIndex > 0)","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.SemanticKernel/SemanticKernelAgent.cs#L54-L90","documentation":"SemanticKernelAgent.GenerateReplyAsync throws this when the underlying IChatCompletionService returns more than one ChatMessageContent. The agent maps GenerateReplyOptions.ResultsPerPrompt into the kernel's PromptExecutionSettings, but its return type (a single IMessage) can only carry one reply, so multiple results are treated as unsupported.","triggerScenarios":"Calling GenerateReplyAsync with a GenerateReplyOptions whose ResultsPerPrompt (or the kernel execution settings' ResultsPerPrompt / ChoiceCount) is greater than 1, against a connector that honors n>1.","commonSituations":"Copying options from an OpenAI agent configuration that sets n>1 for sampling variety, a model/connector version that started respecting ResultsPerPrompt, or sharing one options object across different agent types.","solutions":["Set ResultsPerPrompt = 1 (or leave it null/default) in the GenerateReplyOptions passed to the SemanticKernel agent","If multiple candidates are genuinely needed, call the kernel's IChatCompletionService directly instead of going through SemanticKernelAgent","Do not reuse an options object configured for another provider's multi-choice behavior"],"exampleFix":"// before\nvar options = new GenerateReplyOptions { Temperature = 0.7f, ResultsPerPrompt = 3 };\nvar reply = await skAgent.GenerateReplyAsync(messages, options);\n\n// after\nvar options = new GenerateReplyOptions { Temperature = 0.7f, ResultsPerPrompt = 1 };\nvar reply = await skAgent.GenerateReplyAsync(messages, options);","handlingStrategy":"validation","validationCode":"if (options?.ResultsPerPrompt is > 1)\n{\n    options = options with { ResultsPerPrompt = 1 }; // or throw your own config error early\n}","typeGuard":"static bool IsSingleChoice(GenerateReplyOptions? o) => o?.ResultsPerPrompt is null or 1;","tryCatchPattern":"try { return await skAgent.GenerateReplyAsync(messages, options); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ResultsPerPrompt\"))\n{\n    throw new ConfigurationException(\"SemanticKernel agent requires ResultsPerPrompt=1\", ex);\n}","preventionTips":["Never share an options object configured with n>1 across agent implementations","Assert single-choice options in integration tests for SK agents","Centralize option construction per provider instead of one global template"],"tags":["csharp","semantic-kernel","options","invalid-operation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}