microsoft-agents-copilotstudio-client 0.8.0.dev3__tar.gz → 0.9.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. microsoft_agents_copilotstudio_client-0.9.0.dev1/PKG-INFO +485 -0
  2. microsoft_agents_copilotstudio_client-0.9.0.dev1/VERSION.txt +1 -0
  3. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents/copilotstudio/client/__init__.py +12 -0
  4. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents/copilotstudio/client/connection_settings.py +135 -0
  5. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents/copilotstudio/client/copilot_client.py +326 -0
  6. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents/copilotstudio/client/copilot_client_protocol.py +91 -0
  7. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents/copilotstudio/client/power_platform_environment.py +358 -0
  8. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents/copilotstudio/client/start_request.py +26 -0
  9. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents/copilotstudio/client/subscribe_event.py +21 -0
  10. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents/copilotstudio/client/subscribe_request.py +12 -0
  11. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents/copilotstudio/client/subscribe_response.py +12 -0
  12. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents/copilotstudio/client/user_agent_helper.py +53 -0
  13. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents_copilotstudio_client.egg-info/PKG-INFO +485 -0
  14. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents_copilotstudio_client.egg-info/SOURCES.txt +6 -0
  15. microsoft_agents_copilotstudio_client-0.9.0.dev1/microsoft_agents_copilotstudio_client.egg-info/requires.txt +1 -0
  16. microsoft_agents_copilotstudio_client-0.9.0.dev1/readme.md +464 -0
  17. microsoft_agents_copilotstudio_client-0.8.0.dev3/PKG-INFO +0 -211
  18. microsoft_agents_copilotstudio_client-0.8.0.dev3/VERSION.txt +0 -1
  19. microsoft_agents_copilotstudio_client-0.8.0.dev3/microsoft_agents/copilotstudio/client/connection_settings.py +0 -48
  20. microsoft_agents_copilotstudio_client-0.8.0.dev3/microsoft_agents/copilotstudio/client/copilot_client.py +0 -147
  21. microsoft_agents_copilotstudio_client-0.8.0.dev3/microsoft_agents/copilotstudio/client/power_platform_environment.py +0 -154
  22. microsoft_agents_copilotstudio_client-0.8.0.dev3/microsoft_agents_copilotstudio_client.egg-info/PKG-INFO +0 -211
  23. microsoft_agents_copilotstudio_client-0.8.0.dev3/microsoft_agents_copilotstudio_client.egg-info/requires.txt +0 -1
  24. microsoft_agents_copilotstudio_client-0.8.0.dev3/readme.md +0 -190
  25. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/LICENSE +0 -0
  26. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/MANIFEST.in +0 -0
  27. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents/copilotstudio/client/agent_type.py +0 -0
  28. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents/copilotstudio/client/direct_to_engine_connection_settings_protocol.py +0 -0
  29. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents/copilotstudio/client/errors/__init__.py +0 -0
  30. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents/copilotstudio/client/errors/error_resources.py +0 -0
  31. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents/copilotstudio/client/execute_turn_request.py +0 -0
  32. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents/copilotstudio/client/power_platform_cloud.py +0 -0
  33. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents_copilotstudio_client.egg-info/dependency_links.txt +0 -0
  34. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/microsoft_agents_copilotstudio_client.egg-info/top_level.txt +0 -0
  35. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/pyproject.toml +0 -0
  36. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/setup.cfg +0 -0
  37. {microsoft_agents_copilotstudio_client-0.8.0.dev3 → microsoft_agents_copilotstudio_client-0.9.0.dev1}/setup.py +0 -0
