Skip to content

Python: [Bug]: Copilot Studio Agent and AG-UI Protocol Integration #3203

@yegor-klymenchuk

Description

@yegor-klymenchuk

Description

When integrating Microsoft Studio Copilot agents with AG UI protocol + CopilotKit, the agent run consistently authenticates successfully and returns HTTP 200, but often produces no assistant message content.

In many runs, the stream contains only:

  • RUN_STARTED
  • RUN_FINISHED

with no TEXT_MESSAGE_* chunks in between.

Occasionally, the agent does respond with TEXT_MESSAGE_START / CONTENT / END, but this behavior is still not correct and inconsistent.


Observed Behavior

Case 1 - No assistant response (most frequent)

The agent run starts and finishes successfully, but no assistant message is emitted:

{"type":"RUN_STARTED", ...}
{"type":"RUN_FINISHED", ...}
  • No TEXT_MESSAGE_* events are streamed.

Case 2 - Partial / minimal response (inconsistent)

Sometimes the agent responds with a short assistant message:

{"type":"TEXT_MESSAGE_START", "role":"assistant"}
{"type":"TEXT_MESSAGE_CONTENT", "delta":"Generating plan..."}
{"type":"TEXT_MESSAGE_END"}

Expected Behavior

  • Every successful agent run (RUN_STARTED -> RUN_FINISHED) should reliably emit assistant content when the agent decides to respond.

Question

Is this:

  1. Expected behavior of Copilot Studio agents when used via AG UI?
  2. A known limitation or configuration issue?
  3. Or a bug in the AG UI <-> Copilot Studio integration?

Code Sample

import os

from agent_framework.microsoft import CopilotStudioAgent
from agent_framework_ag_ui import AgentFrameworkAgent
from azure.identity import OnBehalfOfCredential
from microsoft_agents.copilotstudio.client import (
    AgentType,
    ConnectionSettings,
    CopilotClient,
    PowerPlatformCloud,
)


environment_id = os.getenv("COPILOTSTUDIOAGENT__ENVIRONMENTID")
schema_name = os.getenv("COPILOTSTUDIOAGENT__SCHEMANAME")


def create_copilot_studio_agent() -> AgentFrameworkAgent:
    try:
        credential = OnBehalfOfCredential(
            tenant_id=os.getenv("AZURE_TENANT_ID"),
            client_id=os.getenv("AZURE_CLIENT_ID"),
            client_secret=os.getenv("AZURE_CLIENT_SECRET"),
            user_assertion=os.getenv("AZURE_USER_ASSERTION"),
        )

        scope = "https://api.powerplatform.com/.default"
        token_response = credential.get_token(scope)
        token = token_response.token

    except Exception as e:
        raise ValueError(
            f"Failed to authenticate with Azure AD:\n  Error: {str(e)}\n"
        ) from e

    try:
        settings = ConnectionSettings(
            environment_id=environment_id,
            agent_identifier=schema_name,
            cloud=PowerPlatformCloud.PROD,
            copilot_agent_type=AgentType.PUBLISHED,
            custom_power_platform_cloud=None,
        )

        copilot_client = CopilotClient(settings=settings, token=token)
        copilot_agent = CopilotStudioAgent(client=copilot_client)

        return AgentFrameworkAgent(
            agent=copilot_agent,
            name="Microsoft Copilot Studio Agent",
            description="Agent powered by Microsoft Copilot Studio with AG-UI integration.",
            require_confirmation=False,
        )

    except Exception as e:
        raise ValueError(
            f"Failed to create Copilot Studio agent:\n  Error: {str(e)}\n"
        ) from e

Error Messages / Stack Traces

Package Versions

agent-framework-ag-ui: "1.0.0b260107"; agent-framework-azure-ai: "1.0.0b260107"; agent-framework-copilotstudio: "1.0.0b260107"

Python Version

Python 3.12

Additional Context

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions