{"record":{"id":"382d26b464b3025d","repo":"microsoft/semantic-kernel","slug":"auto-invocation-of-tool-calls-may-only-be-used-wit-382d26","errorCode":null,"errorMessage":"Auto invocation of tool calls may only be used with a single completion.","messagePattern":"Auto invocation of tool calls may only be used with a single completion\\.","errorType":"exception","errorClass":"ServiceInvalidExecutionSettingsError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/azure_ai_inference/services/azure_ai_inference_chat_completion.py","lineNumber":207,"sourceCode":"            if len(chunk.choices) == 0:\n                continue\n            chunk_metadata = self._get_metadata_from_response(chunk)\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, AzureAIInferenceChatPromptExecutionSettings):\n            raise ServiceInvalidExecutionSettingsError(\n                \"The settings must be an AzureAIInferenceChatPromptExecutionSettings.\"\n            )\n        if settings.extra_parameters is not None and settings.extra_parameters.get(\"n\", 1) > 1:\n            # Currently only OpenAI models allow multiple completions but the Azure AI Inference service\n            # does not expose the functionality directly. If users want to have more than 1 responses, they\n            # need to configure `extra_parameters` with a key of \"n\" and a value greater than 1.\n            raise ServiceInvalidExecutionSettingsError(\n                \"Auto invocation of tool calls may only be used with a single completion.\"\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    @override\n    def _prepare_chat_history_for_request(","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/azure_ai_inference/services/azure_ai_inference_chat_completion.py#L189-L225","documentation":"Raised by _verify_function_choice_settings when auto-invocation of tool calls is enabled and extra_parameters contains 'n' greater than 1. Auto-invocation needs a single deterministic completion to feed the tool result back into the conversation loop; requesting multiple completions (n>1) makes the result ambiguous and the loop cannot proceed.","triggerScenarios":"Enabling function_choice_behavior='auto' (or required) while also setting extra_parameters={'n': N} with N>1 on AzureAIInferenceChatPromptExecutionSettings. Azure AI Inference does not expose n directly, so users configure it via extra_parameters.","commonSituations":"Wanting multiple candidate responses (n>1) and tool use in the same call; leaving extra_parameters from a prior config that set n for non-tool calls; misunderstanding that auto-invocation implies n=1.","solutions":["If you need auto tool-invocation, set extra_parameters n to 1 (or remove the 'n' key).","If you need multiple completions (n>1), disable auto-invocation (function_choice_behavior=None) and handle tool calls manually.","Split into two separate calls: one for multiple completions, one for tool-augmented single completion."],"exampleFix":"# before\nsettings.extra_parameters = {\"n\": 3}\nsettings.function_choice_behavior = \"auto\"\n\n# after  (auto-invocation path)\nsettings.extra_parameters = {\"n\": 1}\nsettings.function_choice_behavior = \"auto\"","handlingStrategy":"validation","validationCode":"def ensure_single_completion_for_auto_invoke(settings):\n    if settings.function_choice_behavior and settings.function_choice_behavior.auto_invoke:\n        n = (settings.extra_parameters or {}).get(\"n\", 1)\n        assert n == 1, \"Auto-invocation requires n == 1\"\n    return settings","typeGuard":"def auto_invoke_with_single_completion(settings) -> bool:\n    ep = settings.extra_parameters or {}\n    return ep.get(\"n\", 1) == 1 or not (\n        settings.function_choice_behavior and settings.function_choice_behavior.auto_invoke\n    )","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidExecutionSettingsError\ntry:\n    service._verify_function_choice_settings(settings)\nexcept ServiceInvalidExecutionSettingsError as e:\n    if \"single completion\" in str(e):\n        settings.extra_parameters = {\"n\": 1}","preventionTips":["Keep n == 1 when auto-invocation is on.","Disable auto-invocation if you need n > 1.","Validate extra_parameters before enabling tools."],"tags":["azure-ai-inference","function-calling","settings","validation","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}