{"record":{"id":"fc78dadb5109fb1d","repo":"microsoft/semantic-kernel","slug":"the-kernel-is-required-for-function-calls","errorCode":null,"errorMessage":"The kernel is required for function calls.","messagePattern":"The kernel is required for function calls\\.","errorType":"exception","errorClass":"ServiceInvalidExecutionSettingsError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/chat_completion_client_base.py","lineNumber":118,"sourceCode":"            A list of chat message contents representing the response(s) from the LLM.\n        \"\"\"\n        from semantic_kernel.connectors.ai.function_calling_utils import (\n            merge_function_results,\n        )\n\n        # Create a copy of the settings to avoid modifying the original settings\n        settings = copy.deepcopy(settings)\n        # Later on, we already use the tools or equivalent settings, we cast here.\n        if not isinstance(settings, self.get_prompt_execution_settings_class()):\n            settings = self.get_prompt_execution_settings_from_settings(settings)\n\n        if not self.SUPPORTS_FUNCTION_CALLING:\n            return await self._inner_get_chat_message_contents(chat_history, settings)\n\n        kernel: \"Kernel\" = kwargs.get(\"kernel\")  # type: ignore\n        if settings.function_choice_behavior is not None:\n            if kernel is None:\n                raise ServiceInvalidExecutionSettingsError(\"The kernel is required for function calls.\")\n            self._verify_function_choice_settings(settings)\n\n        if settings.function_choice_behavior and kernel:\n            # Configure the function choice behavior into the settings object\n            # that will become part of the request to the AI service\n            settings.function_choice_behavior.configure(\n                kernel=kernel,\n                update_settings_callback=self._update_function_choice_settings_callback(),\n                settings=settings,\n            )\n\n        if (\n            settings.function_choice_behavior is None\n            or not settings.function_choice_behavior.auto_invoke_kernel_functions\n        ):\n            return await self._inner_get_chat_message_contents(chat_history, settings)\n\n        # Auto invoke loop","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/chat_completion_client_base.py#L100-L136","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the kernel instance: service.get_chat_message_contents(history, settings, kernel=kernel).","If you did not intend to use function calling, set settings.function_choice_behavior = None.","Prefer routing the call through Kernel.invoke so the kernel is supplied automatically."],"exampleFix":"# before\nsettings.function_choice_behavior = FunctionChoiceBehavior.Auto()\nawait service.get_chat_message_contents(history, settings)\n# after\nsettings.function_choice_behavior = FunctionChoiceBehavior.Auto()\nawait service.get_chat_message_contents(history, settings, kernel=kernel)","handlingStrategy":"validation","validationCode":"def kernel_required_for_function_calling(settings, kwargs) -> bool:\n    if getattr(settings, \"function_choice_behavior\", None) is not None and kwargs.get(\"kernel\") is None:\n        return False\n    return True","typeGuard":"def is_ready_for_function_calling(settings, kwargs) -> bool:\n    fcb = getattr(settings, \"function_choice_behavior\", None)\n    return fcb is None or kwargs.get(\"kernel\") is not None","tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInvalidExecutionSettingsError\n\ntry:\n    completions = await service.get_chat_message_contents(history, settings, kernel=kernel)\nexcept ServiceInvalidExecutionSettingsError as e:\n    if \"kernel is required for function calls\" in str(e):\n        if settings.function_choice_behavior is not None:\n            raise TypeError(\"Pass kernel=kernel when function_choice_behavior is set\") from e\n    raise","preventionTips":["Always pass kernel=kernel when settings.function_choice_behavior is set.","Prefer Kernel.invoke over calling the service directly so the kernel is forwarded.","Set function_choice_behavior=None when you do not need tool calling."],"tags":["chat-completion","function-calling","kernel","execution-settings"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}