microsoft-agents-hosting-aiohttp 0.5.0.dev5__py3-none-any.whl → 0.7.0.dev0__py3-none-any.whl

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.
@@ -1,5 +1,6 @@
1
1
  from typing import Optional
2
2
  from aiohttp.web import Request, Response
3
+ from microsoft_agents.hosting.core import error_resources
3
4
  from microsoft_agents.hosting.core.app import AgentApplication
4
5
  from .cloud_adapter import CloudAdapter
5
6
 
@@ -15,9 +16,9 @@ async def start_agent_process(
15
16
  agent_application (AgentApplication): The agent application to run.
16
17
  """
17
18
  if not adapter:
18
- raise TypeError("start_agent_process: adapter can't be None")
19
+ raise TypeError(str(error_resources.AdapterRequired))
19
20
  if not agent_application:
20
- raise TypeError("start_agent_process: agent_application can't be None")
21
+ raise TypeError(str(error_resources.AgentApplicationRequired))
21
22
 
22
23
  # Start the agent application with the provided adapter
23
24
  return await adapter.process(
@@ -16,8 +16,8 @@ from microsoft_agents.activity import (
16
16
  SensitivityUsageInfo,
17
17
  )
18
18
 
19
- if TYPE_CHECKING:
20
- from microsoft_agents.hosting.core.turn_context import TurnContext
19
+ from microsoft_agents.hosting.core import error_resources
20
+ from microsoft_agents.hosting.core.turn_context import TurnContext
21
21
 
22
22
  from .citation import Citation
23
23
  from .citation_util import CitationUtil
@@ -99,7 +99,7 @@ class StreamingResponse:
99
99
  return
100
100
 
101
101
  if self._ended:
102
- raise RuntimeError("The stream has already ended.")
102
+ raise RuntimeError(str(error_resources.StreamAlreadyEnded))
103
103
 
104
104
  # Queue a typing activity
105
105
  def create_activity():
@@ -135,7 +135,7 @@ class StreamingResponse:
135
135
  if self._cancelled:
136
136
  return
137
137
  if self._ended:
138
- raise RuntimeError("The stream has already ended.")
138
+ raise RuntimeError(str(error_resources.StreamAlreadyEnded))
139
139
 
140
140
  # Update full message text
141
141
  self._message += text
@@ -151,7 +151,7 @@ class StreamingResponse:
151
151
  Ends the stream by sending the final message to the client.
152
152
  """
153
153
  if self._ended:
154
- raise RuntimeError("The stream has already ended.")
154
+ raise RuntimeError(str(error_resources.StreamAlreadyEnded))
155
155
 
156
156
  # Queue final message
157
157
  self._ended = True
@@ -250,10 +250,15 @@ class StreamingResponse:
250
250
  await self._queue_sync
251
251
 
252
252
  def _set_defaults(self, context: "TurnContext"):
253
- if context.activity.channel_id == Channels.ms_teams:
254
- self._is_streaming_channel = True
255
- self._interval = 1.0
256
- elif context.activity.channel_id == Channels.direct_line:
253
+ if Channels.ms_teams == context.activity.channel_id.channel:
254
+ if context.activity.is_agentic_request():
255
+ # Agentic requests do not support streaming responses at this time.
256
+ # TODO : Enable streaming for agentic requests when supported.
257
+ self._is_streaming_channel = False
258
+ else:
259
+ self._is_streaming_channel = True
260
+ self._interval = 1.0
261
+ elif Channels.direct_line == context.activity.channel_id.channel:
257
262
  self._is_streaming_channel = True
258
263
  self._interval = 0.5
259
264
  elif context.activity.delivery_mode == DeliveryModes.stream:
@@ -284,6 +289,7 @@ class StreamingResponse:
284
289
  entities=[
285
290
  Entity(
286
291
  type="streaminfo",
292
+ stream_id=self._stream_id,
287
293
  stream_type="final",
288
294
  stream_sequence=self._sequence_number,
289
295
  )
@@ -12,6 +12,7 @@ from aiohttp.web import (
12
12
  HTTPUnauthorized,
13
13
  HTTPUnsupportedMediaType,
14
14
  )
15
+ from microsoft_agents.hosting.core import error_resources
15
16
  from microsoft_agents.hosting.core.authorization import (
16
17
  ClaimsIdentity,
17
18
  Connections,
@@ -70,9 +71,9 @@ class CloudAdapter(ChannelServiceAdapter, AgentHttpAdapter):
70
71
 
71
72
  async def process(self, request: Request, agent: Agent) -> Optional[Response]:
72
73
  if not request:
73
- raise TypeError("CloudAdapter.process: request can't be None")
74
+ raise TypeError(str(error_resources.RequestRequired))
74
75
  if not agent:
75
- raise TypeError("CloudAdapter.process: agent can't be None")
76
+ raise TypeError(str(error_resources.AgentRequired))
76
77
 
77
78
  if request.method == "POST":
78
79
  # Deserialize the incoming Activity
@@ -13,11 +13,12 @@ async def jwt_authorization_middleware(request: Request, handler):
13
13
  auth_config: AgentAuthConfiguration = request.app["agent_configuration"]
14
14
  token_validator = JwtTokenValidator(auth_config)
15
15
  auth_header = request.headers.get("Authorization")
16
+
16
17
  if auth_header:
17
18
  # Extract the token from the Authorization header
18
19
  token = auth_header.split(" ")[1]
19
20
  try:
20
- claims = token_validator.validate_token(token)
21
+ claims = await token_validator.validate_token(token)
21
22
  request["claims_identity"] = claims
22
23
  except ValueError as e:
23
24
  print(f"JWT validation error: {e}")
@@ -44,7 +45,7 @@ def jwt_authorization_decorator(func):
44
45
  # Extract the token from the Authorization header
45
46
  token = auth_header.split(" ")[1]
46
47
  try:
47
- claims = token_validator.validate_token(token)
48
+ claims = await token_validator.validate_token(token)
48
49
  request["claims_identity"] = claims
49
50
  except ValueError as e:
50
51
  print(f"JWT validation error: {e}")
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: microsoft-agents-hosting-aiohttp
3
+ Version: 0.7.0.dev0
4
+ Summary: Integration library for Microsoft Agents with aiohttp
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.7.0.dev0
19
+ Requires-Dist: aiohttp>=3.11.11
20
+ Dynamic: license-file
21
+ Dynamic: requires-dist
22
+
23
+ # Microsoft Agents Hosting - aiohttp
24
+
25
+ [![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/)
26
+
27
+ Integration library for hosting Microsoft 365 Agents using aiohttp. This library provides HTTP adapters, middleware, and utilities for building web-based agent applications with the popular aiohttp framework.
28
+
29
+ This library bridges the Microsoft 365 Agents SDK with aiohttp, allowing you to create HTTP endpoints that handle agent conversations. It provides everything you need to host agents as web services, including request processing, authentication, and routing.
30
+
31
+ # What is this?
32
+
33
+ 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.
34
+
35
+ ## Release Notes
36
+ <table style="width:100%">
37
+ <tr>
38
+ <th style="width:20%">Version</th>
39
+ <th style="width:20%">Date</th>
40
+ <th style="width:60%">Release Notes</th>
41
+ </tr>
42
+ <tr>
43
+ <td>0.5.0</td>
44
+ <td>2025-10-22</td>
45
+ <td>
46
+ <a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md">
47
+ 0.5.0 Release Notes
48
+ </a>
49
+ </td>
50
+ </tr>
51
+ </table>
52
+
53
+ ## Packages Overview
54
+
55
+ We offer the following PyPI packages to create conversational experiences based on Agents:
56
+
57
+ | Package Name | PyPI Version | Description |
58
+ |--------------|-------------|-------------|
59
+ | `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. |
60
+ | `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. |
61
+ | `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. |
62
+ | `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. |
63
+ | `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. |
64
+ | `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. |
65
+ | `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. |
66
+
67
+ Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
68
+
69
+ | Package Name | PyPI Version | Description |
70
+ |--------------|-------------|-------------|
71
+ | `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 |
72
+
73
+ ## Installation
74
+
75
+ ```bash
76
+ pip install microsoft-agents-hosting-aiohttp
77
+ ```
78
+
79
+ ## Simple Echo Agent
80
+ See the [Quickstart sample](https://github.com/microsoft/Agents/tree/main/samples/python/quickstart) for full working code.
81
+
82
+ ```python
83
+ agents_sdk_config = load_configuration_from_env(environ)
84
+
85
+ STORAGE = MemoryStorage()
86
+ CONNECTION_MANAGER = MsalConnectionManager(**agents_sdk_config)
87
+ ADAPTER = CloudAdapter(connection_manager=CONNECTION_MANAGER)
88
+ AUTHORIZATION = Authorization(STORAGE, CONNECTION_MANAGER, **agents_sdk_config)
89
+
90
+ AGENT_APP = AgentApplication[TurnState](
91
+ storage=STORAGE, adapter=ADAPTER, authorization=AUTHORIZATION, **agents_sdk_config
92
+ )
93
+
94
+ @AGENT_APP.activity("message")
95
+ async def on_message(context: TurnContext, state: TurnState):
96
+ await context.send_activity(f"You said: {context.activity.text}")
97
+
98
+ ...
99
+
100
+ start_server(
101
+ agent_application=AGENT_APP,
102
+ auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(),
103
+ )
104
+ ```
105
+
106
+
107
+ ### Error Handling
108
+
109
+ Customize error responses. Code take from the [Quickstart sample](https://github.com/microsoft/Agents/tree/main/samples/python/quickstart).
110
+
111
+ ```python
112
+ @AGENT_APP.error
113
+ async def on_error(context: TurnContext, error: Exception):
114
+ # This check writes out errors to console log
115
+ # NOTE: In production environment, you should consider logging this to Azure
116
+ # application insights.
117
+ print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr)
118
+ traceback.print_exc()
119
+
120
+ # Send a message to the user
121
+ await context.send_activity("The bot encountered an error or bug.")
122
+ ```
123
+
124
+ ## Features
125
+
126
+ ✅ **HTTP hosting** - Full aiohttp integration for web hosting
127
+ ✅ **JWT authentication** - Built-in security with middleware
128
+ ✅ **Agent-to-agent** - Support for multi-agent communication
129
+ ✅ **Streaming** - Real-time response streaming
130
+ ✅ **Error handling** - Comprehensive error management
131
+ ✅ **Development friendly** - Hot reload and debugging support
132
+
133
+ ## Requirements
134
+
135
+ - Python 3.10+ (supports 3.10, 3.11, 3.12, 3.13, 3.14)
136
+ - aiohttp 3.11.11+
137
+ - Microsoft Agents hosting core library
138
+
139
+ ## Best Practices
140
+
141
+ 1. **Use middleware** for cross-cutting concerns like auth and logging
142
+ 2. **Handle errors gracefully** with custom error handlers
143
+ 3. **Secure your endpoints** with JWT middleware in production
144
+ 4. **Structure routes** logically for agent communication
145
+
146
+ # Quick Links
147
+
148
+ - 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
149
+ - 📖 [Complete Documentation](https://aka.ms/agents)
150
+ - 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
151
+ - 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
152
+
153
+ # Sample Applications
154
+ |Name|Description|README|
155
+ |----|----|----|
156
+ |Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)|
157
+ |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)|
158
+ |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)|
159
+ |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)|
160
+ |Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)|
161
+ |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)|
162
+ |Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)|
@@ -1,16 +1,16 @@
1
1
  microsoft_agents/hosting/aiohttp/__init__.py,sha256=MiCeImORsTFi9V2n-MIWJA53GzroDd-54G_UoH_5U0Y,664
