{"record":{"id":"ae0a3f8154e054e2","repo":"microsoft/semantic-kernel","slug":"auto-invocation-of-tool-calls-may-only-be-used-wit-ae0a3f","errorCode":null,"errorMessage":"Auto-invocation of tool calls may only be used with a VertexAIChatPromptExecutionSettings.candidate_count of 1.","messagePattern":"Auto-invocation of tool calls may only be used with a VertexAIChatPromptExecutionSettings\\.candidate_count of 1\\.","errorType":"exception","errorClass":"ServiceInvalidExecutionSettingsError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/google/vertex_ai/services/vertex_ai_chat_completion.py","lineNumber":189,"sourceCode":"            contents=self._prepare_chat_history_for_request(chat_history),\n            generation_config=settings.prepare_settings_dict(),\n            tools=settings.tools,\n            tool_config=settings.tool_config,\n            stream=True,\n        )\n\n        async for chunk in response:\n            yield [\n                self._create_streaming_chat_message_content(chunk, candidate, function_invoke_attempt)\n                for candidate in chunk.candidates\n            ]\n\n    @override\n    def _verify_function_choice_settings(self, settings: \"PromptExecutionSettings\") -> None:\n        if not isinstance(settings, VertexAIChatPromptExecutionSettings):\n            raise ServiceInvalidExecutionSettingsError(\"The settings must be an VertexAIChatPromptExecutionSettings.\")\n        if settings.candidate_count is not None and settings.candidate_count > 1:\n            raise ServiceInvalidExecutionSettingsError(\n                \"Auto-invocation of tool calls may only be used with a \"\n                \"VertexAIChatPromptExecutionSettings.candidate_count 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_choice_configuration\n\n    @override\n    def _reset_function_choice_settings(self, settings: \"PromptExecutionSettings\") -> None:\n        if hasattr(settings, \"tool_config\"):\n            settings.tool_config = None\n        if hasattr(settings, \"tools\"):\n            settings.tools = None\n\n    @override","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/vertex_ai/services/vertex_ai_chat_completion.py#L171-L207","documentation":"Raised by VertexAIChatCompletion._verify_function_choice_settings when auto-invocation of tool calls is enabled and VertexAIChatPromptExecutionSettings.candidate_count is greater than 1. Auto-invocation requires a single deterministic candidate to drive the tool-call loop, so multiple candidates are incompatible and rejected.","triggerScenarios":"Configuring FunctionChoiceBehavior with auto-invocation while setting candidate_count > 1 on VertexAIChatPromptExecutionSettings.","commonSituations":"Wanting several sample completions (candidate_count=n) and enabling automatic function calling at the same time. Carrying over an OpenAI n>1 setting to Vertex AI.","solutions":["Set candidate_count to 1 (or leave it None) when using auto-invocation of tool calls.","If you need multiple candidates, disable auto-invocation (use manual function calling) instead of raising candidate_count.","Branch your settings: one configuration for multi-candidate sampling, another for tool auto-invocation."],"exampleFix":"# before\nsettings = VertexAIChatPromptExecutionSettings(candidate_count=3)\nsettings.function_choice_behavior = FunctionChoiceBehavior.Auto()\n# after\nsettings = VertexAIChatPromptExecutionSettings(candidate_count=1)\nsettings.function_choice_behavior = FunctionChoiceBehavior.Auto()","handlingStrategy":"validation","validationCode":"if getattr(settings, 'function_choice_behavior', None) and getattr(settings, 'candidate_count', None) and settings.candidate_count > 1:\n    raise ValueError('Set candidate_count=1 when using tool auto-invocation')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat candidate_count>1 and auto-invocation as mutually exclusive.","Default candidate_count to None/1 unless you specifically need multiple samples.","Add a config assertion before invoking the completion call."],"tags":["vertex-ai","function-calling","settings","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}