microsoft/semantic-kernel · error · ServiceInvalidExecutionSettingsError

The kernel is required for function calls.

Error message

The kernel is required for function calls.

What it means

Raised in the non-streaming path of ChatCompletionClientBase.get_chat_message_contents when settings.function_choice_behavior is not None (function calling is requested) but no kernel was passed via kwargs. Function calling requires a Kernel to resolve and invoke available functions, so the absence of one is treated as invalid execution settings.

Source

Thrown at python/semantic_kernel/connectors/ai/chat_completion_client_base.py:118

            A list of chat message contents representing the response(s) from the LLM.
        """
        from semantic_kernel.connectors.ai.function_calling_utils import (
            merge_function_results,
        )

        # Create a copy of the settings to avoid modifying the original settings
        settings = copy.deepcopy(settings)
        # Later on, we already use the tools or equivalent settings, we cast here.
        if not isinstance(settings, self.get_prompt_execution_settings_class()):
            settings = self.get_prompt_execution_settings_from_settings(settings)

        if not self.SUPPORTS_FUNCTION_CALLING:
            return await self._inner_get_chat_message_contents(chat_history, settings)

        kernel: "Kernel" = kwargs.get("kernel")  # type: ignore
        if settings.function_choice_behavior is not None:
            if kernel is None:
                raise ServiceInvalidExecutionSettingsError("The kernel is required for function calls.")
            self._verify_function_choice_settings(settings)

        if settings.function_choice_behavior and kernel:
            # Configure the function choice behavior into the settings object
            # that will become part of the request to the AI service
            settings.function_choice_behavior.configure(
                kernel=kernel,
                update_settings_callback=self._update_function_choice_settings_callback(),
                settings=settings,
            )

        if (
            settings.function_choice_behavior is None
            or not settings.function_choice_behavior.auto_invoke_kernel_functions
        ):
            return await self._inner_get_chat_message_contents(chat_history, settings)

        # Auto invoke loop

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass the kernel instance: service.get_chat_message_contents(history, settings, kernel=kernel).
  2. If you did not intend to use function calling, set settings.function_choice_behavior = None.
  3. Prefer routing the call through Kernel.invoke so the kernel is supplied automatically.

Example fix

# before
settings.function_choice_behavior = FunctionChoiceBehavior.Auto()
await service.get_chat_message_contents(history, settings)
# after
settings.function_choice_behavior = FunctionChoiceBehavior.Auto()
await service.get_chat_message_contents(history, settings, kernel=kernel)
Defensive patterns

Strategy: validation

Validate before calling

def kernel_required_for_function_calling(settings, kwargs) -> bool:
    if getattr(settings, "function_choice_behavior", None) is not None and kwargs.get("kernel") is None:
        return False
    return True

Type guard

def is_ready_for_function_calling(settings, kwargs) -> bool:
    fcb = getattr(settings, "function_choice_behavior", None)
    return fcb is None or kwargs.get("kernel") is not None

Try / catch

from semantic_kernel.exceptions.service_exceptions import ServiceInvalidExecutionSettingsError

try:
    completions = await service.get_chat_message_contents(history, settings, kernel=kernel)
except ServiceInvalidExecutionSettingsError as e:
    if "kernel is required for function calls" in str(e):
        if settings.function_choice_behavior is not None:
            raise TypeError("Pass kernel=kernel when function_choice_behavior is set") from e
    raise

Prevention

When it happens

Trigger: Calling service.get_chat_message_contents(chat_history, settings) (or kernel invocation that reaches it) where settings.function_choice_behavior is set (Auto/None/Required) but the 'kernel' keyword argument is missing, while the service's SUPPORTS_FUNCTION_CALLING is True.

Common situations: Using a connector directly (not through Kernel.invoke) with FunctionChoiceBehavior.Auto but forgetting to pass kernel=kernel; settings loaded from a preset that defaults function_choice_behavior; switching from a non-function-calling flow to one with tools enabled.

Related errors


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