microsoft-agents-copilotstudio-client 1.3.0


pip install microsoft-agents-copilotstudio-client

  Latest version

Released: Jul 30, 2026

Project Links

Meta
Author: Microsoft Corporation
Requires Python: >=3.10

Classifiers

Programming Language
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14

Operating System
  • OS Independent

Microsoft Agents Copilot Studio Client

PyPI version

The Copilot Studio Client is for connecting to and interacting with agents created in Microsoft Copilot Studio. This library allows you to integrate Copilot Studio agents into your Python applications.

This client library provides a direct connection to Copilot Studio agents, bypassing traditional chat channels. It's perfect for integrating AI conversations into your applications, building custom UIs, or creating agent-to-agent communication flows.

What is this?

This library is part of the Microsoft 365 Agents SDK for Python - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio.

Release Notes

Version Date Release Notes
1.3.0 2026-07-30 1.3.0 Release Notes
1.2.0 2026-07-17 1.2.0 Release Notes
1.1.0 2026-06-19 1.1.0 Release Notes
1.0.0 2026-05-22 1.0.0 Release Notes
0.9.1 2026-05-04 0.9.1 Release Notes
0.9.0 2026-04-15 0.9.0 Release Notes
0.8.0 2026-02-23 0.8.0 Release Notes
0.7.0 2026-01-21 0.7.0 Release Notes
0.6.1 2025-12-01 0.6.1 Release Notes
0.6.0 2025-11-18 0.6.0 Release Notes
0.5.0 2025-10-22 0.5.0 Release Notes

Packages Overview

We offer the following PyPI packages to create conversational experiences based on Agents:

Package Name PyPI Version Description
microsoft-agents-activity PyPI Types and validators implementing the Activity protocol spec.
microsoft-agents-hosting-core PyPI Core library for Microsoft Agents hosting.
microsoft-agents-hosting-aiohttp PyPI Configures aiohttp to run the Agent.
microsoft-agents-hosting-fastapi PyPI Configures fastapi to run the Agent.
microsoft-agents-hosting-msteams PyPI Provides classes to host an Agent for Teams.
microsoft-agents-hosting-dialogs PyPI Dialog system with waterfall dialogs, prompts, and multi-turn conversation management.
microsoft-agents-hosting-slack PyPI Provides classes to host an Agent for Slack.
microsoft-agents-storage-blob PyPI Extension to use Azure Blob as storage.
microsoft-agents-storage-cosmos PyPI Extension to use CosmosDB as storage.
microsoft-agents-authentication-msal PyPI MSAL-based authentication for Microsoft Agents.
microsoft-agents-authentication-entra-auth-sidecar PyPI Credential-free Entra ID Agent ID authentication via the sidecar.

Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:

Package Name PyPI Version Description
microsoft-agents-copilotstudio-client PyPI Direct to Engine client to interact with Agents created in CopilotStudio

Installation

pip install microsoft-agents-copilotstudio-client

Quick Start

Basic Setup

Standard Environment-Based Connection

Code below from the main.py in the Copilot Studio Client

def create_client():
    settings = ConnectionSettings(
        environment_id=environ.get("COPILOTSTUDIOAGENT__ENVIRONMENTID"),
        agent_identifier=environ.get("COPILOTSTUDIOAGENT__SCHEMANAME"),
        cloud=None,
        copilot_agent_type=None,
        custom_power_platform_cloud=None,
    )
    token = acquire_token(
        settings,
        app_client_id=environ.get("COPILOTSTUDIOAGENT__AGENTAPPID"),
        tenant_id=environ.get("COPILOTSTUDIOAGENT__TENANTID"),
    )
    copilot_client = CopilotClient(settings, token)
    return copilot_client

DirectConnect URL Mode (Simplified Setup)

For simplified setup, you can use a DirectConnect URL instead of environment-based configuration:

