microsoft-agents-hosting-core 0.6.0.dev15__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.
- microsoft_agents_hosting_core-0.6.0.dev15/LICENSE +21 -0
- microsoft_agents_hosting_core-0.6.0.dev15/PKG-INFO +191 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/__init__.py +157 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/_oauth/__init__.py +15 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/_oauth/_flow_state.py +81 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/_oauth/_flow_storage_client.py +93 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/_oauth/_oauth_flow.py +335 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/activity_handler.py +605 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/agent.py +22 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/__init__.py +50 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/_routes/__init__.py +13 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/_routes/_route.py +89 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/_routes/_route_list.py +32 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/_routes/route_rank.py +14 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/_type_defs.py +15 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/agent_application.py +879 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/app_error.py +15 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/app_options.py +91 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/input_file.py +49 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/oauth/__init__.py +23 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/oauth/_handlers/__init__.py +14 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/oauth/_handlers/_authorization_handler.py +109 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/oauth/_handlers/_user_authorization.py +263 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py +186 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/oauth/_sign_in_response.py +28 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/oauth/_sign_in_state.py +41 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/oauth/auth_handler.py +99 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/oauth/authorization.py +409 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/query.py +18 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/state/__init__.py +14 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/state/conversation_state.py +51 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/state/state.py +251 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/state/temp_state.py +107 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/state/turn_state.py +320 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/app/typing_indicator.py +81 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/authorization/__init__.py +19 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/authorization/access_token_provider_base.py +48 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/authorization/agent_auth_configuration.py +70 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/authorization/anonymous_token_provider.py +38 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/authorization/auth_types.py +12 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/authorization/authentication_constants.py +110 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/authorization/claims_identity.py +85 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/authorization/connections.py +42 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/authorization/jwt_token_validator.py +56 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/card_factory.py +193 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/channel_adapter.py +253 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/channel_api_handler_protocol.py +162 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/channel_service_adapter.py +528 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/channel_service_client_factory_base.py +52 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/__init__.py +35 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/agent_conversation_reference.py +9 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/channel_factory_protocol.py +13 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/channel_host_protocol.py +27 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/channel_info_protocol.py +13 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/channel_protocol.py +22 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/channels_configuration.py +42 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/configuration_channel_host.py +62 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/conversation_constants.py +8 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/conversation_id_factory.py +69 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/conversation_id_factory_options.py +21 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/conversation_id_factory_protocol.py +37 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/http_agent_channel.py +100 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/client/http_agent_channel_factory.py +13 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/__init__.py +19 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/agent_sign_in_base.py +26 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/attachments_base.py +17 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/client/__init__.py +4 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/client/connector_client.py +684 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/client/user_token_client.py +326 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/connector_client_base.py +25 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/conversations_base.py +136 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/get_product_info.py +26 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/teams/__init__.py +5 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/teams/teams_connector_client.py +345 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/user_token_base.py +120 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/connector/user_token_client_base.py +20 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/errors/__init__.py +18 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/errors/error_resources.py +173 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/message_factory.py +223 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/middleware_set.py +78 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/rest_channel_service_client_factory.py +162 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/state/__init__.py +9 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/state/agent_state.py +359 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/state/state_property_accessor.py +49 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/state/user_state.py +49 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/__init__.py +28 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/_type_aliases.py +3 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/error_handling.py +42 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/memory_storage.py +67 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/storage.py +104 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/store_item.py +16 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/transcript_file_store.py +263 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/transcript_info.py +12 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/transcript_logger.py +221 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/transcript_memory_store.py +156 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/storage/transcript_store.py +52 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents/hosting/core/turn_context.py +435 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents_hosting_core.egg-info/PKG-INFO +191 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents_hosting_core.egg-info/SOURCES.txt +104 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents_hosting_core.egg-info/dependency_links.txt +1 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents_hosting_core.egg-info/requires.txt +5 -0
- microsoft_agents_hosting_core-0.6.0.dev15/microsoft_agents_hosting_core.egg-info/top_level.txt +1 -0
- microsoft_agents_hosting_core-0.6.0.dev15/pyproject.toml +25 -0
- microsoft_agents_hosting_core-0.6.0.dev15/readme.md +166 -0
- microsoft_agents_hosting_core-0.6.0.dev15/setup.cfg +4 -0
- microsoft_agents_hosting_core-0.6.0.dev15/setup.py +15 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microsoft-agents-hosting-core
|
|
3
|
+
Version: 0.6.0.dev15
|
|
4
|
+
Summary: Core 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-activity==0.6.0.dev15
|
|
19
|
+
Requires-Dist: pyjwt>=2.10.1
|
|
20
|
+
Requires-Dist: isodate>=0.6.1
|
|
21
|
+
Requires-Dist: azure-core>=1.30.0
|
|
22
|
+
Requires-Dist: python-dotenv>=1.1.1
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
|
|
26
|
+
# Microsoft Agents Hosting Core
|
|
27
|
+
|
|
28
|
+
[](https://pypi.org/project/microsoft-agents-hosting-core/)
|
|
29
|
+
|
|
30
|
+
The core hosting library for Microsoft 365 Agents SDK. This library provides the fundamental building blocks for creating conversational AI agents, including activity processing, state management, authentication, and channel communication.
|
|
31
|
+
|
|
32
|
+
This is the heart of the Microsoft 365 Agents SDK - think of it as the engine that powers your conversational agents. It handles the complex orchestration of conversations, manages state across turns, and provides the infrastructure needed to build production-ready agents that work across Microsoft 365 platforms.
|
|
33
|
+
|
|
34
|
+
# What is this?
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
## Release Notes
|
|
38
|
+
<table style="width:100%">
|
|
39
|
+
<tr>
|
|
40
|
+
<th style="width:20%">Version</th>
|
|
41
|
+
<th style="width:20%">Date</th>
|
|
42
|
+
<th style="width:60%">Release Notes</th>
|
|
43
|
+
</tr>
|
|
44
|
+
<tr>
|
|
45
|
+
<td>0.5.0</td>
|
|
46
|
+
<td>2025-10-22</td>
|
|
47
|
+
<td>
|
|
48
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md">
|
|
49
|
+
0.5.0 Release Notes
|
|
50
|
+
</a>
|
|
51
|
+
</td>
|
|
52
|
+
</tr>
|
|
53
|
+
</table>
|
|
54
|
+
|
|
55
|
+
## Packages Overview
|
|
56
|
+
|
|
57
|
+
We offer the following PyPI packages to create conversational experiences based on Agents:
|
|
58
|
+
|
|
59
|
+
| Package Name | PyPI Version | Description |
|
|
60
|
+
|--------------|-------------|-------------|
|
|
61
|
+
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
62
|
+
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
63
|
+
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
64
|
+
| `microsoft-agents-hosting-teams` | [](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. |
|
|
65
|
+
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
66
|
+
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
67
|
+
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
68
|
+
|
|
69
|
+
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
70
|
+
|
|
71
|
+
| Package Name | PyPI Version | Description |
|
|
72
|
+
|--------------|-------------|-------------|
|
|
73
|
+
| `microsoft-agents-copilotstudio-client` | [](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio |
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## Installation
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install microsoft-agents-hosting-core
|
|
80
|
+
```
|
|
81
|
+
## Simple Echo Agent
|
|
82
|
+
See the [Quickstart sample](https://github.com/microsoft/Agents/tree/main/samples/python/quickstart) for full working code.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
agents_sdk_config = load_configuration_from_env(environ)
|
|
86
|
+
|
|
87
|
+
STORAGE = MemoryStorage()
|
|
88
|
+
CONNECTION_MANAGER = MsalConnectionManager(**agents_sdk_config)
|
|
89
|
+
ADAPTER = CloudAdapter(connection_manager=CONNECTION_MANAGER)
|
|
90
|
+
AUTHORIZATION = Authorization(STORAGE, CONNECTION_MANAGER, **agents_sdk_config)
|
|
91
|
+
|
|
92
|
+
AGENT_APP = AgentApplication[TurnState](
|
|
93
|
+
storage=STORAGE, adapter=ADAPTER, authorization=AUTHORIZATION, **agents_sdk_config
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
@AGENT_APP.activity("message")
|
|
97
|
+
async def on_message(context: TurnContext, state: TurnState):
|
|
98
|
+
await context.send_activity(f"You said: {context.activity.text}")
|
|
99
|
+
|
|
100
|
+
...
|
|
101
|
+
|
|
102
|
+
start_server(
|
|
103
|
+
agent_application=AGENT_APP,
|
|
104
|
+
auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(),
|
|
105
|
+
)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Core Concepts
|
|
109
|
+
|
|
110
|
+
### AgentApplication vs ActivityHandler
|
|
111
|
+
|
|
112
|
+
**AgentApplication** - Modern, fluent API for building agents:
|
|
113
|
+
- Decorator-based routing (`@agent_app.activity("message")`)
|
|
114
|
+
- Built-in state management and middleware
|
|
115
|
+
- AI-ready with authorization support
|
|
116
|
+
- Type-safe with generics
|
|
117
|
+
|
|
118
|
+
**ActivityHandler** - Traditional inheritance-based approach:
|
|
119
|
+
- Override methods for different activity types
|
|
120
|
+
- More familiar to Bot Framework developers
|
|
121
|
+
- Lower-level control over activity processing
|
|
122
|
+
|
|
123
|
+
### Route-based Message Handling
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
@AGENT_APP.message(re.compile(r"^hello$"))
|
|
127
|
+
async def on_hello(context: TurnContext, _state: TurnState):
|
|
128
|
+
await context.send_activity("Hello!")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@AGENT_APP.activity("message")
|
|
132
|
+
async def on_message(context: TurnContext, _state: TurnState):
|
|
133
|
+
await context.send_activity(f"you said: {context.activity.text}")
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Error Handling
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
@AGENT_APP.error
|
|
140
|
+
async def on_error(context: TurnContext, error: Exception):
|
|
141
|
+
# NOTE: In production environment, you should consider logging this to Azure
|
|
142
|
+
# application insights.
|
|
143
|
+
print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr)
|
|
144
|
+
traceback.print_exc()
|
|
145
|
+
|
|
146
|
+
# Send a message to the user
|
|
147
|
+
await context.send_activity("The bot encountered an error or bug.")
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
## Key Classes Reference
|
|
152
|
+
|
|
153
|
+
### Core Classes
|
|
154
|
+
- **`AgentApplication`** - Main application class with fluent API
|
|
155
|
+
- **`ActivityHandler`** - Base class for inheritance-based agents
|
|
156
|
+
- **`TurnContext`** - Context for each conversation turn
|
|
157
|
+
- **`TurnState`** - State management across conversation turns
|
|
158
|
+
|
|
159
|
+
### State Management
|
|
160
|
+
- **`ConversationState`** - Conversation-scoped state
|
|
161
|
+
- **`UserState`** - User-scoped state across conversations
|
|
162
|
+
- **`TempState`** - Temporary state for current turn
|
|
163
|
+
- **`MemoryStorage`** - In-memory storage (development)
|
|
164
|
+
|
|
165
|
+
### Messaging
|
|
166
|
+
- **`MessageFactory`** - Create different types of messages
|
|
167
|
+
- **`CardFactory`** - Create rich card attachments
|
|
168
|
+
- **`InputFile`** - Handle file attachments
|
|
169
|
+
|
|
170
|
+
### Authorization
|
|
171
|
+
- **`Authorization`** - Authentication and authorization manager
|
|
172
|
+
- **`ClaimsIdentity`** - User identity and claims
|
|
173
|
+
|
|
174
|
+
# Quick Links
|
|
175
|
+
|
|
176
|
+
- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
|
|
177
|
+
- 📖 [Complete Documentation](https://aka.ms/agents)
|
|
178
|
+
- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
|
|
179
|
+
- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
|
|
180
|
+
|
|
181
|
+
# Sample Applications
|
|
182
|
+
|
|
183
|
+
|Name|Description|README|
|
|
184
|
+
|----|----|----|
|
|
185
|
+
|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)|
|
|
186
|
+
|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)|
|
|
187
|
+
|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)|
|
|
188
|
+
|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)|
|
|
189
|
+
|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)|
|
|
190
|
+
|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)|
|
|
191
|
+
|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)|
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
from .activity_handler import ActivityHandler
|
|
2
|
+
from .agent import Agent
|
|
3
|
+
from .card_factory import CardFactory
|
|
4
|
+
from .channel_adapter import ChannelAdapter
|
|
5
|
+
from .channel_api_handler_protocol import ChannelApiHandlerProtocol
|
|
6
|
+
from .channel_service_adapter import ChannelServiceAdapter
|
|
7
|
+
from .channel_service_client_factory_base import ChannelServiceClientFactoryBase
|
|
8
|
+
from .message_factory import MessageFactory
|
|
9
|
+
from .middleware_set import Middleware
|
|
10
|
+
from .rest_channel_service_client_factory import RestChannelServiceClientFactory
|
|
11
|
+
from .turn_context import TurnContext
|
|
12
|
+
|
|
13
|
+
# Application Style
|
|
14
|
+
from .app._type_defs import RouteHandler, RouteSelector, StateT
|
|
15
|
+
from .app.agent_application import AgentApplication
|
|
16
|
+
from .app.app_error import ApplicationError
|
|
17
|
+
from .app.app_options import ApplicationOptions
|
|
18
|
+
from .app.input_file import InputFile, InputFileDownloader
|
|
19
|
+
from .app.query import Query
|
|
20
|
+
from .app._routes import _Route, _RouteList, RouteRank
|
|
21
|
+
from .app.typing_indicator import TypingIndicator
|
|
22
|
+
|
|
23
|
+
# App Auth
|
|
24
|
+
from .app.oauth import (
|
|
25
|
+
Authorization,
|
|
26
|
+
AuthHandler,
|
|
27
|
+
AgenticUserAuthorization,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# App State
|
|
31
|
+
from .app.state.conversation_state import ConversationState
|
|
32
|
+
from .app.state.state import State, state
|
|
33
|
+
from .app.state.temp_state import TempState
|
|
34
|
+
from .app.state.turn_state import TurnState
|
|
35
|
+
|
|
36
|
+
# Authorization
|
|
37
|
+
from .authorization.access_token_provider_base import AccessTokenProviderBase
|
|
38
|
+
from .authorization.authentication_constants import AuthenticationConstants
|
|
39
|
+
from .authorization.anonymous_token_provider import AnonymousTokenProvider
|
|
40
|
+
from .authorization.connections import Connections
|
|
41
|
+
from .authorization.agent_auth_configuration import AgentAuthConfiguration
|
|
42
|
+
from .authorization.claims_identity import ClaimsIdentity
|
|
43
|
+
from .authorization.jwt_token_validator import JwtTokenValidator
|
|
44
|
+
from .authorization.auth_types import AuthTypes
|
|
45
|
+
|
|
46
|
+
# Client API
|
|
47
|
+
from .client.agent_conversation_reference import AgentConversationReference
|
|
48
|
+
from .client.channel_factory_protocol import ChannelFactoryProtocol
|
|
49
|
+
from .client.channel_host_protocol import ChannelHostProtocol
|
|
50
|
+
from .client.channel_info_protocol import ChannelInfoProtocol
|
|
51
|
+
from .client.channel_protocol import ChannelProtocol
|
|
52
|
+
from .client.channels_configuration import (
|
|
53
|
+
ChannelsConfiguration,
|
|
54
|
+
ChannelHostConfiguration,
|
|
55
|
+
ChannelInfo,
|
|
56
|
+
)
|
|
57
|
+
from .client.configuration_channel_host import ConfigurationChannelHost
|
|
58
|
+
from .client.conversation_constants import ConversationConstants
|
|
59
|
+
from .client.conversation_id_factory_options import ConversationIdFactoryOptions
|
|
60
|
+
from .client.conversation_id_factory_protocol import ConversationIdFactoryProtocol
|
|
61
|
+
from .client.conversation_id_factory import ConversationIdFactory
|
|
62
|
+
from .client.http_agent_channel_factory import HttpAgentChannelFactory
|
|
63
|
+
from .client.http_agent_channel import HttpAgentChannel
|
|
64
|
+
|
|
65
|
+
# Connector API
|
|
66
|
+
from .connector import (
|
|
67
|
+
ConnectorClient,
|
|
68
|
+
UserTokenClient,
|
|
69
|
+
UserTokenClientBase,
|
|
70
|
+
TeamsConnectorClient,
|
|
71
|
+
ConnectorClientBase,
|
|
72
|
+
get_product_info,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# State management
|
|
76
|
+
from .state.agent_state import AgentState
|
|
77
|
+
from .state.state_property_accessor import StatePropertyAccessor
|
|
78
|
+
from .state.user_state import UserState
|
|
79
|
+
|
|
80
|
+
# Storage
|
|
81
|
+
from .storage.store_item import StoreItem
|
|
82
|
+
from .storage import Storage
|
|
83
|
+
from .storage.memory_storage import MemoryStorage
|
|
84
|
+
|
|
85
|
+
# Error Resources
|
|
86
|
+
from .errors import error_resources, ErrorMessage, ErrorResources
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# Define the package's public interface
|
|
90
|
+
__all__ = [
|
|
91
|
+
"ActivityHandler",
|
|
92
|
+
"Agent",
|
|
93
|
+
"CardFactory",
|
|
94
|
+
"ChannelAdapter",
|
|
95
|
+
"ChannelApiHandlerProtocol",
|
|
96
|
+
"ChannelServiceAdapter",
|
|
97
|
+
"ChannelServiceClientFactoryBase",
|
|
98
|
+
"MessageFactory",
|
|
99
|
+
"Middleware",
|
|
100
|
+
"RestChannelServiceClientFactory",
|
|
101
|
+
"TurnContext",
|
|
102
|
+
"AgentApplication",
|
|
103
|
+
"ApplicationError",
|
|
104
|
+
"ApplicationOptions",
|
|
105
|
+
"InputFile",
|
|
106
|
+
"InputFileDownloader",
|
|
107
|
+
"Query",
|
|
108
|
+
"Route",
|
|
109
|
+
"RouteHandler",
|
|
110
|
+
"TypingIndicator",
|
|
111
|
+
"ConversationState",
|
|
112
|
+
"state",
|
|
113
|
+
"State",
|
|
114
|
+
"TurnState",
|
|
115
|
+
"TempState",
|
|
116
|
+
"Authorization",
|
|
117
|
+
"AuthHandler",
|
|
118
|
+
"AccessTokenProviderBase",
|
|
119
|
+
"AuthenticationConstants",
|
|
120
|
+
"AnonymousTokenProvider",
|
|
121
|
+
"Connections",
|
|
122
|
+
"AgentAuthConfiguration",
|
|
123
|
+
"ClaimsIdentity",
|
|
124
|
+
"JwtTokenValidator",
|
|
125
|
+
"AgentConversationReference",
|
|
126
|
+
"ChannelFactoryProtocol",
|
|
127
|
+
"ChannelHostProtocol",
|
|
128
|
+
"ChannelInfoProtocol",
|
|
129
|
+
"ChannelProtocol",
|
|
130
|
+
"ChannelsConfiguration",
|
|
131
|
+
"ChannelHostConfiguration",
|
|
132
|
+
"ChannelInfo",
|
|
133
|
+
"ConfigurationChannelHost",
|
|
134
|
+
"ConversationConstants",
|
|
135
|
+
"ConversationIdFactoryOptions",
|
|
136
|
+
"ConversationIdFactoryProtocol",
|
|
137
|
+
"ConversationIdFactory",
|
|
138
|
+
"HttpAgentChannelFactory",
|
|
139
|
+
"HttpAgentChannel",
|
|
140
|
+
"ConnectorClient",
|
|
141
|
+
"UserTokenClient",
|
|
142
|
+
"UserTokenClientBase",
|
|
143
|
+
"TeamsConnectorClient",
|
|
144
|
+
"ConnectorClientBase",
|
|
145
|
+
"get_product_info",
|
|
146
|
+
"AgentState",
|
|
147
|
+
"StatePropertyAccessor",
|
|
148
|
+
"UserState",
|
|
149
|
+
"StoreItem",
|
|
150
|
+
"Storage",
|
|
151
|
+
"MemoryStorage",
|
|
152
|
+
"AgenticUserAuthorization",
|
|
153
|
+
"Authorization",
|
|
154
|
+
"error_resources",
|
|
155
|
+
"ErrorMessage",
|
|
156
|
+
"ErrorResources",
|
|
157
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
from ._flow_state import _FlowState, _FlowStateTag, _FlowErrorTag
|
|
5
|
+
from ._flow_storage_client import _FlowStorageClient
|
|
6
|
+
from ._oauth_flow import _OAuthFlow, _FlowResponse
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"_FlowState",
|
|
10
|
+
"_FlowStateTag",
|
|
11
|
+
"_FlowErrorTag",
|
|
12
|
+
"_FlowResponse",
|
|
13
|
+
"_FlowStorageClient",
|
|
14
|
+
"_OAuthFlow",
|
|
15
|
+
]
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
from pydantic import BaseModel
|
|
11
|
+
|
|
12
|
+
from microsoft_agents.activity import Activity
|
|
13
|
+
|
|
14
|
+
from ..storage import StoreItem
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class _FlowStateTag(Enum):
|
|
18
|
+
"""Represents the top-level state of an OAuthFlow
|
|
19
|
+
|
|
20
|
+
For instance, a flow can arrive at an error, but its
|
|
21
|
+
broader state may still be CONTINUE if the flow can
|
|
22
|
+
still progress
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
BEGIN = "begin"
|
|
26
|
+
CONTINUE = "continue"
|
|
27
|
+
NOT_STARTED = "not_started"
|
|
28
|
+
FAILURE = "failure"
|
|
29
|
+
COMPLETE = "complete"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class _FlowErrorTag(Enum):
|
|
33
|
+
"""Represents the various error states that can occur during an OAuthFlow"""
|
|
34
|
+
|
|
35
|
+
NONE = "none"
|
|
36
|
+
MAGIC_FORMAT = "magic_format"
|
|
37
|
+
MAGIC_CODE_INCORRECT = "magic_code_incorrect"
|
|
38
|
+
OTHER = "other"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class _FlowState(BaseModel, StoreItem):
|
|
42
|
+
"""Represents the state of an OAuthFlow"""
|
|
43
|
+
|
|
44
|
+
channel_id: str = ""
|
|
45
|
+
user_id: str = ""
|
|
46
|
+
ms_app_id: str = ""
|
|
47
|
+
connection: str = ""
|
|
48
|
+
auth_handler_id: str = ""
|
|
49
|
+
|
|
50
|
+
expiration: float = 0
|
|
51
|
+
continuation_activity: Optional[Activity] = None
|
|
52
|
+
attempts_remaining: int = 0
|
|
53
|
+
tag: _FlowStateTag = _FlowStateTag.NOT_STARTED
|
|
54
|
+
|
|
55
|
+
def store_item_to_json(self) -> dict:
|
|
56
|
+
return self.model_dump(mode="json", exclude_unset=True, by_alias=True)
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
def from_json_to_store_item(json_data: dict) -> _FlowState:
|
|
60
|
+
return _FlowState.model_validate(json_data)
|
|
61
|
+
|
|
62
|
+
def is_expired(self) -> bool:
|
|
63
|
+
return datetime.now(timezone.utc).timestamp() >= self.expiration
|
|
64
|
+
|
|
65
|
+
def reached_max_attempts(self) -> bool:
|
|
66
|
+
return self.attempts_remaining <= 0
|
|
67
|
+
|
|
68
|
+
def is_active(self) -> bool:
|
|
69
|
+
return (
|
|
70
|
+
not self.is_expired()
|
|
71
|
+
and not self.reached_max_attempts()
|
|
72
|
+
and self.tag in [_FlowStateTag.BEGIN, _FlowStateTag.CONTINUE]
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
def refresh(self):
|
|
76
|
+
if (
|
|
77
|
+
self.tag
|
|
78
|
+
in [_FlowStateTag.BEGIN, _FlowStateTag.CONTINUE, _FlowStateTag.COMPLETE]
|
|
79
|
+
and self.is_expired()
|
|
80
|
+
):
|
|
81
|
+
self.tag = _FlowStateTag.NOT_STARTED
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from ..storage import Storage
|
|
7
|
+
from ._flow_state import _FlowState
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class _DummyCache(Storage):
|
|
11
|
+
|
|
12
|
+
async def read(self, keys: list[str], **kwargs) -> dict[str, _FlowState]:
|
|
13
|
+
return {}
|
|
14
|
+
|
|
15
|
+
async def write(self, changes: dict[str, _FlowState]) -> None:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
async def delete(self, keys: list[str]) -> None:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# this could be generalized. Ideas:
|
|
23
|
+
# - CachedStorage class for two-tier storage
|
|
24
|
+
# - Namespaced/PrefixedStorage class for namespacing keying
|
|
25
|
+
# not generally thread or async safe (operations are not atomic)
|
|
26
|
+
class _FlowStorageClient:
|
|
27
|
+
"""Wrapper around Storage that manages sign-in state specific to each user and channel.
|
|
28
|
+
|
|
29
|
+
Uses the activity's channel_id and from.id to create a key prefix for storage operations.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
channel_id: str,
|
|
35
|
+
user_id: str,
|
|
36
|
+
storage: Storage,
|
|
37
|
+
cache_class: Optional[type[Storage]] = None,
|
|
38
|
+
):
|
|
39
|
+
"""
|
|
40
|
+
Args:
|
|
41
|
+
channel_id: used to create the prefix
|
|
42
|
+
user_id: used to create the prefix
|
|
43
|
+
storage: the backing storage
|
|
44
|
+
cache_class: the cache class to use (defaults to DummyCache, which performs no caching).
|
|
45
|
+
This cache's lifetime is tied to the FlowStorageClient instance.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
if not user_id or not channel_id:
|
|
49
|
+
raise ValueError(
|
|
50
|
+
"FlowStorageClient.__init__(): channel_id and user_id must be set."
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
self._base_key = f"auth/{channel_id}/{user_id}/"
|
|
54
|
+
self._storage = storage
|
|
55
|
+
if cache_class is None:
|
|
56
|
+
cache_class = _DummyCache
|
|
57
|
+
self._cache = cache_class()
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def base_key(self) -> str:
|
|
61
|
+
"""Returns the prefix used for flow state storage isolation."""
|
|
62
|
+
return self._base_key
|
|
63
|
+
|
|
64
|
+
def key(self, auth_handler_id: str) -> str:
|
|
65
|
+
"""Creates a storage key for a specific sign-in handler."""
|
|
66
|
+
return f"{self._base_key}{auth_handler_id}"
|
|
67
|
+
|
|
68
|
+
async def read(self, auth_handler_id: str) -> Optional[_FlowState]:
|
|
69
|
+
"""Reads the flow state for a specific authentication handler."""
|
|
70
|
+
key: str = self.key(auth_handler_id)
|
|
71
|
+
data = await self._cache.read([key], target_cls=_FlowState)
|
|
72
|
+
if key not in data:
|
|
73
|
+
data = await self._storage.read([key], target_cls=_FlowState)
|
|
74
|
+
if key not in data:
|
|
75
|
+
return None
|
|
76
|
+
await self._cache.write({key: data[key]})
|
|
77
|
+
return _FlowState.model_validate(data.get(key))
|
|
78
|
+
|
|
79
|
+
async def write(self, value: _FlowState) -> None:
|
|
80
|
+
"""Saves the flow state for a specific authentication handler."""
|
|
81
|
+
key: str = self.key(value.auth_handler_id)
|
|
82
|
+
cached_state = await self._cache.read([key], target_cls=_FlowState)
|
|
83
|
+
if not cached_state or cached_state != value:
|
|
84
|
+
await self._cache.write({key: value})
|
|
85
|
+
await self._storage.write({key: value})
|
|
86
|
+
|
|
87
|
+
async def delete(self, auth_handler_id: str) -> None:
|
|
88
|
+
"""Deletes the flow state for a specific authentication handler."""
|
|
89
|
+
key: str = self.key(auth_handler_id)
|
|
90
|
+
cached_state = await self._cache.read([key], target_cls=_FlowState)
|
|
91
|
+
if cached_state:
|
|
92
|
+
await self._cache.delete([key])
|
|
93
|
+
await self._storage.delete([key])
|