microsoft-agents-hosting-core 0.4.0.dev14__tar.gz → 0.4.0.dev18__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 (104) hide show
  1. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/PKG-INFO +2 -2
  2. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/__init__.py +2 -1
  3. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/_oauth/__init__.py +3 -0
  4. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/activity_handler.py +1 -0
  5. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/__init__.py +2 -1
  6. microsoft_agents_hosting_core-0.4.0.dev18/microsoft_agents/hosting/core/app/_routes/__init__.py +13 -0
  7. microsoft_agents_hosting_core-0.4.0.dev18/microsoft_agents/hosting/core/app/_routes/_route.py +89 -0
  8. microsoft_agents_hosting_core-0.4.0.dev18/microsoft_agents/hosting/core/app/_routes/_route_list.py +32 -0
  9. microsoft_agents_hosting_core-0.4.0.dev18/microsoft_agents/hosting/core/app/_routes/route_rank.py +14 -0
  10. microsoft_agents_hosting_core-0.4.0.dev18/microsoft_agents/hosting/core/app/_type_defs.py +15 -0
  11. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/agent_application.py +85 -45
  12. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/oauth/__init__.py +4 -0
  13. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/oauth/_handlers/__init__.py +5 -0
  14. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/oauth/_handlers/_authorization_handler.py +5 -0
  15. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/oauth/_handlers/_user_authorization.py +4 -2
  16. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py +5 -0
  17. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/oauth/_sign_in_response.py +4 -0
  18. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/oauth/_sign_in_state.py +5 -0
  19. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/oauth/auth_handler.py +4 -2
  20. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/oauth/authorization.py +5 -0
  21. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/authorization/access_token_provider_base.py +3 -0
  22. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/authorization/agent_auth_configuration.py +3 -0
  23. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/authorization/anonymous_token_provider.py +3 -0
  24. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/authorization/auth_types.py +3 -0
  25. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/authorization/connections.py +3 -0
  26. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/authorization/jwt_token_validator.py +3 -0
  27. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/channel_api_handler_protocol.py +3 -0
  28. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/channel_service_adapter.py +24 -30
  29. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/channel_service_client_factory_base.py +9 -1
  30. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/agent_conversation_reference.py +3 -0
  31. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/channel_factory_protocol.py +3 -0
  32. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/channel_host_protocol.py +3 -0
  33. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/channel_info_protocol.py +3 -0
  34. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/channel_protocol.py +3 -0
  35. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/channels_configuration.py +3 -0
  36. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/configuration_channel_host.py +3 -0
  37. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/conversation_constants.py +3 -0
  38. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/conversation_id_factory.py +3 -0
  39. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/conversation_id_factory_options.py +3 -0
  40. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/conversation_id_factory_protocol.py +3 -0
  41. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/http_agent_channel.py +3 -0
  42. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/http_agent_channel_factory.py +3 -0
  43. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/client/connector_client.py +19 -2
  44. microsoft_agents_hosting_core-0.4.0.dev18/microsoft_agents/hosting/core/rest_channel_service_client_factory.py +162 -0
  45. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/__init__.py +4 -0
  46. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/error_handling.py +3 -0
  47. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/memory_storage.py +3 -0
  48. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/storage.py +3 -0
  49. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/store_item.py +3 -0
  50. microsoft_agents_hosting_core-0.4.0.dev18/microsoft_agents/hosting/core/storage/transcript_file_store.py +267 -0
  51. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/transcript_logger.py +12 -0
  52. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/transcript_memory_store.py +9 -7
  53. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents_hosting_core.egg-info/PKG-INFO +2 -2
  54. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents_hosting_core.egg-info/SOURCES.txt +6 -1
  55. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents_hosting_core.egg-info/requires.txt +1 -1
  56. microsoft_agents_hosting_core-0.4.0.dev14/microsoft_agents/hosting/core/app/route.py +0 -32
  57. microsoft_agents_hosting_core-0.4.0.dev14/microsoft_agents/hosting/core/rest_channel_service_client_factory.py +0 -133
  58. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/_oauth/_flow_state.py +0 -0
  59. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/_oauth/_flow_storage_client.py +0 -0
  60. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/_oauth/_oauth_flow.py +0 -0
  61. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/agent.py +0 -0
  62. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/app_error.py +0 -0
  63. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/app_options.py +0 -0
  64. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/input_file.py +0 -0
  65. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/query.py +0 -0
  66. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/state/__init__.py +0 -0
  67. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/state/conversation_state.py +0 -0
  68. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/state/state.py +0 -0
  69. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/state/temp_state.py +0 -0
  70. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/state/turn_state.py +0 -0
  71. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/app/typing_indicator.py +0 -0
  72. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/authorization/__init__.py +0 -0
  73. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/authorization/authentication_constants.py +0 -0
  74. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/authorization/claims_identity.py +0 -0
  75. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/card_factory.py +0 -0
  76. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/channel_adapter.py +0 -0
  77. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/client/__init__.py +0 -0
  78. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/__init__.py +0 -0
  79. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/agent_sign_in_base.py +0 -0
  80. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/attachments_base.py +0 -0
  81. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/client/__init__.py +0 -0
  82. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/client/user_token_client.py +0 -0
  83. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/connector_client_base.py +0 -0
  84. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/conversations_base.py +0 -0
  85. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/get_product_info.py +0 -0
  86. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/teams/__init__.py +0 -0
  87. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/teams/teams_connector_client.py +0 -0
  88. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/user_token_base.py +0 -0
  89. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/connector/user_token_client_base.py +0 -0
  90. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/message_factory.py +0 -0
  91. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/middleware_set.py +0 -0
  92. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/state/__init__.py +0 -0
  93. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/state/agent_state.py +0 -0
  94. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/state/state_property_accessor.py +0 -0
  95. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/state/user_state.py +0 -0
  96. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/_type_aliases.py +0 -0
  97. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/transcript_info.py +0 -0
  98. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/storage/transcript_store.py +0 -0
  99. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents/hosting/core/turn_context.py +0 -0
  100. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents_hosting_core.egg-info/dependency_links.txt +0 -0
  101. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/microsoft_agents_hosting_core.egg-info/top_level.txt +0 -0
  102. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/pyproject.toml +0 -0
  103. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/setup.cfg +0 -0
  104. {microsoft_agents_hosting_core-0.4.0.dev14 → microsoft_agents_hosting_core-0.4.0.dev18}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: microsoft-agents-hosting-core