@@ -0,0 +1,485 @@
1
+ Metadata-Version: 2.4
2
+ Name: microsoft-agents-copilotstudio-client
3
+ Version: 0.9.0.dev1
4
+ Summary: A client library for Microsoft Agents
5
+ Author: Microsoft Corporation
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/microsoft/Agents
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Operating System :: OS Independent
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: microsoft-agents-hosting-core==0.9.0.dev1
19
+ Dynamic: license-file
20
+ Dynamic: requires-dist
21
+
22
+ # Microsoft Agents Copilot Studio Client
23
+
24
+ [![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/)
25
+
26
+ 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.
27
+
28
+ 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.
29
+
30
+ # What is this?
31
+ 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.
32
+
33
+ ## Release Notes
34
+ <table style="width:100%">
35
+ <tr>
36
+ <th style="width:20%">Version</th>
37
+ <th style="width:20%">Date</th>
38
+ <th style="width:60%">Release Notes</th>
39
+ </tr>
40
+ <tr>
41
+ <td>0.8.0</td>
42
+ <td>2026-02-23</td>
43
+ <td>
44
+ <a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v080">
45
+ 0.8.0 Release Notes
46
+ </a>
47
+ </td>
48
+ </tr>
49
+ <tr>
50
+ <td>0.7.0</td>
51
+ <td>2026-01-21</td>
52
+ <td>
53
+ <a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v070">
54
+ 0.7.0 Release Notes
55
+ </a>
56
+ </td>
57
+ </tr>
58
+ <tr>
59
+ <td>0.6.1</td>
60
+ <td>2025-12-01</td>
61
+ <td>
62
+ <a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v061">
63
+ 0.6.1 Release Notes
64
+ </a>
65
+ </td>
66
+ </tr>
67
+ <tr>
68
+ <td>0.6.0</td>
69
+ <td>2025-11-18</td>
70
+ <td>
71
+ <a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v060">
72
+ 0.6.0 Release Notes
73
+ </a>
74
+ </td>
75
+ </tr>
76
+ <tr>
77
+ <td>0.5.0</td>
78
+ <td>2025-10-22</td>
79
+ <td>
80
+ <a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v050">
81
+ 0.5.0 Release Notes
82
+ </a>
83
+ </td>
84
+ </tr>
85
+ </table>
86
+
87
+ ## Packages Overview
88
+
89
+ We offer the following PyPI packages to create conversational experiences based on Agents:
90
+
91
+ | Package Name | PyPI Version | Description |
92
+ |--------------|-------------|-------------|
93
+ | `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
94
+ | `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
95
+ | `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
96
+ | `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. |
97
+ | `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
98
+ | `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
99
+ | `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
100
+
101
+ Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
102
+
103
+ | Package Name | PyPI Version | Description |
104
+ |--------------|-------------|-------------|
105
+ | `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio |
106
+
107
+
108
+ ## Installation
109
+
110
+ ```bash
111
+ pip install microsoft-agents-copilotstudio-client
112
+ ```
113
+
114
+ ## Quick Start
115
+
116
+ ### Basic Setup
117
+
118
+ #### Standard Environment-Based Connection
119
+
120
+ Code below from the [main.py in the Copilot Studio Client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/src/main.py)
121
+ ```python
122
+ def create_client():
123
+ settings = ConnectionSettings(
124
+ environment_id=environ.get("COPILOTSTUDIOAGENT__ENVIRONMENTID"),
125
+ agent_identifier=environ.get("COPILOTSTUDIOAGENT__SCHEMANAME"),
126
+ cloud=None,
127
+ copilot_agent_type=None,
128
+ custom_power_platform_cloud=None,
129
+ )
130
+ token = acquire_token(
131
+ settings,
132
+ app_client_id=environ.get("COPILOTSTUDIOAGENT__AGENTAPPID"),
133
+ tenant_id=environ.get("COPILOTSTUDIOAGENT__TENANTID"),
134
+ )
135
+ copilot_client = CopilotClient(settings, token)
136
+ return copilot_client
137
+ ```
138
+
139
+ #### DirectConnect URL Mode (Simplified Setup)
140
+
141
+ For simplified setup, you can use a DirectConnect URL instead of environment-based configuration:
142
+
143
+ ```python
144
+ def create_client_direct():
145
+ settings = ConnectionSettings(
146
+ environment_id="", # Not needed with DirectConnect URL
147
+ agent_identifier="", # Not needed with DirectConnect URL
148
+ direct_connect_url="https://api.powerplatform.com/copilotstudio/dataverse-backed/authenticated/bots/your-bot-id"
149
+ )
150
+ token = acquire_token(...)
151
+ copilot_client = CopilotClient(settings, token)
152
+ return copilot_client
153
+ ```
154
+
155
+ #### Advanced Configuration Options
156
+
157
+ ```python
158
+ settings = ConnectionSettings(
159
+ environment_id="your-env-id",
160
+ agent_identifier="your-agent-id",
161
+ cloud=PowerPlatformCloud.PROD,
162
+ copilot_agent_type=AgentType.PUBLISHED,
163
+ custom_power_platform_cloud=None,
164
+ direct_connect_url=None, # Optional: Direct URL to agent
165
+ use_experimental_endpoint=False, # Optional: Enable experimental features
166
+ enable_diagnostics=False, # Optional: Enable diagnostic logging (logs HTTP details)
167
+ client_session_settings={"timeout": aiohttp.ClientTimeout(total=60)} # Optional: aiohttp settings
168
+ )
169
+ ```
170
+
171
+ **Diagnostic Logging Details**:
172
+ When `enable_diagnostics=True`, the CopilotClient logs detailed HTTP communication using Python's `logging` module at the `DEBUG` level:
173
+ - Pre-request: Logs the full request URL (`>>> SEND TO {url}`)
174
+ - Post-response: Logs all HTTP response headers in a formatted table
175
+ - Errors: Logs error messages with status codes
176
+
177
+ To see diagnostic output, configure your Python logging:
178
+ ```python
179
+ import logging
180
+ logging.basicConfig(level=logging.DEBUG)
181
+ ```
182
+
183
+ **Experimental Endpoint Details**:
184
+ When `use_experimental_endpoint=True`, the CopilotClient will automatically capture and use the experimental endpoint URL from the first response:
185
+ - The server returns the experimental endpoint in the `x-ms-d2e-experimental` response header
186
+ - Once captured, this URL is stored in `settings.direct_connect_url` and used for all subsequent requests
187
+ - This feature is only active when `use_experimental_endpoint=True` AND `direct_connect_url` is not already set
188
+ - The experimental endpoint allows access to pre-release features and optimizations
189
+
190
+ ### Start a Conversation
191
+
192
+ #### Simple Start
193
+
194
+ The code below is summarized from the [main.py in the Copilot Studio Client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/src/main.py). See that sample for complete & working code.
195
+
196
+ ```python
197
+ copilot_client = create_client()
198
+ async for activity in copilot_client.start_conversation(emit_start_conversation_event=True):
199
+ if activity.type == ActivityTypes.message:
200
+ print(f"\n{activity.text}")
201
+
202
+ # Ask questions
203
+ async for reply in copilot_client.ask_question("Who are you?", conversation_id):
204
+ if reply.type == ActivityTypes.message:
205
+ print(f"\n{reply.text}")
206
+ ```
207
+
208
+ #### Start with Advanced Options (Locale Support)
209
+
210
+ ```python
211
+ from microsoft_agents.copilotstudio.client import StartRequest
212
+
213
+ # Create a start request with locale
214
+ start_request = StartRequest(
215
+ emit_start_conversation_event=True,
216
+ locale="en-US", # Optional: specify conversation locale
217
+ conversation_id="custom-conv-id" # Optional: provide your own conversation ID
218
+ )
219
+
220
+ async for activity in copilot_client.start_conversation_with_request(start_request):
221
+ if activity.type == ActivityTypes.message:
222
+ print(f"\n{activity.text}")
223
+ ```
224
+
225
+ ### Send Activities
226
+
227
+ #### Send a Custom Activity
228
+
229
+ ```python
230
+ from microsoft_agents.activity import Activity
231
+
232
+ activity = Activity(
233
+ type="message",
234
+ text="Hello, agent!",
235
+ conversation={"id": conversation_id}
236
+ )
237
+
238
+ async for reply in copilot_client.send_activity(activity):
239
+ print(f"Response: {reply.text}")
240
+ ```
241
+
242
+ #### Execute with Explicit Conversation ID
243
+
244
+ ```python
245
+ # Execute an activity with a specific conversation ID
246
+ activity = Activity(type="message", text="What's the weather?")
247
+
248
+ async for reply in copilot_client.execute(conversation_id="conv-123", activity=activity):
249
+ print(f"Response: {reply.text}")
250
+ ```
251
+
252
+ ### Subscribe to Conversation Events
253
+
254
+ For real-time event streaming with resumption support:
255
+
256
+ ```python
257
+ from microsoft_agents.copilotstudio.client import SubscribeEvent
258
+
259
+ # Subscribe to conversation events
260
+ async for subscribe_event in copilot_client.subscribe(
261
+ conversation_id="conv-123",
262
+ last_received_event_id=None # Optional: resume from last event
263
+ ):
264
+ activity = subscribe_event.activity
265
+ event_id = subscribe_event.event_id # Use for resumption
266
+
267
+ if activity.type == ActivityTypes.message:
268
+ print(f"[{event_id}] {activity.text}")
269
+ ```
270
+
271
+ ### Environment Variables
272
+
273
+ Set up your `.env` file with the following options:
274
+
275
+ #### Standard Environment-Based Configuration
276
+
277
+ ```bash
278
+ # Required (unless using DIRECT_CONNECT_URL)
279
+ ENVIRONMENT_ID=your-power-platform-environment-id
280
+ AGENT_IDENTIFIER=your-copilot-studio-agent-id
281
+ APP_CLIENT_ID=your-azure-app-client-id
282
+ TENANT_ID=your-azure-tenant-id
283
+
284
+ # Optional Cloud Configuration
285
+ CLOUD=PROD # Options: PROD, GOV, HIGH, DOD, MOONCAKE, DEV, TEST, etc.
286
+ COPILOT_AGENT_TYPE=PUBLISHED # Options: PUBLISHED, PREBUILT
287
+ CUSTOM_POWER_PLATFORM_CLOUD=https://custom.cloud.com
288
+ ```
289
+
290
+ #### DirectConnect URL Configuration (Alternative)
291
+
292
+ ```bash
293
+ # Required for DirectConnect mode
294
+ DIRECT_CONNECT_URL=https://api.powerplatform.com/copilotstudio/dataverse-backed/authenticated/bots/your-bot-id
295
+ APP_CLIENT_ID=your-azure-app-client-id
296
+ TENANT_ID=your-azure-tenant-id
297
+
298
+ # Optional
299
+ CLOUD=PROD # Used for token audience resolution
300
+ ```
301
+
302
+ #### Advanced Options
303
+
304
+ ```bash
305
+ # Experimental and diagnostic features
306
+ USE_EXPERIMENTAL_ENDPOINT=false # Enable automatic experimental endpoint capture
307
+ ENABLE_DIAGNOSTICS=false # Enable diagnostic logging (logs HTTP requests/responses)
308
+ ```
309
+
310
+ **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:
311
+ - Only activates when `direct_connect_url` is not already set
312
+ - Captures the URL from the first response and stores it for all subsequent requests
313
+ - Provides access to pre-release features and performance optimizations
314
+ - Useful for testing new capabilities before general availability
315
+
316
+ **Diagnostic Logging**: When `ENABLE_DIAGNOSTICS=true` or `enable_diagnostics=True`, the client will log detailed HTTP request and response information including:
317
+ - Request URLs before sending
318
+ - All response headers with their values
319
+ - Error messages for failed requests
320
+
321
+ 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.
322
+
323
+ #### Using Environment Variables in Code
324
+
325
+ The `ConnectionSettings.populate_from_environment()` helper method automatically loads these variables:
326
+
327
+ ```python
328
+ from microsoft_agents.copilotstudio.client import ConnectionSettings
329
+
330
+ # Automatically loads from environment variables
331
+ settings_dict = ConnectionSettings.populate_from_environment()
332
+ settings = ConnectionSettings(**settings_dict)
333
+ ```
334
+
335
+ ## Features
336
+
337
+ ### Core Capabilities
338
+
339
+ ✅ **Real-time streaming** - Server-sent events for live responses
340
+ ✅ **Multi-cloud support** - Works across all Power Platform clouds (PROD, GOV, HIGH, DOD, MOONCAKE, etc.)
341
+ ✅ **Rich content** - Support for cards, actions, and attachments
342
+ ✅ **Conversation management** - Maintain context across interactions
343
+ ✅ **Custom activities** - Send structured data to agents
344
+ ✅ **Async/await** - Modern Python async support
345
+
346
+ ### Advanced Features
347
+
348
+ ✅ **DirectConnect URLs** - Simplified connection with direct bot URLs
349
+ ✅ **Locale support** - Specify conversation language with `StartRequest`
350
+ ✅ **Event subscription** - Subscribe to conversation events with SSE resumption
351
+ ✅ **Multiple connection modes** - Environment-based or DirectConnect URL
352
+ ✅ **Token audience resolution** - Automatic cloud detection from URLs
353
+ ✅ **User-Agent tracking** - Automatic SDK version and platform headers
354
+ ✅ **Environment configuration** - Automatic loading from environment variables
355
+ ✅ **Experimental endpoints** - Toggle experimental API features
356
+ ✅ **Diagnostic logging** - HTTP request/response logging for debugging and troubleshooting
357
+
358
+ ### API Methods
359
+
360
+ | Method | Description |
361
+ |--------|-------------|
362
+ | `start_conversation()` | Start a new conversation with basic options |
363
+ | `start_conversation_with_request()` | Start with advanced options (locale, custom conversation ID) |
364
+ | `ask_question()` | Send a text question to the agent |
365
+ | `ask_question_with_activity()` | Send a custom Activity object |
366
+ | `send_activity()` | Send any activity (alias for ask_question_with_activity) |
367
+ | `execute()` | Execute an activity with explicit conversation ID |
368
+ | `subscribe()` | Subscribe to conversation events with resumption support |
369
+
370
+ ### Configuration Models
371
+
372
+ | Class | Description |
373
+ |-------|-------------|
374
+ | `ConnectionSettings` | Main configuration class with all connection options |
375
+ | `StartRequest` | Advanced start options (locale, conversation ID) |
376
+ | `SubscribeEvent` | Event wrapper with activity and SSE event ID |
377
+ | `PowerPlatformCloud` | Enum for cloud environments |
378
+ | `AgentType` | Enum for agent types (PUBLISHED, PREBUILT) |
379
+ | `UserAgentHelper` | Utility for generating user-agent headers |
380
+
381
+ ## Connection Modes
382
+
383
+ The client supports two connection modes:
384
+
385
+ ### 1. Environment-Based Connection (Standard)
386
+
387
+ Uses environment ID and agent identifier to construct the connection URL:
388
+
389
+ ```python
390
+ settings = ConnectionSettings(
391
+ environment_id="aaaabbbb-1111-2222-3333-ccccddddeeee",
392
+ agent_identifier="cr123_myagent"
393
+ )
394
+ ```
395
+
396
+ **URL Pattern:**
397
+ `https://{env-prefix}.{env-suffix}.environment.api.powerplatform.com/copilotstudio/dataverse-backed/authenticated/bots/{agent-id}/conversations`
398
+
399
+ ### 2. DirectConnect URL Mode (Simplified)
400
+
401
+ Uses a direct URL to the agent, bypassing environment resolution:
402
+
403
+ ```python
404
+ settings = ConnectionSettings(
405
+ environment_id="",
406
+ agent_identifier="",
407
+ direct_connect_url="https://api.powerplatform.com/copilotstudio/dataverse-backed/authenticated/bots/cr123_myagent"
408
+ )
409
+ ```
410
+
411
+ **Benefits:**
412
+ - Simpler configuration with single URL
413
+ - Automatic cloud detection for token audience
414
+ - Works across environments without environment ID lookup
415
+ - Useful for multi-tenant scenarios
416
+
417
+ ## Token Audience Resolution
418
+
419
+ The client automatically determines the correct token audience:
420
+
421
+ ```python
422
+ # For environment-based connections
423
+ audience = PowerPlatformEnvironment.get_token_audience(settings)
424
+ # Returns: https://api.powerplatform.com/.default
425
+
426
+ # For DirectConnect URLs
427
+ audience = PowerPlatformEnvironment.get_token_audience(
428
+ settings=ConnectionSettings("", "", direct_connect_url="https://api.gov.powerplatform.microsoft.us/...")
429
+ )
430
+ # Returns: https://api.gov.powerplatform.microsoft.us/.default
431
+ ```
432
+
433
+ ## Troubleshooting
434
+
435
+ ### Common Issues
436
+
437
+ **Authentication failed**
438
+ - Verify your app is registered in Azure AD
439
+ - Check that token has the correct audience scope (use `PowerPlatformEnvironment.get_token_audience()`)
440
+ - Ensure your app has permissions to the Power Platform environment
441
+ - For DirectConnect URLs, verify cloud setting matches the URL domain
442
+
443
+ **Agent not found**
444
+ - Verify the environment ID and agent identifier
445
+ - Check that the agent is published and accessible
446
+ - Confirm you're using the correct cloud setting
447
+ - For DirectConnect URLs, ensure the URL is correct and complete
448
+
449
+ **Connection timeout**
450
+ - Check network connectivity to Power Platform
451
+ - Verify firewall settings allow HTTPS traffic
452
+ - Try a different cloud region if available
453
+ - Check if `client_session_settings` timeout is appropriate
454
+
455
+ **Invalid DirectConnect URL**
456
+ - Ensure URL includes scheme (https://)
457
+ - Verify URL format matches expected pattern
458
+ - Check for trailing slashes (automatically normalized)
459
+ - Confirm URL points to the correct cloud environment
460
+
461
+ ## Requirements
462
+
463
+ - Python 3.10+ (supports 3.10, 3.11, 3.12, 3.13, 3.14)
464
+ - Valid Azure AD app registration
465
+ - Access to Microsoft Power Platform environment
466
+ - Published Copilot Studio agent
467
+
468
+ # Quick Links
469
+
470
+ - 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
471
+ - 📖 [Complete Documentation](https://aka.ms/agents)
472
+ - 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
473
+ - 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
474
+
475
+ # Sample Applications
476
+
477
+ |Name|Description|README|
478
+ |----|----|----|
479
+ |Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)|
480
+ |Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)|
481
+ |OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)|
482
+ |Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)|
483
+ |Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)|
484
+ |Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)|
485
+ |Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)|
@@ -4,19 +4,31 @@
4
4
  from .agent_type import AgentType
5
5
  from .connection_settings import ConnectionSettings
6
6
  from .copilot_client import CopilotClient
7
+ from .copilot_client_protocol import CopilotClientProtocol
7
8
  from .direct_to_engine_connection_settings_protocol import (
8
9
  DirectToEngineConnectionSettingsProtocol,
9
10
  )
10
11
  from .execute_turn_request import ExecuteTurnRequest
11
12
  from .power_platform_cloud import PowerPlatformCloud
12
13
  from .power_platform_environment import PowerPlatformEnvironment
14
+ from .start_request import StartRequest
15
+ from .subscribe_event import SubscribeEvent
16
+ from .subscribe_request import SubscribeRequest
17
+ from .subscribe_response import SubscribeResponse
18
+ from .user_agent_helper import UserAgentHelper
13
19
 
14
20
  __all__ = [
15
21
  "AgentType",
16
22
  "ConnectionSettings",
17
23
  "CopilotClient",
24
+ "CopilotClientProtocol",
18
25
  "DirectToEngineConnectionSettingsProtocol",
19
26
  "ExecuteTurnRequest",
20
27
  "PowerPlatformCloud",
21
28
  "PowerPlatformEnvironment",
29
+ "StartRequest",
30
+ "SubscribeEvent",
31
+ "SubscribeRequest",
32
+ "SubscribeResponse",
33
+ "UserAgentHelper",
22
34
  ]
