microsoft/semantic-kernel · error · AgentThreadOperationException

Copilot Studio did not return a conversation ID.

Error message

Copilot Studio did not return a conversation ID.

What it means

Raised by CopilotStudioAgent._ensure_conversation() when iterating self.client.start_conversation() yields no activity whose .conversation.id is set. The method is called from _inner_invoke before ask_question to guarantee a conversation ID exists. Reaching the throw means the Copilot Studio service returned no usable conversation activity — a service-side misbehavior or connectivity issue. It is an AgentThreadOperationException.

Source

Thrown at python/semantic_kernel/agents/copilot_studio/copilot_studio_agent.py:624

                        if on_intermediate_message:
                            await on_intermediate_message(
                                ChatMessageContent(role=AuthorRole.ASSISTANT, name=self.name, content=action.text)
                            )
                yield ChatMessageContent(role=AuthorRole.ASSISTANT, name=self.name, content=activity.text)

    async def _ensure_conversation(self, thread: CopilotStudioAgentThread) -> None:
        """Guarantee that `thread.conversation_id` is populated."""
        if thread.id:
            return

        async for act in self.client.start_conversation():
            conversation_id = getattr(getattr(act, "conversation", None), "id", None)
            if conversation_id:
                thread.conversation_id = conversation_id
                return

        # If we reach this point, the service misbehaved, so throw
        raise AgentThreadOperationException("Copilot Studio did not return a conversation ID.")

    @staticmethod
    def _normalize_messages(messages: str | ChatMessageContent | list[str | ChatMessageContent] | None) -> list[str]:
        """Return a flat list[str] irrespective of the caller-supplied type."""
        if messages is None:
            return []

        if isinstance(messages, (str, ChatMessageContent)):
            messages = [messages]

        normalized: list[str] = []
        for m in messages:
            normalized.append(m.content if isinstance(m, ChatMessageContent) else str(m))
        return normalized

    @staticmethod
    def _to_streaming(
        msg: ChatMessageContent,

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Retry the invocation after a short delay — this is often a transient service issue.
  2. Verify the agent_identifier and environment_id in settings match a published, accessible Copilot Studio agent.
  3. Check that the access token is valid and not expired (see error 800 for auth troubleshooting).
  4. Inspect network/proxy configuration for anything modifying or blocking the streaming response from the Power Platform endpoint.
  5. Enable debug logging on the microsoft_agents.copilotstudio namespace to inspect the raw activities returned.

Example fix

# before — single attempt, fails on transient service blip
async for resp in agent.invoke("hello", thread=thread):
    ...

# after — retry wrapper for the first invocation
import asyncio
for attempt in range(3):
    try:
        async for resp in agent.invoke("hello", thread=thread):
            ...
        break
    except AgentThreadOperationException:
        thread = CopilotStudioAgentThread(agent.client)  # fresh thread
        await asyncio.sleep(2 ** attempt)
Defensive patterns

Strategy: retry

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentThreadOperationException
import asyncio

for attempt in range(3):
    thread = CopilotStudioAgentThread(agent.client)
    try:
        async for resp in agent.invoke("hello", thread=thread):
            process(resp)
        break
    except AgentThreadOperationException as exc:
        if "did not return a conversation ID" not in str(exc):
            raise
        await asyncio.sleep(2 ** attempt)

Prevention

When it happens

Trigger: During the first invocation on a fresh thread (no conversation_id yet), _ensure_conversation calls client.start_conversation(). If the async generator produces zero activities or none carry a conversation.id, the exception fires.

Common situations: Copilot Studio service outage or degradation; network proxy/firewall stripping response payloads; invalid or expired access token causing the service to return error activities without a conversation; agent_identifier / environment_id pointing to a non-existent or unpublished copilot.

Related errors


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