def create_client_direct():
    settings = ConnectionSettings(
        environment_id="",  # Not needed with DirectConnect URL
        agent_identifier="",  # Not needed with DirectConnect URL
        direct_connect_url="https://api.powerplatform.com/copilotstudio/dataverse-backed/authenticated/bots/your-bot-id"
    )
    token = acquire_token(...)
    copilot_client = CopilotClient(settings, token)
    return copilot_client

Advanced Configuration Options

settings = ConnectionSettings(
    environment_id="your-env-id",
    agent_identifier="your-agent-id",
    cloud=PowerPlatformCloud.PROD,
    copilot_agent_type=AgentType.PUBLISHED,
    custom_power_platform_cloud=None,
    direct_connect_url=None,  # Optional: Direct URL to agent
    use_experimental_endpoint=False,  # Optional: Enable experimental features
    enable_diagnostics=False,  # Optional: Enable diagnostic logging (logs HTTP details)
    client_session_settings={"timeout": aiohttp.ClientTimeout(total=60)}  # Optional: aiohttp settings
)

Diagnostic Logging Details: When enable_diagnostics=True, the CopilotClient logs detailed HTTP communication using Python's logging module at the DEBUG level:

  • Pre-request: Logs the full request URL (>>> SEND TO {url})
  • Post-response: Logs all HTTP response headers in a formatted table
  • Errors: Logs error messages with status codes

To see diagnostic output, configure your Python logging:

import logging
logging.basicConfig(level=logging.DEBUG)

Experimental Endpoint Details: When use_experimental_endpoint=True, the CopilotClient will automatically capture and use the experimental endpoint URL from the first response:

  • The server returns the experimental endpoint in the x-ms-d2e-experimental response header
  • Once captured, this URL is stored in settings.direct_connect_url and used for all subsequent requests
  • This feature is only active when use_experimental_endpoint=True AND direct_connect_url is not already set
  • The experimental endpoint allows access to pre-release features and optimizations

Start a Conversation

Simple Start

The code below is summarized from the main.py in the Copilot Studio Client. See that sample for complete & working code.

copilot_client = create_client()
async for activity in copilot_client.start_conversation(emit_start_conversation_event=True):
    if activity.type == ActivityTypes.message:
        print(f"\n{activity.text}")

# Ask questions
async for reply in copilot_client.ask_question("Who are you?", conversation_id):
    if reply.type == ActivityTypes.message:
        print(f"\n{reply.text}")

Start with Advanced Options (Locale Support)

from microsoft_agents.copilotstudio.client import StartRequest

# Create a start request with locale
start_request = StartRequest(
    emit_start_conversation_event=True,
    locale="en-US",  # Optional: specify conversation locale
    conversation_id="custom-conv-id"  # Optional: provide your own conversation ID
)

async for activity in copilot_client.start_conversation_with_request(start_request):
    if activity.type == ActivityTypes.message:
        print(f"\n{activity.text}")

Send Activities

Send a Custom Activity

from microsoft_agents.activity import Activity

activity = Activity(
    type="message",
    text="Hello, agent!",
    conversation={"id": conversation_id}
)

async for reply in copilot_client.send_activity(activity):
    print(f"Response: {reply.text}")

Execute with Explicit Conversation ID

# Execute an activity with a specific conversation ID
activity = Activity(type="message", text="What's the weather?")

async for reply in copilot_client.execute(conversation_id="conv-123", activity=activity):
    print(f"Response: {reply.text}")

Subscribe to Conversation Events

For real-time event streaming with resumption support:

from microsoft_agents.copilotstudio.client import SubscribeEvent

# Subscribe to conversation events
async for subscribe_event in copilot_client.subscribe(
    conversation_id="conv-123",
    last_received_event_id=None  # Optional: resume from last event
):
    activity = subscribe_event.activity
    event_id = subscribe_event.event_id  # Use for resumption

    if activity.type == ActivityTypes.message:
        print(f"[{event_id}] {activity.text}")

Environment Variables

Set up your .env file with the following options:

Standard Environment-Based Configuration