3
- Version: 0.4.0.dev14
3
+ Version: 0.4.0.dev18
4
4
  Summary: Core library for Microsoft Agents
5
5
  Author: Microsoft Corporation
6
6
  Project-URL: Homepage, https://github.com/microsoft/Agents
@@ -8,7 +8,7 @@ Classifier: Programming Language :: Python :: 3
8
8
  Classifier: License :: OSI Approved :: MIT License
9
9
  Classifier: Operating System :: OS Independent
10
10
  Requires-Python: >=3.9
11
- Requires-Dist: microsoft-agents-activity==0.4.0.dev14
11
+ Requires-Dist: microsoft-agents-activity==0.4.0.dev18
12
12
  Requires-Dist: pyjwt>=2.10.1
13
13
  Requires-Dist: isodate>=0.6.1
14
14
  Requires-Dist: azure-core>=1.30.0
@@ -11,12 +11,13 @@ from .rest_channel_service_client_factory import RestChannelServiceClientFactory
11
11
  from .turn_context import TurnContext
12
12
 
13
13
  # Application Style
14
+ from .app._type_defs import RouteHandler, RouteSelector, StateT
14
15
  from .app.agent_application import AgentApplication
15
16
  from .app.app_error import ApplicationError
16
17
  from .app.app_options import ApplicationOptions
17
18
  from .app.input_file import InputFile, InputFileDownloader
18
19
  from .app.query import Query
19
- from .app.route import Route, RouteHandler
20
+ from .app._routes import _Route, _RouteList, RouteRank
20
21
  from .app.typing_indicator import TypingIndicator
21
22
 
22
23
  # App Auth
@@ -1,3 +1,6 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
1
4
  from ._flow_state import _FlowState, _FlowStateTag, _FlowErrorTag
2
5
  from ._flow_storage_client import _FlowStorageClient
3
6
  from ._oauth_flow import _OAuthFlow, _FlowResponse
@@ -1,5 +1,6 @@
1
1
  # Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  # Licensed under the MIT License.
