Skip to content

Commit f6913e3

Browse files
authored
Enhance type annotations in various modules for improved clarity and consistency (#162)
1 parent b1930c9 commit f6913e3

File tree

7 files changed

+200
-47
lines changed

7 files changed

+200
-47
lines changed

libraries/microsoft-agents-activity/microsoft_agents/activity/semantic_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SemanticAction(AgentsModel):
1313
:param entities: Entities associated with this action
1414
:type entities: dict[str, :class:`microsoft_agents.activity.entity.Entity`]
1515
:param state: State of this action. Allowed values: `start`, `continue`, `done`
16-
:type state: str or :class:`microsoft_agents.activity.semantic_action_states.SemanticActionStates`
16+
:type state: str or :class:`microsoft_agents.activity.semantic_actions_states.SemanticActionsStates`
1717
"""
1818

1919
id: NonEmptyString

libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_connection_manager.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(
2828
Initialize the MSAL connection manager.
2929
3030
:arg connections_configurations: A dictionary of connection configurations.
31-
:type connections_configurations: Dict[str, AgentAuthConfiguration]
31+
:type connections_configurations: Dict[str, :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`]
3232
:arg connections_map: A list of connection mappings.
3333
:type connections_map: List[Dict[str, str]]
3434
:raises ValueError: If no service connection configuration is provided.
@@ -64,16 +64,19 @@ def get_connection(self, connection_name: Optional[str]) -> AccessTokenProviderB
6464
Get the OAuth connection for the agent.
6565
6666
:arg connection_name: The name of the connection.
67-
:type connection_name: str
67+
:type connection_name: Optional[str]
6868
:return: The OAuth connection for the agent.
69-
:rtype: AccessTokenProviderBase
69+
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
7070
"""
7171
# should never be None
7272
return self._connections.get(connection_name, None)
7373

7474
def get_default_connection(self) -> AccessTokenProviderBase:
7575
"""
7676
Get the default OAuth connection for the agent.
77+
78+
:return: The default OAuth connection for the agent.
79+
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
7780
"""
7881
# should never be None
7982
return self._connections.get("SERVICE_CONNECTION", None)
@@ -85,11 +88,11 @@ def get_token_provider(
8588
Get the OAuth token provider for the agent.
8689
8790
:arg claims_identity: The claims identity of the bot.
88-
:type claims_identity: ClaimsIdentity
91+
:type claims_identity: :class:`microsoft_agents.hosting.core.ClaimsIdentity`
8992
:arg service_url: The service URL of the bot.
9093
:type service_url: str
9194
:return: The OAuth token provider for the agent.
92-
:rtype: AccessTokenProviderBase
95+
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
9396
:raises ValueError: If no connection is found for the given audience and service URL.
9497
"""
9598
if not claims_identity or not service_url:
@@ -130,5 +133,8 @@ def get_token_provider(
130133
def get_default_connection_configuration(self) -> AgentAuthConfiguration:
131134
"""
132135
Get the default connection configuration for the agent.
136+
137+
:return: The default connection configuration for the agent.
138+
:rtype: :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`
133139
"""
134140
return self._service_connection_configuration

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/activity_handler.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async def on_members_added_activity(
176176
177177
:param members_added: A list of all the members added to the conversation, as described by the
178178
conversation update activity
179-
:type members_added: list[ChannelAccount]
179+
:type members_added: list[:class:`microsoft_agents.activity.ChannelAccount`]
180180
:param turn_context: The context object for this turn
181181
:type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
182182
:returns: A task that represents the work queued to execute
@@ -195,9 +195,9 @@ async def on_members_removed_activity(
195195
Override this method in a derived class to provide logic for when members other than the agent leave
196196
the conversation. You can add your agent's good-bye logic.
197197
198-
:param members_added: A list of all the members removed from the conversation, as described by the
198+
:param members_removed: A list of all the members removed from the conversation, as described by the
199199
conversation update activity
200-
:type members_added: list[ChannelAccount]
200+
:type members_removed: list[:class:`microsoft_agents.activity.ChannelAccount`]
201201
:param turn_context: The context object for this turn
202202
:type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
203203
:returns: A task that represents the work queued to execute
@@ -260,7 +260,7 @@ async def on_reactions_added( # pylint: disable=unused-argument
260260
are added to the conversation.
261261
262262
:param message_reactions: The list of reactions added
263-
:type message_reactions: list[MessageReaction]
263+
:type message_reactions: list[:class:`microsoft_agents.activity.MessageReaction`]
264264
:param turn_context: The context object for this turn
265265
:type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
266266
:returns: A task that represents the work queued to execute
@@ -285,7 +285,7 @@ async def on_reactions_removed( # pylint: disable=unused-argument
285285
are removed from the conversation.
286286
287287
:param message_reactions: The list of reactions removed
288-
:type message_reactions: list[MessageReaction]
288+
:type message_reactions: list[:class:`microsoft_agents.activity.MessageReaction`]
289289
:param turn_context: The context object for this turn
290290
:type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
291291
@@ -459,6 +459,7 @@ async def on_invoke_activity( # pylint: disable=unused-argument
459459
:type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
460460
461461
:returns: A task that represents the work queued to execute
462+
:rtype: Optional[:class:`microsoft_agents.activity.InvokeResponse`]
462463
"""
463464
try:
464465
if (
@@ -510,8 +511,9 @@ async def on_adaptive_card_invoke(
510511
:param turn_context: A context object for this turn.
511512
:type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
512513
:param invoke_value: A string-typed object from the incoming activity's value.
513-
:type invoke_value: :class:`microsoft_agents.activity.adaptive_card_invoke_value.AdaptiveCardInvokeValue`
514+
:type invoke_value: :class:`microsoft_agents.activity.AdaptiveCardInvokeValue`
514515
:return: The HealthCheckResponse object
516+
:rtype: :class:`microsoft_agents.activity.AdaptiveCardInvokeResponse`
515517
"""
516518
raise _InvokeResponseException(HTTPStatus.NOT_IMPLEMENTED)
517519

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ def __init__(
8383
) -> None:
8484
"""
8585
Creates a new AgentApplication instance.
86+
87+
:param options: Configuration options for the application.
88+
:type options: Optional[:class:`microsoft_agents.hosting.core.app.app_options.ApplicationOptions`]
89+
:param connection_manager: OAuth connection manager.
90+
:type connection_manager: Optional[:class:`microsoft_agents.hosting.core.authorization.Connections`]
91+
:param authorization: Authorization manager for handling authentication flows.
92+
:type authorization: Optional[:class:`microsoft_agents.hosting.core.app.oauth.Authorization`]
93+
:param kwargs: Additional configuration parameters.
94+
:type kwargs: Any
8695
"""
8796
self.typing = TypingIndicator()
8897
self._route_list = _RouteList[StateT]()
@@ -161,6 +170,10 @@ def __init__(
161170
def adapter(self) -> ChannelServiceAdapter:
162171
"""
163172
The bot's adapter.
173+
174+
:return: The channel service adapter for the bot.
175+
:rtype: :class:`microsoft_agents.hosting.core.channel_service_adapter.ChannelServiceAdapter`
176+
:raises ApplicationError: If the adapter is not configured.
164177
"""
165178

166179
if not self._adapter:
@@ -181,6 +194,10 @@ def adapter(self) -> ChannelServiceAdapter:
181194
def auth(self) -> Authorization:
182195
"""
183196
The application's authentication manager
197+
198+
:return: The authentication manager for handling OAuth flows.
199+
:rtype: :class:`microsoft_agents.hosting.core.app.oauth.Authorization`
200+
:raises ApplicationError: If authentication is not configured.
184201
"""
185202
if not self._auth:
186203
logger.error(
@@ -200,6 +217,9 @@ def auth(self) -> Authorization:
200217
def options(self) -> ApplicationOptions:
201218
"""
202219
The application's configured options.
220+
221+
:return: The configuration options for the application.
222+
:rtype: :class:`microsoft_agents.hosting.core.app.app_options.ApplicationOptions`
203223
"""
204224
return self._options
205225

@@ -217,16 +237,16 @@ def add_route(
217237
Routes are ordered by: is_agentic, is_invoke, rank (lower is higher priority), in that order.
218238
219239
:param selector: A function that takes a TurnContext and returns a boolean indicating whether the route should be selected.
220-
:type selector: RouteSelector
240+
:type selector: :class:`microsoft_agents.hosting.core.app._type_defs.RouteSelector`
221241
:param handler: A function that takes a TurnContext and a TurnState and returns an Awaitable.
222-
:type handler: RouteHandler[StateT]
242+
:type handler: :class:`microsoft_agents.hosting.core.app._type_defs.RouteHandler`[StateT]
223243
:param is_invoke: Whether the route is for an invoke activity, defaults to False
224244
:type is_invoke: bool, Optional
225245
:param is_agentic: Whether the route is for an agentic request, defaults to False. For agentic requests
226246
the selector will include a new check for `context.activity.is_agentic_request()`.
227247
:type is_agentic: bool, Optional
228248
:param rank: The rank of the route, defaults to RouteRank.DEFAULT
229-
:type rank: RouteRank, Optional
249+
:type rank: :class:`microsoft_agents.hosting.core.app._routes.RouteRank`, Optional
230250
:param auth_handlers: A list of authentication handler IDs to use for this route, defaults to None
231251
:type auth_handlers: Optional[list[str]], Optional
232252
:raises ApplicationError: If the selector or handler are not valid.
@@ -706,6 +726,11 @@ def _remove_mentions(self, context: TurnContext):
706726
def parse_env_vars_configuration(vars: dict[str, Any]) -> dict:
707727
"""
708728
Parses environment variables and returns a dictionary with the relevant configuration.
729+
730+
:param vars: Dictionary of environment variable names and values.
731+
:type vars: dict[str, Any]
732+
:return: Parsed configuration dictionary with nested structure.
733+
:rtype: dict
709734
"""
710735
result = {}
711736
for key, value in vars.items():

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/authorization.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ def __init__(
5555
only if auth_handlers is empty or None.
5656
5757
:param storage: The storage system to use for state management.
58-
:type storage: Storage
58+
:type storage: :class:`microsoft_agents.hosting.core.storage.Storage`
5959
:param connection_manager: The connection manager for OAuth providers.
60-
:type connection_manager: Connections
60+
:type connection_manager: :class:`microsoft_agents.hosting.core.authorization.Connections`
6161
:param auth_handlers: Configuration for OAuth providers.
62-
:type auth_handlers: dict[str, AuthHandler], Optional
62+
:type auth_handlers: dict[str, :class:`microsoft_agents.hosting.core.app.oauth.auth_handler.AuthHandler`], Optional
6363
:raises ValueError: When storage is None or no auth handlers provided.
6464
"""
6565
if not storage:
@@ -105,7 +105,7 @@ def _init_handlers(self) -> None:
105105
it initializes an instance of each variant that is referenced.
106106
107107
:param auth_handlers: A dictionary of auth handler configurations.
108-
:type auth_handlers: dict[str, AuthHandler]
108+
:type auth_handlers: dict[str, :class:`microsoft_agents.hosting.core.app.oauth.auth_handler.AuthHandler`]
109109
"""
110110
for name, auth_handler in self._handler_settings.items():
111111
auth_type = auth_handler.auth_type
@@ -126,26 +126,42 @@ def _sign_in_state_key(context: TurnContext) -> str:
126126
can be used to inspect or manipulate the state directly if needed.
127127
128128
:param context: The turn context for the current turn of conversation.
129-
:type context: TurnContext
129+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
130130
:return: A unique (across other values of channel_id and user_id) key for the sign-in state.
131131
:rtype: str
132132
"""
133133
return f"auth:_SignInState:{context.activity.channel_id}:{context.activity.from_property.id}"
134134

135135
async def _load_sign_in_state(self, context: TurnContext) -> Optional[_SignInState]:
136-
"""Load the sign-in state from storage for the given context."""
136+
"""Load the sign-in state from storage for the given context.
137+
138+
:param context: The turn context for the current turn of conversation.
139+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
140+
:return: The sign-in state if found, None otherwise.
141+
:rtype: Optional[:class:`microsoft_agents.hosting.core.app.oauth._sign_in_state._SignInState`]
142+
"""
137143
key = self._sign_in_state_key(context)
138144
return (await self._storage.read([key], target_cls=_SignInState)).get(key)
139145

140146
async def _save_sign_in_state(
141147
self, context: TurnContext, state: _SignInState
142148
) -> None:
143-
"""Save the sign-in state to storage for the given context."""
149+
"""Save the sign-in state to storage for the given context.
150+
151+
:param context: The turn context for the current turn of conversation.
152+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
153+
:param state: The sign-in state to save.
154+
:type state: :class:`microsoft_agents.hosting.core.app.oauth._sign_in_state._SignInState`
155+
"""
144156
key = self._sign_in_state_key(context)
145157
await self._storage.write({key: state})
146158

147159
async def _delete_sign_in_state(self, context: TurnContext) -> None:
148-
"""Delete the sign-in state from storage for the given context."""
160+
"""Delete the sign-in state from storage for the given context.
161+
162+
:param context: The turn context for the current turn of conversation.
163+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
164+
"""
149165
key = self._sign_in_state_key(context)
150166
await self._storage.delete([key])
151167

@@ -179,7 +195,7 @@ def _resolve_handler(self, handler_id: str) -> _AuthorizationHandler:
179195
:param handler_id: The ID of the auth handler to resolve.
180196
:type handler_id: str
181197
:return: The corresponding AuthorizationHandler instance.
182-
:rtype: AuthorizationHandler
198+
:rtype: :class:`microsoft_agents.hosting.core.app.oauth._handlers._AuthorizationHandler`
183199
:raises ValueError: If the handler ID is not recognized or not configured.
184200
"""
185201
if handler_id not in self._handlers:
@@ -200,13 +216,13 @@ async def _start_or_continue_sign_in(
200216
Storage is updated as needed with _SignInState data for caching purposes.
201217
202218
:param context: The turn context for the current turn of conversation.
203-
:type context: TurnContext
219+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
204220
:param state: The turn state for the current turn of conversation.
205-
:type state: TurnState
221+
:type state: :class:`microsoft_agents.hosting.core.app.state.turn_state.TurnState`
206222
:param auth_handler_id: The ID of the auth handler to use for sign-in. If None, the first handler will be used.
207223
:type auth_handler_id: str
208224
:return: A _SignInResponse indicating the result of the sign-in attempt.
209-
:rtype: _SignInResponse
225+
:rtype: :class:`microsoft_agents.hosting.core.app.oauth._sign_in_response._SignInResponse`
210226
"""
211227

212228
auth_handler_id = auth_handler_id or self._default_handler_id
@@ -250,7 +266,7 @@ async def sign_out(
250266
"""Attempts to sign out the user from a specified auth handler or the default handler.
251267
252268
:param context: The turn context for the current turn of conversation.
253-
:type context: TurnContext
269+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
254270
:param auth_handler_id: The ID of the auth handler to sign out from. If None, sign out from all handlers.
255271
:type auth_handler_id: Optional[str]
256272
:return: None
@@ -272,11 +288,11 @@ async def _on_turn_auth_intercept(
272288
from the cached _SignInState.
273289
274290
:param context: The context object for the current turn.
275-
:type context: TurnContext
291+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
276292
:param state: The turn state for the current turn.
277-
:type state: TurnState
293+
:type state: :class:`microsoft_agents.hosting.core.app.state.turn_state.TurnState`
278294
:return: A tuple indicating whether the turn should be skipped and the continuation activity if applicable.
279-
:rtype: tuple[bool, Optional[Activity]]
295+
:rtype: tuple[bool, Optional[:class:`microsoft_agents.activity.Activity`]]
280296
"""
281297
sign_in_state = await self._load_sign_in_state(context)
282298

@@ -306,11 +322,11 @@ async def get_token(
306322
The token is taken from cache, so this does not initiate nor continue a sign-in flow.
307323
308324
:param context: The context object for the current turn.
309-
:type context: TurnContext
325+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
310326
:param auth_handler_id: The ID of the auth handler to get the token for.
311327
:type auth_handler_id: str
312328
:return: The token response from the OAuth provider.
313-
:rtype: TokenResponse
329+
:rtype: :class:`microsoft_agents.activity.TokenResponse`
314330
"""
315331
return await self.exchange_token(context, auth_handler_id=auth_handler_id)
316332

@@ -324,7 +340,7 @@ async def exchange_token(
324340
"""Exchanges or refreshes the token for a specific auth handler or the default handler.
325341
326342
:param context: The context object for the current turn.
327-
:type context: TurnContext
343+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
328344
:param scopes: The scopes to request during the token exchange or refresh. Defaults
329345
to the list given in the AuthHandler configuration if None.
330346
:type scopes: Optional[list[str]]
@@ -335,7 +351,7 @@ async def exchange_token(
335351
the connection defined in the AuthHandler configuration will be used.
336352
:type exchange_connection: Optional[str]
337353
:return: The token response from the OAuth provider.
338-
:rtype: TokenResponse
354+
:rtype: :class:`microsoft_agents.activity.TokenResponse`
339355
:raises ValueError: If the specified auth handler ID is not recognized or not configured.
340356
"""
341357

@@ -376,6 +392,7 @@ def on_sign_in_success(
376392
Sets a handler to be called when sign-in is successfully completed.
377393
378394
:param handler: The handler function to call on successful sign-in.
395+
:type handler: Callable[[:class:`microsoft_agents.hosting.core.turn_context.TurnContext`, :class:`microsoft_agents.hosting.core.app.state.turn_state.TurnState`, Optional[str]], Awaitable[None]]
379396
"""
380397
self._sign_in_success_handler = handler
381398

@@ -387,5 +404,6 @@ def on_sign_in_failure(
387404
Sets a handler to be called when sign-in fails.
388405
389406
:param handler: The handler function to call on sign-in failure.
407+
:type handler: Callable[[:class:`microsoft_agents.hosting.core.turn_context.TurnContext`, :class:`microsoft_agents.hosting.core.app.state.turn_state.TurnState`, Optional[str]], Awaitable[None]]
390408
"""
391409
self._sign_in_failure_handler = handler

0 commit comments

Comments
 (0)