@@ -0,0 +1,135 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ from os import environ
5
+ from typing import Dict, Optional, Any
6
+ from .direct_to_engine_connection_settings_protocol import (
7
+ DirectToEngineConnectionSettingsProtocol,
8
+ )
9
+ from .power_platform_cloud import PowerPlatformCloud
10
+ from .agent_type import AgentType
11
+
12
+
13
+ class ConnectionSettings(DirectToEngineConnectionSettingsProtocol):
14
+ """
15
+ Connection settings for the DirectToEngineConnectionConfiguration.
16
+ """
17
+
18
+ def __init__(
19
+ self,
20
+ environment_id: str,
21
+ agent_identifier: str,
22
+ cloud: Optional[PowerPlatformCloud] = None,
23
+ copilot_agent_type: Optional[AgentType] = None,
24
+ custom_power_platform_cloud: Optional[str] = None,
25
+ client_session_settings: Optional[dict] = None,
26
+ direct_connect_url: Optional[str] = None,
27
+ use_experimental_endpoint: bool = False,
28
+ enable_diagnostics: bool = False,
29
+ ) -> None:
30
+ """Initialize connection settings.
31
+
32
+ :param environment_id: The ID of the environment to connect to.
33
+ :param agent_identifier: The identifier of the agent to use for the connection.
34
+ :param cloud: The PowerPlatformCloud to use for the connection.
35
+ :param copilot_agent_type: The AgentType to use for the Copilot.
36
+ :param custom_power_platform_cloud: The custom PowerPlatformCloud URL.
37
+ :param client_session_settings: Additional arguments for initialization
38
+ of the underlying Aiohttp ClientSession.
39
+ :param direct_connect_url: Direct connection URL override.
40
+ :param use_experimental_endpoint: Flag to enable experimental endpoint.
41
+ :param enable_diagnostics: Flag to enable diagnostics.
42
+ """
43
+
44
+ self.environment_id = environment_id
45
+ self.agent_identifier = agent_identifier
46
+
47
+ if not self.environment_id and not direct_connect_url:
48
+ raise ValueError("Environment ID or Direct Connect URL must be provided")
49
+ if not self.agent_identifier and not direct_connect_url:
50
+ raise ValueError("Agent Identifier or Direct Connect URL must be provided")
51
+
52
+ self.cloud = cloud or PowerPlatformCloud.PROD
53
+ self.copilot_agent_type = copilot_agent_type or AgentType.PUBLISHED
54
+ self.custom_power_platform_cloud = custom_power_platform_cloud
55
+ self.client_session_settings = client_session_settings or {}
56
+ self.direct_connect_url = direct_connect_url
57
+ self.use_experimental_endpoint = use_experimental_endpoint
58
+ self.enable_diagnostics = enable_diagnostics
59
+
60
+ @staticmethod
61
+ def populate_from_environment(
62
+ environment_id: Optional[str] = None,
63
+ agent_identifier: Optional[str] = None,
64
+ cloud: Optional[PowerPlatformCloud] = None,
65
+ copilot_agent_type: Optional[AgentType] = None,
66
+ custom_power_platform_cloud: Optional[str] = None,
67
+ direct_connect_url: Optional[str] = None,
68
+ use_experimental_endpoint: Optional[bool] = None,
69
+ enable_diagnostics: Optional[bool] = None,
70
+ ) -> Dict[str, Any]:
71
+ """
72
+ Populate connection settings from environment variables.
73
+
74
+ This method reads configuration values from environment variables
75
+ and returns them as a dictionary suitable for passing to ConnectionSettings.__init__().
76
+
77
+ :param environment_id: Optional override for ENVIRONMENT_ID env var.
78
+ :param agent_identifier: Optional override for AGENT_IDENTIFIER env var.
79
+ :param cloud: Optional override for CLOUD env var.
80
+ :param copilot_agent_type: Optional override for COPILOT_AGENT_TYPE env var.
81
+ :param custom_power_platform_cloud: Optional override for CUSTOM_POWER_PLATFORM_CLOUD env var.
82
+ :param direct_connect_url: Optional override for DIRECT_CONNECT_URL env var.
83
+ :param use_experimental_endpoint: Optional override for USE_EXPERIMENTAL_ENDPOINT env var.
84
+ :param enable_diagnostics: Optional override for ENABLE_DIAGNOSTICS env var.
85
+ :return: Dictionary of connection settings.
86
+ """
87
+ # Read from environment variables with provided overrides
88
+ env_id = environment_id or environ.get("ENVIRONMENT_ID", "")
89
+ agent_id = agent_identifier or environ.get("AGENT_IDENTIFIER", "")
90
+
91
+ # Handle cloud enum
92
+ cloud_value = cloud
93
+ if cloud_value is None:
94
+ cloud_str = environ.get("CLOUD", "PROD")
95
+ try:
96
+ cloud_value = PowerPlatformCloud[cloud_str]
97
+ except KeyError:
98
+ cloud_value = PowerPlatformCloud.PROD
99
+
100
+ # Handle copilot agent type enum
101
+ agent_type_value = copilot_agent_type
102
+ if agent_type_value is None:
103
+ agent_type_str = environ.get("COPILOT_AGENT_TYPE", "PUBLISHED")
104
+ try:
105
+ agent_type_value = AgentType[agent_type_str]
106
+ except KeyError:
107
+ agent_type_value = AgentType.PUBLISHED
108
+
109
+ # Handle other settings
110
+ custom_cloud = custom_power_platform_cloud or environ.get(
111
+ "CUSTOM_POWER_PLATFORM_CLOUD", None
112
+ )
113
+ direct_url = direct_connect_url or environ.get("DIRECT_CONNECT_URL", None)
114
+
115
+ # Handle boolean flags
116
+ exp_endpoint = use_experimental_endpoint
117
+ if exp_endpoint is None:
118
+ exp_endpoint = (
119
+ environ.get("USE_EXPERIMENTAL_ENDPOINT", "false").lower() == "true"
120
+ )
121
+
122
+ diagnostics = enable_diagnostics
123
+ if diagnostics is None:
124
+ diagnostics = environ.get("ENABLE_DIAGNOSTICS", "false").lower() == "true"
125
+
126
+ return {
127
+ "environment_id": env_id,
128
+ "agent_identifier": agent_id,
129
+ "cloud": cloud_value,
130
+ "copilot_agent_type": agent_type_value,
131
+ "custom_power_platform_cloud": custom_cloud,
132
+ "direct_connect_url": direct_url,
133
+ "use_experimental_endpoint": exp_endpoint,
134
+ "enable_diagnostics": diagnostics,
135
+ }