{"record":{"id":"0ec15cc49e7eedf7","repo":"microsoft/semantic-kernel","slug":"the-thread-is-not-a-copilot-studio-agent-thread","errorCode":null,"errorMessage":"The thread is not a Copilot Studio Agent thread.","messagePattern":"The thread is not a Copilot Studio Agent thread\\.","errorType":"exception","errorClass":"AgentThreadOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/copilot_studio/copilot_studio_agent.py","lineNumber":442,"sourceCode":"\n        Args:\n            messages: The messages to send to the agent.\n            thread: The thread to use for the agent.\n            arguments: The arguments to pass to the agent. These take precedence over the agent-defined args.\n            kernel: The kernel to use for the agent. This kernel takes precedence over the agent-defined kernel.\n            **kwargs: Additional keyword arguments.\n\n        Returns:\n            A chat message content and thread with the response.\n        \"\"\"\n        thread = await self._ensure_thread_exists_with_messages(\n            messages=messages,\n            thread=thread,\n            construct_thread=lambda: CopilotStudioAgentThread(self.client),\n            expected_type=CopilotStudioAgentThread,\n        )\n        if not isinstance(thread, CopilotStudioAgentThread):\n            raise AgentThreadOperationException(\"The thread is not a Copilot Studio Agent thread.\")\n\n        normalized_messages = self._normalize_messages(messages)\n\n        responses: list[ChatMessageContent] = []\n        async for response in self._inner_invoke(\n            thread=thread,\n            messages=normalized_messages,\n            on_intermediate_message=None,\n            arguments=arguments,\n            kernel=kernel,\n            **kwargs,\n        ):\n            responses.append(response)\n\n        return AgentResponseItem(message=responses[-1], thread=thread)\n\n    @trace_agent_invocation\n    @override","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/copilot_studio/copilot_studio_agent.py#L424-L460","documentation":"Raised by CopilotStudioAgent.get_response() after _ensure_thread_exists_with_messages returns a thread that is not an instance of CopilotStudioAgentThread. The method passes expected_type=CopilotStudioAgentThread to the thread-resolution helper, but if the caller supplies a pre-existing thread of a different concrete type (e.g. ChatHistoryAgentThread), the isinstance check fails. It is an AgentThreadOperationException.","triggerScenarios":"Calling agent.get_response(messages, thread=some_other_thread) where some_other_thread is a plain AgentThread, ChatHistoryAgentThread, or any other AgentThread subclass that is not CopilotStudioAgentThread.","commonSituations":"Sharing a thread across different agent types in a multi-agent pipeline; passing a thread created for a ChatCompletionAgent to a CopilotStudioAgent by mistake; refactoring code that previously used a different agent type.","solutions":["Omit the thread argument so the agent creates its own CopilotStudioAgentThread internally.","Pass an explicit CopilotStudioAgentThread(agent.client) when you need to control the thread lifecycle.","Keep per-agent-type thread instances; do not mix thread types across agent implementations."],"exampleFix":"# before\nthread = ChatHistoryAgentThread()\nawait copilot_agent.get_response(\"hello\", thread=thread)  # raises\n\n# after\nthread = CopilotStudioAgentThread(copilot_agent.client)\nawait copilot_agent.get_response(\"hello\", thread=thread)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"from semantic_kernel.agents.copilot_studio.copilot_studio_agent import CopilotStudioAgentThread\n\ndef is_copilot_thread(t) -> bool:\n    return isinstance(t, CopilotStudioAgentThread)","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentThreadOperationException\n\nif thread is not None and not isinstance(thread, CopilotStudioAgentThread):\n    thread = CopilotStudioAgentThread(agent.client)\nawait agent.get_response(\"hello\", thread=thread)","preventionTips":["Always use CopilotStudioAgentThread with CopilotStudioAgent, or omit the thread argument.","Keep thread instances scoped per agent type.","Type-check threads at pipeline boundaries when mixing agent types."],"tags":["type-mismatch","thread","copilot-studio"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}