microsoft/semantic-kernel · error · KernelServiceNotFoundError

Chat completion service not found. Check your service or ker

Error message

Chat completion service not found. Check your service or kernel configuration.

What it means

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.

Source

Thrown at python/semantic_kernel/agents/chat_completion/chat_completion_agent.py:590

    ) -> ChatHistory:
        """Prepare the agent chat history from the input history by adding the formatted instructions."""
        formatted_instructions = await self.format_instructions(kernel, arguments)
        messages = []
        if formatted_instructions:
            messages.append(ChatMessageContent(role=AuthorRole.SYSTEM, content=formatted_instructions, name=self.name))
        if history.messages:
            messages.extend(history.messages)

        return ChatHistory(messages=messages)

    async def _get_chat_completion_service_and_settings(
        self, kernel: "Kernel", arguments: KernelArguments
    ) -> tuple[ChatCompletionClientBase, PromptExecutionSettings]:
        """Get the chat completion service and settings."""
        chat_completion_service, settings = kernel.select_ai_service(arguments=arguments, type=ChatCompletionClientBase)

        if not chat_completion_service:
            raise KernelServiceNotFoundError(
                "Chat completion service not found. Check your service or kernel configuration."
            )

        assert isinstance(chat_completion_service, ChatCompletionClientBase)  # nosec
        assert settings is not None  # nosec

        return chat_completion_service, settings

    async def _drain_mutated_messages(
        self,
        history: ChatHistory,
        start: int,
        thread: ChatHistoryAgentThread,
    ) -> list[ChatMessageContent]:
        """Return messages appended to history after start and push them to thread."""
        drained: list[ChatMessageContent] = []
        for i in range(start, len(history)):
            msg: ChatMessageContent = history[i]  # type: ignore

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Register a ChatCompletionClientBase service on the kernel the agent uses: kernel.add_service(AzureChatCompletion(...)).
  2. Pass the service directly to ChatCompletionAgent(service=...) to avoid selection ambiguity.
  3. Confirm the kernel instance the agent uses is the one with the service (not a fresh/other kernel).
  4. Check that the service id in PromptExecutionSettings (if set) matches a registered chat-completion service id.

Example fix

// before
kernel = Kernel()
agent = ChatCompletionAgent(kernel=kernel, name='a')  # no service registered
await agent.get_response('hi')  # raises
// after
kernel = Kernel()
kernel.add_service(AzureChatCompletion(...))
agent = ChatCompletionAgent(kernel=kernel, name='a')
await agent.get_response('hi')
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.connectors.ai.chat_completion_client_base import ChatCompletionClientBase
def has_chat_service(kernel) -> bool:
    return any(isinstance(s, ChatCompletionClientBase) for s in kernel.get_services().values())
if not has_chat_service(kernel):
    kernel.add_service(AzureChatCompletion(...))

Type guard

def has_chat_completion_service(kernel) -> bool:
    from semantic_kernel.connectors.ai.chat_completion_client_base import ChatCompletionClientBase
    return any(isinstance(s, ChatCompletionClientBase) for s in kernel.get_services().values())

Try / catch

from semantic_kernel.exceptions.kernel_exceptions import KernelServiceNotFoundError
try:
    await agent.get_response('hi')
except KernelServiceNotFoundError:
    kernel.add_service(AzureChatCompletion(...))
    await agent.get_response('hi')

Prevention

When it happens

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

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

Related errors


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