# Required (unless using DIRECT_CONNECT_URL)
ENVIRONMENT_ID=your-power-platform-environment-id
AGENT_IDENTIFIER=your-copilot-studio-agent-id
APP_CLIENT_ID=your-azure-app-client-id
TENANT_ID=your-azure-tenant-id

# Optional Cloud Configuration
CLOUD=PROD  # Options: PROD, GOV, HIGH, DOD, MOONCAKE, DEV, TEST, etc.
COPILOT_AGENT_TYPE=PUBLISHED  # Options: PUBLISHED, PREBUILT
CUSTOM_POWER_PLATFORM_CLOUD=https://custom.cloud.com

DirectConnect URL Configuration (Alternative)

# Required for DirectConnect mode
DIRECT_CONNECT_URL=https://api.powerplatform.com/copilotstudio/dataverse-backed/authenticated/bots/your-bot-id
APP_CLIENT_ID=your-azure-app-client-id
TENANT_ID=your-azure-tenant-id

# Optional
CLOUD=PROD  # Used for token audience resolution

Advanced Options

# Experimental and diagnostic features
USE_EXPERIMENTAL_ENDPOINT=false  # Enable automatic experimental endpoint capture
ENABLE_DIAGNOSTICS=false  # Enable diagnostic logging (logs HTTP requests/responses)

Experimental Endpoint: When USE_EXPERIMENTAL_ENDPOINT=true, the client automatically captures and uses the experimental endpoint URL from the server's x-ms-d2e-experimental response header. This feature:

  • Only activates when direct_connect_url is not already set
  • Captures the URL from the first response and stores it for all subsequent requests
  • Provides access to pre-release features and performance optimizations
  • Useful for testing new capabilities before general availability

Diagnostic Logging: When ENABLE_DIAGNOSTICS=true or enable_diagnostics=True, the client will log detailed HTTP request and response information including:

  • Request URLs before sending
  • All response headers with their values
  • Error messages for failed requests

This is useful for debugging connection issues, authentication problems, or understanding the communication flow with Copilot Studio. Diagnostic logs use Python's standard logging module at the DEBUG level.

Using Environment Variables in Code

The ConnectionSettings.populate_from_environment() helper method automatically loads these variables:

from microsoft_agents.copilotstudio.client import ConnectionSettings

# Automatically loads from environment variables
settings_dict = ConnectionSettings.populate_from_environment()
settings = ConnectionSettings(**settings_dict)

Features

Core Capabilities

Real-time streaming - Server-sent events for live responses ✅ Multi-cloud support - Works across all Power Platform clouds (PROD, GOV, HIGH, DOD, MOONCAKE, etc.) ✅ Rich content - Support for cards, actions, and attachments ✅ Conversation management - Maintain context across interactions ✅ Custom activities - Send structured data to agents ✅ Async/await - Modern Python async support

Advanced Features

DirectConnect URLs - Simplified connection with direct bot URLs ✅ Locale support - Specify conversation language with StartRequestEvent subscription - Subscribe to conversation events with SSE resumption ✅ Multiple connection modes - Environment-based or DirectConnect URL ✅ Token audience resolution - Automatic cloud detection from URLs ✅ User-Agent tracking - Automatic SDK version and platform headers ✅ Environment configuration - Automatic loading from environment variables ✅ Experimental endpoints - Toggle experimental API features ✅ Diagnostic logging - HTTP request/response logging for debugging and troubleshooting

API Methods

Method Description
start_conversation() Start a new conversation with basic options
start_conversation_with_request() Start with advanced options (locale, custom conversation ID)
ask_question() Send a text question to the agent
ask_question_with_activity() Send a custom Activity object
send_activity() Send any activity (alias for ask_question_with_activity)
execute() Execute an activity with explicit conversation ID
subscribe() Subscribe to conversation events with resumption support

Configuration Models

Class Description
ConnectionSettings Main configuration class with all connection options
StartRequest Advanced start options (locale, conversation ID)
SubscribeEvent Event wrapper with activity and SSE event ID
PowerPlatformCloud Enum for cloud environments
AgentType Enum for agent types (PUBLISHED, PREBUILT)
UserAgentHelper Utility for generating user-agent headers

