{"record":{"id":"97bb5e33b2465874","repo":"microsoft/semantic-kernel","slug":"auto-invocation-of-tool-calls-may-only-be-used-wit-97bb5e","errorCode":null,"errorMessage":"Auto-invocation of tool calls may only be used with a OpenAIChatPromptExecutions.number_of_responses of 1.","messagePattern":"Auto-invocation of tool calls may only be used with a OpenAIChatPromptExecutions\\.number_of_responses of 1\\.","errorType":"exception","errorClass":"ServiceInvalidExecutionSettingsError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/open_ai_chat_completion_base.py","lineNumber":145,"sourceCode":"                        inner_content=chunk,\n                        ai_model_id=settings.ai_model_id,\n                        metadata=chunk_metadata,\n                        function_invoke_attempt=function_invoke_attempt,\n                    )\n                    for i in range(settings.number_of_responses or 1)\n                ]\n            else:\n                yield [\n                    self._create_streaming_chat_message_content(chunk, choice, chunk_metadata, function_invoke_attempt)\n                    for choice in chunk.choices\n                ]\n\n    @override\n    def _verify_function_choice_settings(self, settings: \"PromptExecutionSettings\") -> None:\n        if not isinstance(settings, OpenAIChatPromptExecutionSettings):\n            raise ServiceInvalidExecutionSettingsError(\"The settings must be an OpenAIChatPromptExecutionSettings.\")\n        if settings.number_of_responses is not None and settings.number_of_responses > 1:\n            raise ServiceInvalidExecutionSettingsError(\n                \"Auto-invocation of tool calls may only be used with a \"\n                \"OpenAIChatPromptExecutions.number_of_responses of 1.\"\n            )\n\n    @override\n    def _update_function_choice_settings_callback(\n        self,\n    ) -> Callable[[\"FunctionCallChoiceConfiguration\", \"PromptExecutionSettings\", FunctionChoiceType], None]:\n        return update_settings_from_function_call_configuration\n\n    @override\n    def _reset_function_choice_settings(self, settings: \"PromptExecutionSettings\") -> None:\n        if hasattr(settings, \"tool_choice\"):\n            settings.tool_choice = None\n        if hasattr(settings, \"tools\"):\n            settings.tools = None\n\n    # endregion","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_chat_completion_base.py#L127-L163","documentation":"Raised in _verify_function_choice_settings when auto-invocation of tool calls is enabled (function_choice configuration is set) but number_of_responses is greater than 1. The OpenAI API cannot reliably correlate tool-call requests/responses across multiple parallel completions, so Semantic Kernel blocks this combination at the configuration validation stage.","triggerScenarios":"Setting OpenAIChatPromptExecutionSettings.number_of_responses (OpenAI's n parameter) to a value > 1 while also configuring auto-function-invocation (e.g., FunctionChoiceBehavior.Auto with kernel/plugins registered).","commonSituations":"A developer sets n > 1 to get multiple candidate responses for selection, then later adds function calling to the same settings without resetting n; copying settings from a template that defaults number_of_responses to a higher value.","solutions":["Set settings.number_of_responses = 1 (or leave it unset, which defaults to 1) when using auto-function-invocation","If you need multiple responses, disable auto-invocation and handle tool calls manually in a loop","Audit your settings object right before the call: if function calling is configured, force number_of_responses to 1"],"exampleFix":"# before\nsettings = OpenAIChatPromptExecutionSettings(number_of_responses=3)\n# auto-invocation configured elsewhere -> raises at verify time\n# after\nsettings = OpenAIChatPromptExecutionSettings()  # number_of_responses defaults to 1\n# or explicitly\nsettings.number_of_responses = 1","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.ai.open_ai import OpenAIChatPromptExecutionSettings\n\nif isinstance(settings, OpenAIChatPromptExecutionSettings):\n    if settings.number_of_responses is not None and settings.number_of_responses > 1:\n        if hasattr(settings, 'function_choice_behavior') and settings.function_choice_behavior:\n            settings.number_of_responses = 1  # reconcile conflict","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInvalidExecutionSettingsError\n\ntry:\n    await kernel.invoke(...)\nexcept ServiceInvalidExecutionSettingsError as e:\n    if 'number_of_responses of 1' in str(e):\n        settings.number_of_responses = 1\n        await kernel.invoke(...)  # retry","preventionTips":["Treat number_of_responses > 1 and function-calling as mutually exclusive by design","Add a settings-validation helper that checks this invariant before the kernel call"],"tags":["openai","function-calling","configuration-conflict","execution-settings"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}