{"record":{"id":"9353e19faa1a2d18","repo":"microsoft/semantic-kernel","slug":"chat-completion-service-not-found-check-your-serv","errorCode":null,"errorMessage":"Chat completion service not found. Check your service or kernel configuration.","messagePattern":"Chat completion service not found\\. Check your service or kernel configuration\\.","errorType":"exception","errorClass":"KernelServiceNotFoundError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/chat_completion/chat_completion_agent.py","lineNumber":590,"sourceCode":"    ) -> ChatHistory:\n        \"\"\"Prepare the agent chat history from the input history by adding the formatted instructions.\"\"\"\n        formatted_instructions = await self.format_instructions(kernel, arguments)\n        messages = []\n        if formatted_instructions:\n            messages.append(ChatMessageContent(role=AuthorRole.SYSTEM, content=formatted_instructions, name=self.name))\n        if history.messages:\n            messages.extend(history.messages)\n\n        return ChatHistory(messages=messages)\n\n    async def _get_chat_completion_service_and_settings(\n        self, kernel: \"Kernel\", arguments: KernelArguments\n    ) -> tuple[ChatCompletionClientBase, PromptExecutionSettings]:\n        \"\"\"Get the chat completion service and settings.\"\"\"\n        chat_completion_service, settings = kernel.select_ai_service(arguments=arguments, type=ChatCompletionClientBase)\n\n        if not chat_completion_service:\n            raise KernelServiceNotFoundError(\n                \"Chat completion service not found. Check your service or kernel configuration.\"\n            )\n\n        assert isinstance(chat_completion_service, ChatCompletionClientBase)  # nosec\n        assert settings is not None  # nosec\n\n        return chat_completion_service, settings\n\n    async def _drain_mutated_messages(\n        self,\n        history: ChatHistory,\n        start: int,\n        thread: ChatHistoryAgentThread,\n    ) -> list[ChatMessageContent]:\n        \"\"\"Return messages appended to history after start and push them to thread.\"\"\"\n        drained: list[ChatMessageContent] = []\n        for i in range(start, len(history)):\n            msg: ChatMessageContent = history[i]  # type: ignore","sourceCodeStart":572,"sourceCodeEnd":608,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/chat_completion/chat_completion_agent.py#L572-L608","documentation":"Raised by ChatCompletionAgent._get_chat_completion_service_and_settings (a KernelServiceNotFoundError) when kernel.select_ai_service returns no service of type ChatCompletionClientBase. The agent needs a registered chat-completion service to run; none was found on the kernel.","triggerScenarios":"Invoking a ChatCompletionAgent whose kernel has no chat-completion service registered; only an embedding or text-completion service is registered; the service was added to a different kernel instance than the one used.","commonSituations":"Forgetting to add_service(AzureChatCompletion(...)) to the kernel; registering a non-chat service; passing a separate kernel to the agent than the one configured; service id mismatch with select settings.","solutions":["Register a ChatCompletionClientBase service on the kernel the agent uses: kernel.add_service(AzureChatCompletion(...)).","Pass the service directly to ChatCompletionAgent(service=...) to avoid selection ambiguity.","Confirm the kernel instance the agent uses is the one with the service (not a fresh/other kernel).","Check that the service id in PromptExecutionSettings (if set) matches a registered chat-completion service id."],"exampleFix":"// before\nkernel = Kernel()\nagent = ChatCompletionAgent(kernel=kernel, name='a')  # no service registered\nawait agent.get_response('hi')  # raises\n// after\nkernel = Kernel()\nkernel.add_service(AzureChatCompletion(...))\nagent = ChatCompletionAgent(kernel=kernel, name='a')\nawait agent.get_response('hi')","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.ai.chat_completion_client_base import ChatCompletionClientBase\ndef has_chat_service(kernel) -> bool:\n    return any(isinstance(s, ChatCompletionClientBase) for s in kernel.get_services().values())\nif not has_chat_service(kernel):\n    kernel.add_service(AzureChatCompletion(...))","typeGuard":"def has_chat_completion_service(kernel) -> bool:\n    from semantic_kernel.connectors.ai.chat_completion_client_base import ChatCompletionClientBase\n    return any(isinstance(s, ChatCompletionClientBase) for s in kernel.get_services().values())","tryCatchPattern":"from semantic_kernel.exceptions.kernel_exceptions import KernelServiceNotFoundError\ntry:\n    await agent.get_response('hi')\nexcept KernelServiceNotFoundError:\n    kernel.add_service(AzureChatCompletion(...))\n    await agent.get_response('hi')","preventionTips":["Register a ChatCompletionClientBase on the kernel before invoking","Pass the service directly to ChatCompletionAgent to avoid selection ambiguity","Ensure the same kernel instance is used by the agent"],"tags":["chat-completion","service-config","kernel","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}