Connection Modes

The client supports two connection modes:

1. Environment-Based Connection (Standard)

Uses environment ID and agent identifier to construct the connection URL:

settings = ConnectionSettings(
    environment_id="aaaabbbb-1111-2222-3333-ccccddddeeee",
    agent_identifier="cr123_myagent"
)

URL Pattern: https://{env-prefix}.{env-suffix}.environment.api.powerplatform.com/copilotstudio/dataverse-backed/authenticated/bots/{agent-id}/conversations

2. DirectConnect URL Mode (Simplified)

Uses a direct URL to the agent, bypassing environment resolution:

settings = ConnectionSettings(
    environment_id="",
    agent_identifier="",
    direct_connect_url="https://api.powerplatform.com/copilotstudio/dataverse-backed/authenticated/bots/cr123_myagent"
)

Benefits:

  • Simpler configuration with single URL
  • Automatic cloud detection for token audience
  • Works across environments without environment ID lookup
  • Useful for multi-tenant scenarios

Token Audience Resolution

The client automatically determines the correct token audience:

# For environment-based connections
audience = PowerPlatformEnvironment.get_token_audience(settings)
# Returns: https://api.powerplatform.com/.default

# For DirectConnect URLs
audience = PowerPlatformEnvironment.get_token_audience(
    settings=ConnectionSettings("", "", direct_connect_url="https://api.gov.powerplatform.microsoft.us/...")
)
# Returns: https://api.gov.powerplatform.microsoft.us/.default

Troubleshooting

Common Issues

Authentication failed

  • Verify your app is registered in Azure AD
  • Check that token has the correct audience scope (use PowerPlatformEnvironment.get_token_audience())
  • Ensure your app has permissions to the Power Platform environment
  • For DirectConnect URLs, verify cloud setting matches the URL domain

Agent not found

  • Verify the environment ID and agent identifier
  • Check that the agent is published and accessible
  • Confirm you're using the correct cloud setting
  • For DirectConnect URLs, ensure the URL is correct and complete

Connection timeout

  • Check network connectivity to Power Platform
  • Verify firewall settings allow HTTPS traffic
  • Try a different cloud region if available
  • Check if client_session_settings timeout is appropriate

