From a384100c5bce013b31050edd949ea6af6a06f668 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Tue, 23 Jun 2026 13:16:22 -0700 Subject: [PATCH 1/5] Adding connection_manager property to AgentApplication --- .../hosting/core/app/agent_application.py | 18 +++++++ .../app/test_agent_application.py | 47 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py index 9f8bf220..78744a7a 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py @@ -76,6 +76,7 @@ class AgentApplication(Agent, Generic[StateT]): _route_list: _RouteList[StateT] _error: Optional[Callable[[TurnContext, Exception], Awaitable[None]]] = None _turn_state_factory: Optional[Callable[[TurnContext], StateT]] = None + _connection_manager: Connections def __init__( self, @@ -159,7 +160,13 @@ def __init__( # TODO: decide how to initialize the Authorization (params vs options vs kwargs) if authorization: + if connection_manager: + logger.error("AgentApplication: connection_manager is not needed when authorization is provided.") + raise ApplicationError( + "The `AgentApplication` does not take a `connection_manager` when `authorization` is provided." + ) self._auth = authorization + self._connection_manager = self._auth.connection_manager else: if not connection_manager: logger.error( @@ -181,6 +188,17 @@ def __init__( handlers=options.authorization_handlers, **auth_options, ) + self._connection_manager = connection_manager + + @property + def connection_manager(self) -> Connections: + """ + The application's connection manager. + + :return: The connection manager for the application. + :rtype: :class:`microsoft_agents.hosting.core.app.connections.Connections` + """ + return self._connection_manager @property def adapter(self) -> ChannelServiceAdapter: diff --git a/tests/hosting_core/app/test_agent_application.py b/tests/hosting_core/app/test_agent_application.py index 54871803..30c56f73 100644 --- a/tests/hosting_core/app/test_agent_application.py +++ b/tests/hosting_core/app/test_agent_application.py @@ -433,3 +433,50 @@ async def on_event(ctx, state): await app.on_turn(StubTurnContext(_make_event_activity())) assert calls == ["event", "after"] + + +# --------------------------------------------------------------------------- +# connection_manager property and constructor guard +# --------------------------------------------------------------------------- + + +def test_init_raises_when_both_authorization_and_connection_manager_provided(): + """Providing both authorization and connection_manager is ambiguous and should raise.""" + with pytest.raises(ApplicationError): + AgentApplication[TurnState]( + options=ApplicationOptions(storage=MemoryStorage()), + authorization=make_auth(), + connection_manager=_ConnectionManager(), + ) + + +def test_connection_manager_property_returns_manager_from_authorization(): + """When authorization is provided, connection_manager property reflects auth's manager.""" + cm = _ConnectionManager() + auth = Authorization(storage=MemoryStorage(), connection_manager=cm) + app = AgentApplication[TurnState]( + options=ApplicationOptions(storage=MemoryStorage()), + authorization=auth, + ) + assert app.connection_manager is cm + + +def test_connection_manager_property_returns_directly_passed_manager(): + """When connection_manager kwarg is used (no authorization), the property returns it.""" + cm = _ConnectionManager() + app = AgentApplication[TurnState]( + options=ApplicationOptions(storage=MemoryStorage()), + connection_manager=cm, + ) + assert app.connection_manager is cm + + +def test_init_with_connection_manager_only_creates_auth(): + """Passing only connection_manager should auto-create an Authorization instance.""" + cm = _ConnectionManager() + app = AgentApplication[TurnState]( + options=ApplicationOptions(storage=MemoryStorage()), + connection_manager=cm, + ) + assert app.auth is not None + assert app.connection_manager is cm From 87ece696d7ea79519512da1eb7603c8a2e7fb474 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Tue, 23 Jun 2026 13:17:54 -0700 Subject: [PATCH 2/5] Formatting --- .../microsoft_agents/hosting/core/app/agent_application.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py index 78744a7a..b8bf3d1d 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py @@ -161,7 +161,9 @@ def __init__( # TODO: decide how to initialize the Authorization (params vs options vs kwargs) if authorization: if connection_manager: - logger.error("AgentApplication: connection_manager is not needed when authorization is provided.") + logger.error( + "AgentApplication: connection_manager is not needed when authorization is provided." + ) raise ApplicationError( "The `AgentApplication` does not take a `connection_manager` when `authorization` is provided." ) From a012ac7cd56cfb42d2bbf3956aa3d20120f80c1a Mon Sep 17 00:00:00 2001 From: rodrigobr-msft Date: Tue, 23 Jun 2026 13:20:35 -0700 Subject: [PATCH 3/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../microsoft_agents/hosting/core/app/agent_application.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py index b8bf3d1d..64f61023 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py @@ -198,8 +198,7 @@ def connection_manager(self) -> Connections: The application's connection manager. :return: The connection manager for the application. - :rtype: :class:`microsoft_agents.hosting.core.app.connections.Connections` - """ + :rtype: :class:`microsoft_agents.hosting.core.authorization.Connections` return self._connection_manager @property From 0be0c7b6852005cc6facf0ebaee3788c38daafae Mon Sep 17 00:00:00 2001 From: rodrigobr-msft Date: Tue, 23 Jun 2026 13:25:26 -0700 Subject: [PATCH 4/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../microsoft_agents/hosting/core/app/agent_application.py | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py index 64f61023..d0e85e02 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py @@ -199,6 +199,7 @@ def connection_manager(self) -> Connections: :return: The connection manager for the application. :rtype: :class:`microsoft_agents.hosting.core.authorization.Connections` + """ return self._connection_manager @property From 5a0d24efc9fb9011112f239464dd28d126849da9 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Tue, 23 Jun 2026 13:27:40 -0700 Subject: [PATCH 5/5] Fixing AppOptions usage for auth_handlers --- .../microsoft_agents/hosting/core/app/agent_application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py index b8bf3d1d..2225fcab 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py @@ -187,7 +187,7 @@ def __init__( self._auth = Authorization( storage=self._options.storage, connection_manager=connection_manager, - handlers=options.authorization_handlers, + auth_handlers=options.authorization_handlers, **auth_options, ) self._connection_manager = connection_manager