{"record":{"id":"d7fe502c1eca199b","repo":"microsoft/semantic-kernel","slug":"auto-invocation-of-tool-calls-may-only-be-used-wit-d7fe50","errorCode":null,"errorMessage":"Auto-invocation of tool calls may only be used with a GoogleAIChatPromptExecutionSettings.candidate_count of 1.","messagePattern":"Auto-invocation of tool calls may only be used with a GoogleAIChatPromptExecutionSettings\\.candidate_count of 1\\.","errorType":"exception","errorClass":"ServiceInvalidExecutionSettingsError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py","lineNumber":240,"sourceCode":"                async for chunk in _generate_content_stream(client):\n                    yield [\n                        self._create_streaming_chat_message_content(chunk, candidate, function_invoke_attempt)\n                        for candidate in chunk.candidates  # type: ignore\n                    ]\n        else:\n            with Client(api_key=self.service_settings.api_key.get_secret_value()) as client:  # type: ignore[union-attr]\n                async for chunk in _generate_content_stream(client):\n                    yield [\n                        self._create_streaming_chat_message_content(chunk, candidate, function_invoke_attempt)\n                        for candidate in chunk.candidates  # type: ignore\n                    ]\n\n    @override\n    def _verify_function_choice_settings(self, settings: \"PromptExecutionSettings\") -> None:\n        if not isinstance(settings, GoogleAIChatPromptExecutionSettings):\n            raise ServiceInvalidExecutionSettingsError(\"The settings must be an GoogleAIChatPromptExecutionSettings.\")\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                \"GoogleAIChatPromptExecutionSettings.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":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py#L222-L258","documentation":"Raised by _verify_function_choice_settings when GoogleAIChatPromptExecutionSettings.candidate_count is greater than 1 while tool/function auto-invocation is enabled. The Gemini API can return multiple candidate responses per call, but auto-invocation of kernel function tool calls requires exactly one deterministic response to process function calls from. The guard prevents ambiguous multi-candidate responses during the function-calling loop.","triggerScenarios":"Setting settings.candidate_count = 2 (or more) AND configuring FunctionChoiceBehavior.Auto()/Required() on the same request. The combination is contradictory because the framework needs a single response to extract and execute tool calls.","commonSituations":"Enabling candidate_count > 1 for A/B comparison or best-of-N sampling and then later adding function calling without resetting candidate_count; copying settings from a non-function-calling scenario.","solutions":["Set settings.candidate_count = 1 (or leave it as None/unset, which defaults to 1) when using function_choice_behavior.","Disable function calling (use no FunctionChoiceBehavior or FunctionChoiceBehavior.None()) if you genuinely need multiple candidates.","Create separate settings objects: one with candidate_count > 1 for plain chat, one with candidate_count=1 for function-calling chat."],"exampleFix":"# before\nsettings = GoogleAIChatPromptExecutionSettings()\nsettings.candidate_count = 3\n# FunctionChoiceBehavior.Auto is set on the request\n\n# after\nsettings = GoogleAIChatPromptExecutionSettings()\nsettings.candidate_count = 1  # or omit — default is 1","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.ai.google.google_ai.google_ai_prompt_execution_settings import GoogleAIChatPromptExecutionSettings\n\nif settings.candidate_count is not None and settings.candidate_count > 1:\n    raise ValueError(\n        'candidate_count must be 1 when function_choice_behavior is enabled; '\n        'set candidate_count=1 or disable function calling.'\n    )","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default candidate_count to 1 (or leave None) whenever you enable FunctionChoiceBehavior.Auto/Required.","Maintain two named settings presets: one for multi-candidate sampling, one for function calling.","Add an assertion in your request wrapper that candidate_count == 1 when tools are attached."],"tags":["google-ai","function-calling","candidate-count","settings","auto-invocation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}