2
- microsoft_agents/hosting/aiohttp/_start_agent_process.py,sha256=f-BGLGlKgfGpxihuOKWmg9Zrnw8EF0wqOwMVdGPmIWM,909
2
+ microsoft_agents/hosting/aiohttp/_start_agent_process.py,sha256=RqKjQrYGRlzp05ssropmKCwI7T4j-glQP1zJtuOHBI0,950
3
3
  microsoft_agents/hosting/aiohttp/agent_http_adapter.py,sha256=U6GQVPPj-Vi2Kan8i2LDrRtU-M9FpfXUzFqzOqvVYoI,444
4
4
  microsoft_agents/hosting/aiohttp/channel_service_route_table.py,sha256=3JNmK63j0ELgqUAtqsOXFjajhRTMgf29cIGwLCDwnLE,6745
5
- microsoft_agents/hosting/aiohttp/cloud_adapter.py,sha256=3WWi4xxEFw8c9XTYp_MVUt3JlbzGJRwVEJ-aky-W_is,3842
6
- microsoft_agents/hosting/aiohttp/jwt_authorization_middleware.py,sha256=yepAZqMq3Cbh4hIExwBeGUDyXbfkakJbeXbSJofC9oY,2314
5
+ microsoft_agents/hosting/aiohttp/cloud_adapter.py,sha256=UzSoZPGNI9VVY9vQx5E6BMgJAa0x2UUmuW2JGEiX9bc,3882
6
+ microsoft_agents/hosting/aiohttp/jwt_authorization_middleware.py,sha256=26r7lK-umiohc5H7mC-m0yeHr-Tq7DoALO1ea0pi714,2327
7
7
  microsoft_agents/hosting/aiohttp/app/__init__.py,sha256=TioskqZet16twXOsI3X2snyLzmuyeKNtN2dySD1Xw7s,253
