nat.plugins.a365.front_end.worker#
Worker for Microsoft Agent 365 front-end plugin.
This worker encapsulates the Microsoft Agents SDK integration logic, allowing for extensibility and better separation of concerns.
Attributes#
Classes#
Worker that handles Microsoft Agents SDK setup and configuration. |
Module Contents#
- logger#
- class A365FrontEndPluginWorker(config: nat.data_models.config.Config)#
Worker that handles Microsoft Agents SDK setup and configuration.
This class encapsulates the implementation details of integrating NAT workflows with the Microsoft Agents SDK, allowing for extensibility through subclassing and better separation of concerns from the plugin orchestration logic.
Initialize the A365 worker with configuration.
- Args:
config: The full NAT configuration
- full_config#
- front_end_config: nat.plugins.a365.front_end.front_end_config.A365FrontEndConfig#
- _get_storage() microsoft_agents.hosting.core.storage.Storage#
Get the storage instance for the AgentApplication.
Uses dependency injection pattern - returns Storage Protocol implementation. Defaults to MemoryStorage, but can be overridden for custom storage (e.g., BlobStorage, CosmosDbStorage).
- Returns:
Storage: A Storage Protocol implementation (default: MemoryStorage)
- _build_connection_configurations(
- service_connection: microsoft_agents.hosting.core.AgentAuthConfiguration,
Build SDK connection configs, including optional JWT audience aliases.
The Microsoft Agents SDK validates inbound JWT audiences via
AgentAuthConfiguration._jwt_patch_is_valid_aud(a private SDK method, as indicated by the_jwt_patch_prefix).MsalConnectionManager.__init__cross-populatesAgentAuthConfiguration._connectionson every config inconnections_configurations(the “# JWT-patch” loop in 0.8.0 wheels), so adding alias entries here is enough to make Bot Framework / Teams tokens with non-app_idaudiences pass JWT validation.SECURITY NOTE: alias entries are constructed as fully-functional
AgentAuthConfigurationobjects carrying the bot’s realclient_secret. Today the SDK only consults aliases on the inbound audience-validation path, but each alias is also registered as an outboundMsalAuthprovider keyed by the aliasclient_id. If a future SDK feature (e.g.connections_map) routes outbound token acquisition through an alias, MSAL will attempt to mint a token forclient_id=<alias_audience>using the bot’s secret – which Azure AD will reject. This is not a credential-leak vector but it does mean the secret is now copied into N+1 in-memoryMsalAuthinstances. Worth revisiting if/when the SDK exposes an audience-only validation API.STABILITY NOTE: the underlying mechanism depends on SDK private members (
_connections,_jwt_patch_is_valid_aud). A test intests/front_end/test_integration.pyexercises the SDK end-to-end so regressions surface before shipping.
- _get_connection_manager(
- service_connection: microsoft_agents.hosting.core.AgentAuthConfiguration,
Get the connection manager instance for the AgentApplication.
Defaults to MsalConnectionManager with a single
SERVICE_CONNECTIONentry (required by the Microsoft Agents SDK 0.8+ MSAL integration).- Args:
service_connection: Auth configuration for the bot’s service connection.
- Returns:
Connections: A Connections implementation (default: MsalConnectionManager)
- async create_agent_application() tuple[microsoft_agents.hosting.core.AgentApplication[microsoft_agents.hosting.core.TurnState], microsoft_agents.hosting.core.authorization.Connections, microsoft_agents.hosting.aiohttp.CloudAdapter]#
Create and initialize Microsoft Agents SDK application.
- Returns:
Initialized
AgentApplication,Connections(MSAL manager), and aiohttpCloudAdapter(used by the HTTP server andAgentApplicationoptions).- Raises:
A365ConfigurationError: If configuration is invalid (missing fields, wrong types) A365SDKError: If SDK component initialization fails
- async setup_notification_handlers(
- agent_app: microsoft_agents.hosting.core.AgentApplication,
- session_manager: nat.runtime.session.SessionManager,
Set up A365 notification handlers.
- Args:
agent_app: The Microsoft Agents SDK AgentApplication instance session_manager: SessionManager for executing NAT workflows
- async setup_message_handlers(
- agent_app: microsoft_agents.hosting.core.AgentApplication,
- session_manager: nat.runtime.session.SessionManager,
Set up message handlers for regular chat messages.
- Args:
agent_app: The Microsoft Agents SDK AgentApplication instance session_manager: SessionManager for executing NAT workflows