{"record":{"id":"5d27f37e59f95d45","repo":"microsoft/semantic-kernel","slug":"service-provided-for-chatcompletionagent-is-not-an","errorCode":null,"errorMessage":"Service provided for ChatCompletionAgent is not an instance of ChatCompletionClientBase. Service: {type(self.service)}","messagePattern":"Service provided for ChatCompletionAgent is not an instance of ChatCompletionClientBase\\. Service: (.+?)","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/chat_completion/chat_completion_agent.py","lineNumber":206,"sourceCode":"\n        if instructions is not None:\n            args[\"instructions\"] = instructions\n        if prompt_template_config is not None:\n            args[\"prompt_template\"] = TEMPLATE_FORMAT_MAP[prompt_template_config.template_format](\n                prompt_template_config=prompt_template_config\n            )\n            if prompt_template_config.template is not None:\n                # Use the template from the prompt_template_config if it is provided\n                args[\"instructions\"] = prompt_template_config.template\n        super().__init__(**args)\n\n    @model_validator(mode=\"after\")\n    def configure_service(self) -> \"ChatCompletionAgent\":\n        \"\"\"Configure the service used by the ChatCompletionAgent.\"\"\"\n        if self.service is None:\n            return self\n        if not isinstance(self.service, ChatCompletionClientBase):\n            raise AgentInitializationException(\n                f\"Service provided for ChatCompletionAgent is not an instance of ChatCompletionClientBase. \"\n                f\"Service: {type(self.service)}\"\n            )\n        self.kernel.add_service(self.service, overwrite=True)\n        return self\n\n    async def create_channel(\n        self, chat_history: ChatHistory | None = None, thread_id: str | None = None\n    ) -> AgentChannel:\n        \"\"\"Create a ChatHistoryChannel.\n\n        Args:\n            chat_history: The chat history for the channel. If None, a new ChatHistory instance will be created.\n            thread_id: The ID of the thread. If None, a new thread will be created.\n\n        Returns:\n            An instance of AgentChannel.\n        \"\"\"","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/chat_completion/chat_completion_agent.py#L188-L224","documentation":"Raised by ChatCompletionAgent.configure_service (a pydantic model_validator, AgentInitializationException) when self.service is provided but is not an instance of ChatCompletionClientBase. The agent can only use a chat-completion service; passing any other service type (e.g. an embedding or text-completion service) fails initialization.","triggerScenarios":"Constructing ChatCompletionAgent(service=<embedding/text-completion service object>); passing a service retrieved from the kernel that is not a ChatCompletionClientBase; passing a dict or settings object instead of a service instance.","commonSituations":"Registering an embedding service and handing it to ChatCompletionAgent; confusing PromptExecutionSettings with a service; version change where a service base class was renamed; passing a text-completion service to a chat-completion-only agent.","solutions":["Pass a ChatCompletionClientBase service instance (e.g. AzureChatCompletion or OpenAIChatComplete) as the service argument.","If relying on a kernel-registered service, omit the service argument and let the agent select via kernel.select_ai_service, or ensure a chat-completion service is registered.","Double-check the service variable is a service object, not settings or a client.","After upgrade, confirm the service class still subclasses ChatCompletionClientBase."],"exampleFix":"// before\nagent = ChatCompletionAgent(service=AzureTextCompletion(...))  # raises\n// after\nfrom semantic_kernel.connectors.ai.open_ai import AzureChatCompletion\nagent = ChatCompletionAgent(service=AzureChatCompletion(...))","handlingStrategy":"type-guard","validationCode":"from semantic_kernel.connectors.ai.chat_completion_client_base import ChatCompletionClientBase\ndef validate_service(service):\n    if service is not None and not isinstance(service, ChatCompletionClientBase):\n        raise TypeError(f'service must be ChatCompletionClientBase, got {type(service)}')\n    return service","typeGuard":"def is_chat_completion_service(service) -> bool:\n    from semantic_kernel.connectors.ai.chat_completion_client_base import ChatCompletionClientBase\n    return isinstance(service, ChatCompletionClientBase)","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException\ntry:\n    agent = ChatCompletionAgent(service=svc)\nexcept AgentInitializationException as e:\n    if 'not an instance of ChatCompletionClientBase' in str(e): raise TypeError(e)\n    raise","preventionTips":["Pass only chat-completion services to ChatCompletionAgent","Do not confuse PromptExecutionSettings with a service instance"],"tags":["chat-completion","service-config","initialization","type-guard"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}