microsoft/semantic-kernel · error · ServiceInvalidExecutionSettingsError

Auto-invocation of tool calls may only be used with a Google

Error message

Auto-invocation of tool calls may only be used with a GoogleAIChatPromptExecutionSettings.candidate_count of 1.

What it means

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.

Source

Thrown at python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py:240

                async for chunk in _generate_content_stream(client):
                    yield [
                        self._create_streaming_chat_message_content(chunk, candidate, function_invoke_attempt)
                        for candidate in chunk.candidates  # type: ignore
                    ]
        else:
            with Client(api_key=self.service_settings.api_key.get_secret_value()) as client:  # type: ignore[union-attr]
                async for chunk in _generate_content_stream(client):
                    yield [
                        self._create_streaming_chat_message_content(chunk, candidate, function_invoke_attempt)
                        for candidate in chunk.candidates  # type: ignore
                    ]

    @override
    def _verify_function_choice_settings(self, settings: "PromptExecutionSettings") -> None:
        if not isinstance(settings, GoogleAIChatPromptExecutionSettings):
            raise ServiceInvalidExecutionSettingsError("The settings must be an GoogleAIChatPromptExecutionSettings.")
        if settings.candidate_count is not None and settings.candidate_count > 1:
            raise ServiceInvalidExecutionSettingsError(
                "Auto-invocation of tool calls may only be used with a "
                "GoogleAIChatPromptExecutionSettings.candidate_count of 1."
            )

    @override
    def _update_function_choice_settings_callback(
        self,
    ) -> Callable[["FunctionCallChoiceConfiguration", "PromptExecutionSettings", FunctionChoiceType], None]:
        return update_settings_from_function_choice_configuration

    @override
    def _reset_function_choice_settings(self, settings: "PromptExecutionSettings") -> None:
        if hasattr(settings, "tool_config"):
            settings.tool_config = None
        if hasattr(settings, "tools"):
            settings.tools = None

    @override

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set settings.candidate_count = 1 (or leave it as None/unset, which defaults to 1) when using function_choice_behavior.
  2. Disable function calling (use no FunctionChoiceBehavior or FunctionChoiceBehavior.None()) if you genuinely need multiple candidates.
  3. Create separate settings objects: one with candidate_count > 1 for plain chat, one with candidate_count=1 for function-calling chat.

Example fix

# before
settings = GoogleAIChatPromptExecutionSettings()
settings.candidate_count = 3
# FunctionChoiceBehavior.Auto is set on the request

# after
settings = GoogleAIChatPromptExecutionSettings()
settings.candidate_count = 1  # or omit — default is 1
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.connectors.ai.google.google_ai.google_ai_prompt_execution_settings import GoogleAIChatPromptExecutionSettings

if settings.candidate_count is not None and settings.candidate_count > 1:
    raise ValueError(
        'candidate_count must be 1 when function_choice_behavior is enabled; '
        'set candidate_count=1 or disable function calling.'
    )

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/d7fe502c1eca199b. Report an issue: GitHub.