3
+
3
4
  from __future__ import annotations
4
5
  from http import HTTPStatus
5
6
  from pydantic import BaseModel
@@ -10,8 +10,9 @@ from .app_error import ApplicationError
10
10
  from .app_options import ApplicationOptions
11
11
  from .input_file import InputFile, InputFileDownloader
12
12
  from .query import Query
13
- from .route import Route, RouteHandler
13
+ from ._routes import _RouteList, _Route, RouteRank
14
14
  from .typing_indicator import TypingIndicator
15
+ from ._type_defs import RouteHandler, RouteSelector, StateT
15
16
 
16
17
  # Auth
17
18
  from .oauth import (
@@ -0,0 +1,13 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ from ._route_list import _RouteList
5
+ from ._route import _Route, _agentic_selector
6
+ from .route_rank import RouteRank
7
+
8
+ __all__ = [
9
+ "_RouteList",
10
+ "_Route",
11
+ "RouteRank",
12
+ "_agentic_selector",
13
+ ]
@@ -0,0 +1,89 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ from __future__ import annotations
5
+
6
+ from typing import Generic, Optional, TypeVar
7
+
8
+ from ...turn_context import TurnContext
9
+ from .._type_defs import RouteHandler, RouteSelector
10
+ from ..state.turn_state import TurnState
11
+ from .route_rank import RouteRank
12
+
13
+
14
+ def _agentic_selector(selector: RouteSelector) -> RouteSelector:
15
+ def wrapped_selector(context: TurnContext) -> bool:
16
+ return context.activity.is_agentic_request() and selector(context)
17
+
18
+ return wrapped_selector
19
+
20
+
21
+ StateT = TypeVar("StateT", bound=TurnState)
22
+
23
+
24
+ class _Route(Generic[StateT]):
25
+ selector: RouteSelector
26
+ handler: RouteHandler[StateT]
27
+ _is_invoke: bool
28
+ _rank: int
29
+ auth_handlers: list[str]
30
+ _is_agentic: bool
31
+
32
+ def __init__(
33
+ self,
34
+ selector: RouteSelector,
35
+ handler: RouteHandler[StateT],
36
+ is_invoke: bool = False,
37
+ rank: int = RouteRank.DEFAULT,
38
+ auth_handlers: Optional[list[str]] = None,
39
+ is_agentic: bool = False,
40
+ **kwargs,
41
+ ) -> None:
42
+
43
+ if rank < 0 or rank > RouteRank.LAST:
44
+ raise ValueError(
45
+ "Route rank must be between 0 and RouteRank.LAST (inclusive)"
46
+ )
47
+
48
+ self.selector = selector
49
+ self.handler = handler
50
+ self._is_invoke = is_invoke
51
+ self._rank = int(rank) # conversion from RouteRank IntEnum if necessary
52
+ self._is_agentic = is_agentic
53
+ self.auth_handlers = auth_handlers or []
54
+
55
+ @property
56
+ def is_invoke(self) -> bool:
57
+ return self._is_invoke
58
+
59
+ @property
60
+ def rank(self) -> int:
61
+ return self._rank
62
+
63
+ @property
64
+ def is_agentic(self) -> bool:
65
+ return self._is_agentic
66
+
67
+ @property
68
+ def priority(self) -> list[int]:
69
+ """Lower "values" indicate higher priority.
70
+
71
+ Priority is determined by:
72
+ 1. Whether the route is for an invoke activity (0) or not (1).
73
+ 2. Whether the route is agentic (0) or not (1).
74
+ 3. The rank of the route (lower numbers indicate higher priority).
75
+
76
+ In that order. If both are invokes, the agentic one has higher priority.
77
+ If both are agentic and invokes, then the rank determines priority.
78
+
79
+ priority is represented as a list of three integers for easy lexicographic comparison.
80
+ """
81
+ return [
82
+ 0 if self._is_invoke else 1,
83
+ 0 if self._is_agentic else 1,
84
+ self._rank,
85
+ ]
86
+
87
+ def __lt__(self, other: _Route) -> bool:
88
+ # built-in list ordering is a lexicographic comparison in Python
89
+ return self.priority < other.priority
@@ -0,0 +1,32 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ from __future__ import annotations
5
+
6
+ import heapq
7
+ from typing import Generic, TypeVar
8
+
9
+ from ..state.turn_state import TurnState
10
+ from ._route import _Route
11
+
12
+ StateT = TypeVar("StateT", bound=TurnState)
13
+
14
+
15
+ class _RouteList(Generic[StateT]):
16
+ _routes: list[_Route[StateT]]
17
+
18
+ def __init__(
19
+ self,
20
+ ) -> None:
21
+ # a min-heap where lower "values" indicate higher priority
22
+ self._routes = []
23
+
24
+ def add_route(self, route: _Route[StateT]) -> None:
25
+ """Adds a route to the list."""
26
+ heapq.heappush(self._routes, route)
27
+
28
+ def __iter__(self):
29
+ # sorted will return a new list, leaving the heap intact
30
+ # returning an iterator over the previous list would expose
31
+ # internal details
32
+ return iter(sorted(self._routes))
@@ -0,0 +1,14 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ from enum import IntEnum
5
+
6
+ _MAX_RANK = 2**16 - 1 # 65,535
7
+
8
+
9
+ class RouteRank(IntEnum):
10
+ """Defines the rank of a route. Lower values indicate higher priority."""
11
+
12
+ FIRST = 0
13
+ DEFAULT = _MAX_RANK // 2
14
+ LAST = _MAX_RANK
@@ -0,0 +1,15 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ from typing import Callable, TypeVar, Awaitable, Protocol
5
+
6
+ from ..turn_context import TurnContext
7
+ from .state import TurnState
8
+
9
+ RouteSelector = Callable[[TurnContext], bool]
10
+
11
+ StateT = TypeVar("StateT", bound=TurnState)
12
+
13
+
14
+ class RouteHandler(Protocol[StateT]):
15
+ def __call__(self, context: TurnContext, state: StateT) -> Awaitable[None]: ...
@@ -13,9 +13,7 @@ from typing import (
13
13
  Any,
14
14
  Awaitable,
15
15
  Callable,
16
- Dict,
17
16
  Generic,
18
- List,
19
17
  Optional,
20
18
  Pattern,
21
19
  TypeVar,
@@ -38,16 +36,17 @@ from ..authorization import Connections
38
36
  from .app_error import ApplicationError
39
37
  from .app_options import ApplicationOptions
40
38
 
41
- from .route import Route, RouteHandler
42
39
  from .state import TurnState
43
40
  from ..channel_service_adapter import ChannelServiceAdapter
44
41
  from .oauth import Authorization
45
42
  from .typing_indicator import TypingIndicator
46
43
 
44
+ from ._type_defs import RouteHandler, RouteSelector
45
+ from ._routes import _RouteList, _Route, RouteRank, _agentic_selector
46
+
47
47
  logger = logging.getLogger(__name__)
48
48
 
49
49
  StateT = TypeVar("StateT", bound=TurnState)
50
- IN_SIGN_IN_KEY = "__InSignInFlow__"
51
50
 
52
51
 
53
52
  class AgentApplication(Agent, Generic[StateT]):
@@ -68,25 +67,25 @@ class AgentApplication(Agent, Generic[StateT]):
68
67
  _options: ApplicationOptions
69
68
  _adapter: Optional[ChannelServiceAdapter] = None
70
69
  _auth: Optional[Authorization] = None
71
- _internal_before_turn: List[Callable[[TurnContext, StateT], Awaitable[bool]]] = []
72
- _internal_after_turn: List[Callable[[TurnContext, StateT], Awaitable[bool]]] = []
73
- _routes: List[Route[StateT]] = []
70
+ _internal_before_turn: list[Callable[[TurnContext, StateT], Awaitable[bool]]] = []
71
+ _internal_after_turn: list[Callable[[TurnContext, StateT], Awaitable[bool]]] = []
72
+ _route_list: _RouteList[StateT] = _RouteList[StateT]()
74
73
  _error: Optional[Callable[[TurnContext, Exception], Awaitable[None]]] = None
75
74
  _turn_state_factory: Optional[Callable[[TurnContext], StateT]] = None
76
75
 
77
76
  def __init__(
78
77
  self,
79
- options: ApplicationOptions = None,
78
+ options: Optional[ApplicationOptions] = None,
80
79
  *,
81
- connection_manager: Connections = None,
82
- authorization: Authorization = None,
80
+ connection_manager: Optional[Connections] = None,
81
+ authorization: Optional[Authorization] = None,
83
82
  **kwargs,
84
83
  ) -> None:
85
84
  """
86
85
  Creates a new AgentApplication instance.
87
86
  """
88
87
  self.typing = TypingIndicator()
89
- self._routes = []
88
+ self._route_list = _RouteList[StateT]()
90
89
 
91
90
  configuration = kwargs
92
91
 
@@ -204,11 +203,54 @@ class AgentApplication(Agent, Generic[StateT]):
204
203
  """
205
204
  return self._options
206
205
 
206
+ def add_route(
207
+ self,
208
+ selector: RouteSelector,
209
+ handler: RouteHandler[StateT],
210
+ is_invoke: bool = False,
211
+ is_agentic: bool = False,
212
+ rank: RouteRank = RouteRank.DEFAULT,
213
+ auth_handlers: Optional[list[str]] = None,
214
+ ) -> None:
215
+ """Adds a new route to the application.
216
+
217
+ Routes are ordered by: is_agentic, is_invoke, rank (lower is higher priority), in that order.
218
+
219
+ :param selector: A function that takes a TurnContext and returns a boolean indicating whether the route should be selected.
220
+ :type selector: RouteSelector
221
+ :param handler: A function that takes a TurnContext and a TurnState and returns an Awaitable.
222
+ :type handler: RouteHandler[StateT]
223
+ :param is_invoke: Whether the route is for an invoke activity, defaults to False
224
+ :type is_invoke: bool, optional
225
+ :param is_agentic: Whether the route is for an agentic request, defaults to False. For agentic requests
226
+ the selector will include a new check for `context.activity.is_agentic_request()`.
227
+ :type is_agentic: bool, optional
228
+ :param rank: The rank of the route, defaults to RouteRank.DEFAULT
229
+ :type rank: RouteRank, optional
230
+ :param auth_handlers: A list of authentication handler IDs to use for this route, defaults to None
231
+ :type auth_handlers: Optional[list[str]], optional
232
+ :raises ApplicationError: If the selector or handler are not valid.
233
+ """
234
+ if not selector or not handler:
235
+ logger.error(
236
+ "AgentApplication.add_route(): selector and handler are required."
237
+ )
238
+ raise ApplicationError("selector and handler are required.")
239
+
240
+ if is_agentic:
241
+ selector = _agentic_selector(selector)
242
+
243
+ route = _Route[StateT](
244
+ selector, handler, is_invoke, rank, auth_handlers, is_agentic
245
+ )
246
+ self._route_list.add_route(route)
247
+
207
248
  def activity(
208
249
  self,
209
- activity_type: Union[str, ActivityTypes, List[Union[str, ActivityTypes]]],
250
+ activity_type: Union[str, ActivityTypes, list[Union[str, ActivityTypes]]],
210
251
  *,
211
- auth_handlers: Optional[List[str]] = None,
252
+ auth_handlers: Optional[list[str]] = None,
253
+ **kwargs,
212
254
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
213
255
  """
214
256
  Registers a new activity event listener. This method can be used as either
@@ -233,18 +275,17 @@ class AgentApplication(Agent, Generic[StateT]):
233
275
  logger.debug(
234
276
  f"Registering activity handler for route handler {func.__name__} with type: {activity_type} with auth handlers: {auth_handlers}"
235
277
  )
236
- self._routes.append(
237
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
238
- )
278
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
239
279
  return func
240
280
 
241
281
  return __call
242
282
 
243
283
  def message(
244
284
  self,
245
- select: Union[str, Pattern[str], List[Union[str, Pattern[str]]]],
285
+ select: Union[str, Pattern[str], list[Union[str, Pattern[str]]]],
246
286
  *,
247
- auth_handlers: Optional[List[str]] = None,
287
+ auth_handlers: Optional[list[str]] = None,
288
+ **kwargs,
248
289
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
249
290
  """
250
291
  Registers a new message activity event listener. This method can be used as either
@@ -276,9 +317,7 @@ class AgentApplication(Agent, Generic[StateT]):
276
317
  logger.debug(
277
318
  f"Registering message handler for route handler {func.__name__} with select: {select} with auth handlers: {auth_handlers}"
278
319
  )
279
- self._routes.append(
280
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
281
- )
320
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
282
321
  return func
283
322
 
284
323
  return __call
@@ -287,7 +326,8 @@ class AgentApplication(Agent, Generic[StateT]):
287
326
  self,
288
327
  type: ConversationUpdateTypes,
289
328
  *,
290
- auth_handlers: Optional[List[str]] = None,
329
+ auth_handlers: Optional[list[str]] = None,
330
+ **kwargs,
291
331
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
292
332
  """
293
333
  Registers a new message activity event listener. This method can be used as either
@@ -311,12 +351,12 @@ class AgentApplication(Agent, Generic[StateT]):
311
351
  return False
312
352
 
313
353
  if type == "membersAdded":
314
- if isinstance(context.activity.members_added, List):
354
+ if isinstance(context.activity.members_added, list):
315
355
  return len(context.activity.members_added) > 0
316
356
  return False
317
357
 
318
358
  if type == "membersRemoved":
319
- if isinstance(context.activity.members_removed, List):
359
+ if isinstance(context.activity.members_removed, list):
320
360
  return len(context.activity.members_removed) > 0
321
361
  return False
322
362
 
@@ -330,15 +370,17 @@ class AgentApplication(Agent, Generic[StateT]):
330
370
  logger.debug(
331
371
  f"Registering conversation update handler for route handler {func.__name__} with type: {type} with auth handlers: {auth_handlers}"
332
372
  )
333
- self._routes.append(
334
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
335
- )
373
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
336
374
  return func
337
375
 
338
376
  return __call
339
377
 
340
378
  def message_reaction(
341
- self, type: MessageReactionTypes, *, auth_handlers: Optional[List[str]] = None
379
+ self,
380
+ type: MessageReactionTypes,
381
+ *,
382
+ auth_handlers: Optional[list[str]] = None,
383
+ **kwargs,
342
384
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
343
385
  """
344
386
  Registers a new message activity event listener. This method can be used as either
@@ -361,12 +403,12 @@ class AgentApplication(Agent, Generic[StateT]):
361
403
  return False
362
404
 
363
405
  if type == "reactionsAdded":
364
- if isinstance(context.activity.reactions_added, List):
406
+ if isinstance(context.activity.reactions_added, list):
365
407
  return len(context.activity.reactions_added) > 0
366
408
  return False
367
409
 
368
410
  if type == "reactionsRemoved":
369
- if isinstance(context.activity.reactions_removed, List):
411
+ if isinstance(context.activity.reactions_removed, list):
370
412
  return len(context.activity.reactions_removed) > 0
371
413
  return False
372
414
 
@@ -376,15 +418,17 @@ class AgentApplication(Agent, Generic[StateT]):
376
418
  logger.debug(
377
419
  f"Registering message reaction handler for route handler {func.__name__} with type: {type} with auth handlers: {auth_handlers}"
378
420
  )
379
- self._routes.append(
380
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
381
- )
421
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
382
422
  return func
383
423
 
384
424
  return __call
385
425
 
386
426
  def message_update(
387
- self, type: MessageUpdateTypes, *, auth_handlers: Optional[List[str]] = None
427
+ self,
428
+ type: MessageUpdateTypes,
429
+ *,
430
+ auth_handlers: Optional[list[str]] = None,
431
+ **kwargs,
388
432
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
389
433
  """
390
434
  Registers a new message activity event listener. This method can be used as either
@@ -435,14 +479,14 @@ class AgentApplication(Agent, Generic[StateT]):
435
479
  logger.debug(
436
480
  f"Registering message update handler for route handler {func.__name__} with type: {type} with auth handlers: {auth_handlers}"
437
481
  )
438
- self._routes.append(
439
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
440
- )
482
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
441
483
  return func
442
484
 
443
485
  return __call
444
486
 
445
- def handoff(self, *, auth_handlers: Optional[List[str]] = None) -> Callable[
487
+ def handoff(
488
+ self, *, auth_handlers: Optional[list[str]] = None, **kwargs
489
+ ) -> Callable[
446
490
  [Callable[[TurnContext, StateT, str], Awaitable[None]]],
447
491
  Callable[[TurnContext, StateT, str], Awaitable[None]],
448
492
  ]:
@@ -483,10 +527,7 @@ class AgentApplication(Agent, Generic[StateT]):
483
527
  f"Registering handoff handler for route handler {func.__name__} with auth handlers: {auth_handlers}"
484
528
  )
485
529
 
486
- self._routes.append(
487
- Route[StateT](__selector, __handler, True, auth_handlers)
488
- )
489
- self._routes = sorted(self._routes, key=lambda route: not route.is_invoke)
530
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
490
531
  return func
491
532
 
492
533
  return __call
@@ -598,7 +639,6 @@ class AgentApplication(Agent, Generic[StateT]):
598
639
  await self._start_long_running_call(context, self._on_turn)
599
640
 
600
641
  async def _on_turn(self, context: TurnContext):
601
- # robrandao: TODO
602
642
  try:
603
643
  if context.activity.type != ActivityTypes.typing:
604
644
  await self._start_typing(context)
@@ -663,7 +703,7 @@ class AgentApplication(Agent, Generic[StateT]):
663
703
  context.activity.text = context.remove_recipient_mention(context.activity)
664
704
 
665
705
  @staticmethod
666
- def parse_env_vars_configuration(vars: Dict[str, Any]) -> dict:
706
+ def parse_env_vars_configuration(vars: dict[str, Any]) -> dict:
667
707
  """
668
708
  Parses environment variables and returns a dictionary with the relevant configuration.
669
709
  """
@@ -738,7 +778,7 @@ class AgentApplication(Agent, Generic[StateT]):
738
778
  return True
739
779
 
740
780
  async def _on_activity(self, context: TurnContext, state: StateT):
741
- for route in self._routes:
781
+ for route in self._route_list:
742
782
  if route.selector(context):
743
783
  if not route.auth_handlers:
744
784
  await route.handler(context, state)
@@ -1,3 +1,7 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+
1
5
  from .authorization import Authorization
2
6
  from .auth_handler import AuthHandler
3
7
  from ._sign_in_state import _SignInState
@@ -1,3 +1,8 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
1
6
  from .agentic_user_authorization import AgenticUserAuthorization
2
7
  from ._user_authorization import _UserAuthorization
3
8
  from ._authorization_handler import _AuthorizationHandler
@@ -1,3 +1,8 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
1
6
  from abc import ABC
2
7
  from typing import Optional
3
8
  import logging
@@ -1,5 +1,7 @@
1
- # Copyright (c) Microsoft Corporation. All rights reserved.
2
- # Licensed under the MIT License.
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
3
5
 
4
6
  from __future__ import annotations
5
7
  import logging
@@ -1,3 +1,8 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
1
6
  import logging
2
7
 
3
8
  from typing import Optional
@@ -1,3 +1,7 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+
1
5
  from typing import Optional
2
6
 
3
7
  from microsoft_agents.activity import TokenResponse
@@ -1,3 +1,8 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
1
6
  from __future__ import annotations
2
7
 
3
8
  from typing import Optional
@@ -1,5 +1,7 @@
1
- # Copyright (c) Microsoft Corporation. All rights reserved.
2
- # Licensed under the MIT License.
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
3
5
 
4
6
  import logging
5
7
  from typing import Optional
@@ -1,3 +1,8 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
1
6
  from datetime import datetime
2
7
  import logging
3
8
  from typing import TypeVar, Optional, Callable, Awaitable, Generic, cast
@@ -1,3 +1,6 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
1
4
  from typing import Protocol, Optional
2
5
  from abc import abstractmethod
3
6
 
@@ -1,3 +1,6 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
1
4
  from typing import Optional
2
5
 
3
6
  from microsoft_agents.hosting.core.authorization.auth_types import AuthTypes
@@ -1,3 +1,6 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
1
4
  from typing import Optional
2
5
 
3
6
  from .access_token_provider_base import AccessTokenProviderBase
@@ -1,3 +1,6 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
1
4
  from enum import Enum
2
5
 
3
6
 
@@ -1,3 +1,6 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
1
4
  from abc import abstractmethod
2
5
  from typing import Protocol
3
6
 
@@ -1,3 +1,6 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
1
4
  import logging
2
5
  import jwt
3
6