8
8
  microsoft_agents/hosting/aiohttp/app/streaming/__init__.py,sha256=G_VGmQ0m6TkHZsHjRV5HitaCOt2EBEjENIoBYabJMqM,292
9
9
  microsoft_agents/hosting/aiohttp/app/streaming/citation.py,sha256=ZGaMUOWxxoMplwRrkFsjnK7Z12V6rT5odE7qZCu-mP8,498
10
10
  microsoft_agents/hosting/aiohttp/app/streaming/citation_util.py,sha256=c95c3Y3genmFc0vSXppPaD1-ShFohAV1UABZnyJS_BQ,2478
11
- microsoft_agents/hosting/aiohttp/app/streaming/streaming_response.py,sha256=VcAhol4PEMvjeWYSg87L1Zbl20_i3W_LSP16LEGeN98,13762
12
- microsoft_agents_hosting_aiohttp-0.5.0.dev5.dist-info/licenses/LICENSE,sha256=ws_MuBL-SCEBqPBFl9_FqZkaaydIJmxHrJG2parhU4M,1141
13
- microsoft_agents_hosting_aiohttp-0.5.0.dev5.dist-info/METADATA,sha256=ef3XZ6rHqxb4fkt-pUqZ62Nvfq_3IhBRKjIIqvdMIMQ,531
14
- microsoft_agents_hosting_aiohttp-0.5.0.dev5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- microsoft_agents_hosting_aiohttp-0.5.0.dev5.dist-info/top_level.txt,sha256=lWKcT4v6fTA_NgsuHdNvuMjSrkiBMXohn64ApY7Xi8A,17
16
- microsoft_agents_hosting_aiohttp-0.5.0.dev5.dist-info/RECORD,,
11
+ microsoft_agents/hosting/aiohttp/app/streaming/streaming_response.py,sha256=JSJfoQ1ARn-rWKHAABO2dA4soyRR2F8435mj0qioGKQ,14187
12
+ microsoft_agents_hosting_aiohttp-0.7.0.dev0.dist-info/licenses/LICENSE,sha256=ws_MuBL-SCEBqPBFl9_FqZkaaydIJmxHrJG2parhU4M,1141
13
+ microsoft_agents_hosting_aiohttp-0.7.0.dev0.dist-info/METADATA,sha256=TRzunrOm0hxmSxxrajWM4dJf_o59v5Hy9QOMXC--zRM,8378
14
+ microsoft_agents_hosting_aiohttp-0.7.0.dev0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ microsoft_agents_hosting_aiohttp-0.7.0.dev0.dist-info/top_level.txt,sha256=lWKcT4v6fTA_NgsuHdNvuMjSrkiBMXohn64ApY7Xi8A,17
16
+ microsoft_agents_hosting_aiohttp-0.7.0.dev0.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: microsoft-agents-hosting-aiohttp
3
- Version: 0.5.0.dev5
4
- Summary: Integration library for Microsoft Agents with aiohttp
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: Operating System :: OS Independent
10
- Requires-Python: >=3.9
11
- License-File: LICENSE
12
- Requires-Dist: microsoft-agents-hosting-core==0.5.0.dev5
13
- Requires-Dist: aiohttp>=3.11.11
14
- Dynamic: license-file
15
- Dynamic: requires-dist