microsoft/semantic-kernel · error · AgentThreadOperationException
The thread is not a Copilot Studio Agent thread.
Error message
The thread is not a Copilot Studio Agent thread.
What it means
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.
Source
Thrown at python/semantic_kernel/agents/copilot_studio/copilot_studio_agent.py:442
Args:
messages: The messages to send to the agent.
thread: The thread to use for the agent.
arguments: The arguments to pass to the agent. These take precedence over the agent-defined args.
kernel: The kernel to use for the agent. This kernel takes precedence over the agent-defined kernel.
**kwargs: Additional keyword arguments.
Returns:
A chat message content and thread with the response.
"""
thread = await self._ensure_thread_exists_with_messages(
messages=messages,
thread=thread,
construct_thread=lambda: CopilotStudioAgentThread(self.client),
expected_type=CopilotStudioAgentThread,
)
if not isinstance(thread, CopilotStudioAgentThread):
raise AgentThreadOperationException("The thread is not a Copilot Studio Agent thread.")
normalized_messages = self._normalize_messages(messages)
responses: list[ChatMessageContent] = []
async for response in self._inner_invoke(
thread=thread,
messages=normalized_messages,
on_intermediate_message=None,
arguments=arguments,
kernel=kernel,
**kwargs,
):
responses.append(response)
return AgentResponseItem(message=responses[-1], thread=thread)
@trace_agent_invocation
@overrideView on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before
thread = ChatHistoryAgentThread()
await copilot_agent.get_response("hello", thread=thread) # raises
# after
thread = CopilotStudioAgentThread(copilot_agent.client)
await copilot_agent.get_response("hello", thread=thread) Defensive patterns
Strategy: type-guard
Type guard
from semantic_kernel.agents.copilot_studio.copilot_studio_agent import CopilotStudioAgentThread
def is_copilot_thread(t) -> bool:
return isinstance(t, CopilotStudioAgentThread) Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentThreadOperationException
if thread is not None and not isinstance(thread, CopilotStudioAgentThread):
thread = CopilotStudioAgentThread(agent.client)
await agent.get_response("hello", thread=thread) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {self.__class__.__name__} currently only supports agent thre
- CopilotClient cannot be None
- Cannot create a thread that has been deleted.
- Cannot delete the thread, since it has not been created.
- This method is not implemented for CopilotStudioAgent. Messa
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/0ec15cc49e7eedf7.
Report an issue: GitHub.