Invalid DirectConnect URL

  • Ensure URL includes scheme (https://)
  • Verify URL format matches expected pattern
  • Check for trailing slashes (automatically normalized)
  • Confirm URL points to the correct cloud environment

Requirements

  • Python 3.10+ (supports 3.10, 3.11, 3.12, 3.13, 3.14)
  • Valid Azure AD app registration
  • Access to Microsoft Power Platform environment
  • Published Copilot Studio agent

Quick Links

Sample Applications

Name Description README
Quickstart Simplest agent Quickstart
Auto Sign In Simple OAuth agent using Graph and GitHub auto-signin
OBO Authorization OBO flow to access a Copilot Studio Agent obo-authorization
Semantic Kernel Integration A weather agent built with Semantic Kernel semantic-kernel-multiturn
Streaming Agent Streams OpenAI responses azure-ai-streaming
Copilot Studio Client Console app to consume a Copilot Studio Agent copilotstudio-client
Cards Agent Agent that uses rich cards to enhance conversation design cards
1.3.0 Jul 30, 2026
1.2.0 Jul 20, 2026
1.2.0.dev20 Jul 14, 2026
1.2.0.dev16 Jul 11, 2026
1.2.0.dev10 Jul 10, 2026
1.2.0.dev9 Jul 09, 2026
1.2.0.dev7 Jul 08, 2026
1.2.0.dev5 Jul 07, 2026
1.2.0.dev4 Jun 24, 2026
1.2.0.dev1 Jun 23, 2026
1.2.0.dev0 Jun 20, 2026
1.1.0 Jun 19, 2026
1.1.0.dev9 Jun 19, 2026
1.1.0.dev8 Jun 18, 2026
1.1.0.dev7 Jun 16, 2026
1.1.0.dev1 Jun 03, 2026
1.1.0.dev0 May 23, 2026
1.0.0 May 22, 2026
0.10.0.dev9 May 22, 2026
0.10.0.dev8 May 20, 2026
0.10.0.dev7 May 19, 2026
0.10.0.dev6 May 15, 2026
0.10.0.dev5 May 13, 2026
0.10.0.dev4 May 02, 2026
0.10.0.dev3 Apr 30, 2026
0.10.0.dev2 Apr 29, 2026
0.10.0.dev1 Apr 17, 2026
0.10.0.dev0 Apr 16, 2026
0.9.1 May 04, 2026
0.9.0 Apr 15, 2026
0.9.0.dev11 Apr 15, 2026
0.9.0.dev10 Apr 11, 2026
0.9.0.dev9 Apr 08, 2026
0.9.0.dev8 Apr 04, 2026
0.9.0.dev7 Apr 03, 2026
0.9.0.dev6 Apr 02, 2026
0.9.0.dev5 Apr 01, 2026
0.9.0.dev4 Mar 27, 2026
0.9.0.dev3 Mar 24, 2026
0.9.0.dev2 Mar 17, 2026
0.9.0.dev1 Feb 25, 2026
0.8.0 Feb 24, 2026
0.8.0.dev4 Feb 18, 2026
0.8.0.dev3 Feb 12, 2026
0.8.0.dev2 Feb 05, 2026
0.8.0.dev0 Feb 04, 2026
0.7.0 Jan 21, 2026
0.7.0.dev16 Feb 04, 2026
0.7.0.dev12 Dec 17, 2025
0.7.0.dev10 Dec 09, 2025
0.7.0.dev8 Dec 03, 2025
0.7.0.dev6 Dec 02, 2025
0.7.0.dev4 Nov 27, 2025
0.7.0.dev1 Nov 21, 2025
0.7.0.dev0 Nov 19, 2025
0.6.1 Dec 01, 2025
0.6.0 Nov 18, 2025
0.6.0.dev17 Nov 15, 2025
0.6.0.dev16 Nov 14, 2025
0.6.0.dev15 Nov 13, 2025
0.6.0.dev11 Nov 12, 2025
0.6.0.dev10 Nov 06, 2025
0.6.0.dev9 Nov 01, 2025
0.6.0.dev8 Oct 31, 2025
0.6.0.dev7 Oct 29, 2025
0.6.0.dev4 Oct 28, 2025
0.6.0.dev1 Oct 23, 2025
0.5.3 Oct 31, 2025
0.5.2 Oct 31, 2025
0.5.1 Oct 28, 2025
0.5.0 Oct 22, 2025
0.5.0.dev19 Oct 22, 2025
0.5.0.dev17 Oct 21, 2025
0.5.0.dev11 Oct 16, 2025
0.5.0.dev10 Oct 15, 2025
0.5.0.dev7 Oct 14, 2025
0.5.0.dev5 Oct 11, 2025
0.5.0.dev3 Oct 09, 2025
0.4.0 Oct 07, 2025
0.4.0.dev18 Oct 08, 2025
0.4.0.dev16 Oct 07, 2025
0.4.0.dev14 Oct 03, 2025
0.4.0.dev10 Oct 02, 2025
0.4.0.dev7 Sep 11, 2025
0.4.0.dev6 Sep 10, 2025
0.4.0.dev4 Sep 09, 2025
0.4.0.dev3 Sep 05, 2025
0.4.0.dev1 Aug 28, 2025
0.3.2 Sep 17, 2025
0.3.1 Sep 09, 2025
0.3.0 Aug 27, 2025
0.3.0.dev0 Aug 19, 2025
0.2.0 Aug 18, 2025
0.2.0.dev1 Aug 15, 2025
0.1.2 Aug 12, 2025
0.1.1 Jul 28, 2025
0.0.0 Jul 25, 2025
Extras: None
Dependencies:
microsoft-agents-hosting-core (==1.3.0)