From 646af6c5ef2239461f004d5ea8f7fcef2d075604 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Wed, 15 Oct 2025 11:37:42 -0700 Subject: [PATCH 1/7] Changing usage of upn property to agentic_user_id --- .../microsoft_agents/activity/activity.py | 4 +-- .../authentication/msal/msal_auth.py | 32 +++++++++---------- .../_handlers/agentic_user_authorization.py | 12 +++---- .../access_token_provider_base.py | 2 +- .../authorization/anonymous_token_provider.py | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py b/libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py index b3189742..4a9c3d1d 100644 --- a/libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py +++ b/libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py @@ -664,7 +664,7 @@ def get_agentic_instance_id(self) -> Optional[str]: return self.recipient.agentic_app_id def get_agentic_user(self) -> Optional[str]: - """Gets the agentic user (UPN) from the context if it's an agentic request.""" + """Gets the agentic user (agenticUserId) from the context if it's an agentic request.""" if not self.is_agentic_request() or not self.recipient: return None - return self.recipient.id + return self.recipient.agentic_user_id diff --git a/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py b/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py index 2f0d34d9..ac10e3fc 100644 --- a/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py +++ b/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py @@ -311,28 +311,28 @@ async def get_agentic_instance_token( return agentic_instance_token["access_token"], agent_token_result async def get_agentic_user_token( - self, agent_app_instance_id: str, upn: str, scopes: list[str] + self, agent_app_instance_id: str, agentic_user_id: str, scopes: list[str] ) -> Optional[str]: """Gets the agentic user token for the given agent application instance ID and user principal name and the scopes. :param agent_app_instance_id: The agent application instance ID. :type agent_app_instance_id: str - :param upn: The user principal name. - :type upn: str + :param agentic_user_id: The agentic user ID. + :type agentic_user_id: str :param scopes: The scopes to request for the token. :type scopes: list[str] :return: The agentic user token, or None if not found. :rtype: Optional[str] """ - if not agent_app_instance_id or not upn: + if not agent_app_instance_id or not agentic_user_id: raise ValueError( "Agent application instance Id and user principal name must be provided." ) logger.info( - "Attempting to get agentic user token from agent_app_instance_id %s and upn %s", + "Attempting to get agentic user token from agent_app_instance_id %s and agentic_user_id %s", agent_app_instance_id, - upn, + agentic_user_id, ) instance_token, agent_token = await self.get_agentic_instance_token( agent_app_instance_id @@ -340,12 +340,12 @@ async def get_agentic_user_token( if not instance_token or not agent_token: logger.error( - "Failed to acquire instance token or agent token for agent_app_instance_id %s and upn %s", + "Failed to acquire instance token or agent token for agent_app_instance_id %s and agentic_user_id %s", agent_app_instance_id, - upn, + agentic_user_id, ) raise Exception( - f"Failed to acquire instance token or agent token for agent_app_instance_id {agent_app_instance_id} and upn {upn}" + f"Failed to acquire instance token or agent token for agent_app_instance_id {agent_app_instance_id} and agentic_user_id {agentic_user_id}" ) authority = ( @@ -359,14 +359,14 @@ async def get_agentic_user_token( ) logger.info( - "Acquiring agentic user token for agent_app_instance_id %s and upn %s", + "Acquiring agentic user token for agent_app_instance_id %s and agentic_user_id %s", agent_app_instance_id, - upn, + agentic_user_id, ) auth_result_payload = instance_app.acquire_token_for_client( scopes, data={ - "username": upn, + "username": agentic_user_id, "user_federated_identity_credential": instance_token, "grant_type": "user_fic", }, @@ -374,9 +374,9 @@ async def get_agentic_user_token( if not auth_result_payload: logger.error( - "Failed to acquire agentic user token for agent_app_instance_id %s and upn %s, %s", + "Failed to acquire agentic user token for agent_app_instance_id %s and agentic_user_id %s, %s", agent_app_instance_id, - upn, + agentic_user_id, auth_result_payload, ) return None @@ -384,9 +384,9 @@ async def get_agentic_user_token( access_token = auth_result_payload.get("access_token") if not access_token: logger.error( - "Failed to acquire agentic user token for agent_app_instance_id %s and upn %s, %s", + "Failed to acquire agentic user token for agent_app_instance_id %s and agentic_user_id %s, %s", agent_app_instance_id, - upn, + agentic_user_id, auth_result_payload, ) return None diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py index 7c8a5a30..eaabdf8c 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py @@ -118,20 +118,20 @@ async def get_agentic_user_token( connection = self._connection_manager.get_token_provider( context.identity, "agentic" ) - upn = context.activity.get_agentic_user() + agentic_user_id = context.activity.get_agentic_user() agentic_instance_id = context.activity.get_agentic_instance_id() - if not upn or not agentic_instance_id: + if not agentic_user_id or not agentic_instance_id: logger.error( - "Unable to retrieve agentic user token: missing UPN or agentic instance ID. UPN: %s, Agentic Instance ID: %s", - upn, + "Unable to retrieve agentic user token: missing agentic user Id or agentic instance Id. agentic_user_id: %s, Agentic Instance ID: %s", + agentic_user_id, agentic_instance_id, ) raise ValueError( - f"Unable to retrieve agentic user token: missing UPN or agentic instance ID. UPN: {upn}, Agentic Instance ID: {agentic_instance_id}" + f"Unable to retrieve agentic user token: missing agentic User Id or agentic instance Id. agentic_user_id: {agentic_user_id}, Agentic Instance ID: {agentic_instance_id}" ) token = await connection.get_agentic_user_token( - agentic_instance_id, upn, scopes + agentic_instance_id, agentic_user_id, scopes ) return TokenResponse(token=token) if token else TokenResponse() diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/access_token_provider_base.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/access_token_provider_base.py index d319c3fd..4d0a593d 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/access_token_provider_base.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/access_token_provider_base.py @@ -43,6 +43,6 @@ async def get_agentic_instance_token( raise NotImplementedError() async def get_agentic_user_token( - self, agent_app_instance_id: str, upn: str, scopes: list[str] + self, agent_app_instance_id: str, agentic_user_id: str, scopes: list[str] ) -> Optional[str]: raise NotImplementedError() diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/anonymous_token_provider.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/anonymous_token_provider.py index 29c3de8c..d262c586 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/anonymous_token_provider.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/anonymous_token_provider.py @@ -33,6 +33,6 @@ async def get_agentic_instance_token( return "", "" async def get_agentic_user_token( - self, agent_app_instance_id: str, upn: str, scopes: list[str] + self, agent_app_instance_id: str, agentic_user_id: str, scopes: list[str] ) -> Optional[str]: return "" From 8269a7cf4674f87fb10dca799c4fa0c0c68d0bcd Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Wed, 15 Oct 2025 11:46:35 -0700 Subject: [PATCH 2/7] Fixing tests --- tests/activity/test_activity.py | 11 ++++++----- .../_handlers/test_agentic_user_authorization.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/activity/test_activity.py b/tests/activity/test_activity.py index 24d70008..7794a387 100644 --- a/tests/activity/test_activity.py +++ b/tests/activity/test_activity.py @@ -436,7 +436,8 @@ def agentic_role(self, request): ) def test_is_agentic_request(self, role, expected): activity = Activity( - type="message", recipient=ChannelAccount(id="bot", name="bot", role=role) + type="message", + recipient=ChannelAccount(agentic_user_id="bot", name="bot", role=role), ) assert activity.is_agentic_request() == expected @@ -444,7 +445,7 @@ def test_get_agentic_instance_id_is_agentic(self, mocker, agentic_role): activity = Activity( type="message", recipient=ChannelAccount( - id="some_id", + agentic_user_id="some_id", agentic_app_id=DEFAULTS.agentic_instance_id, role=agentic_role, ), @@ -455,7 +456,7 @@ def test_get_agentic_instance_id_not_agentic(self, non_agentic_role): activity = Activity( type="message", recipient=ChannelAccount( - id="some_id", + agentic_user_id="some_id", agentic_app_id=DEFAULTS.agentic_instance_id, role=non_agentic_role, ), @@ -466,7 +467,7 @@ def test_get_agentic_user_is_agentic(self, agentic_role): activity = Activity( type="message", recipient=ChannelAccount( - id=DEFAULTS.agentic_user_id, + agentic_user_id=DEFAULTS.agentic_user_id, agentic_app_id=DEFAULTS.agentic_instance_id, role=agentic_role, ), @@ -477,7 +478,7 @@ def test_get_agentic_user_not_agentic(self, non_agentic_role): activity = Activity( type="message", recipient=ChannelAccount( - id=DEFAULTS.agentic_user_id, + agentic_user_id=DEFAULTS.agentic_user_id, agentic_app_id=DEFAULTS.agentic_instance_id, role=non_agentic_role, ), diff --git a/tests/hosting_core/app/_oauth/_handlers/test_agentic_user_authorization.py b/tests/hosting_core/app/_oauth/_handlers/test_agentic_user_authorization.py index 78f2c512..579623b0 100644 --- a/tests/hosting_core/app/_oauth/_handlers/test_agentic_user_authorization.py +++ b/tests/hosting_core/app/_oauth/_handlers/test_agentic_user_authorization.py @@ -85,7 +85,7 @@ async def test_get_agentic_instance_token_not_agentic( activity = Activity( type="message", recipient=ChannelAccount( - id=DEFAULTS.agentic_user_id, + agentic_user_id=DEFAULTS.agentic_user_id, agentic_app_id=DEFAULTS.agentic_instance_id, role=non_agentic_role, ), @@ -100,7 +100,7 @@ async def test_get_agentic_user_token_not_agentic( activity = Activity( type="message", recipient=ChannelAccount( - id=DEFAULTS.agentic_user_id, + agentic_user_id=DEFAULTS.agentic_user_id, agentic_app_id=DEFAULTS.agentic_instance_id, role=non_agentic_role, ), @@ -145,7 +145,7 @@ async def test_get_agentic_instance_token_is_agentic( activity = Activity( type="message", recipient=ChannelAccount( - id="some_id", + agentic_user_id="some_id", agentic_app_id=DEFAULTS.agentic_instance_id, role=agentic_role, ), @@ -177,7 +177,7 @@ async def test_get_agentic_user_token_is_agentic( activity = Activity( type="message", recipient=ChannelAccount( - id="some_id", + agentic_user_id="some_id", agentic_app_id=DEFAULTS.agentic_instance_id, role=agentic_role, ), @@ -221,7 +221,7 @@ async def test_sign_in_success( activity = Activity( type="message", recipient=ChannelAccount( - id="some_id", + agentic_user_id="some_id", agentic_app_id=DEFAULTS.agentic_instance_id, role=agentic_role, ), @@ -266,7 +266,7 @@ async def test_sign_in_failure( activity = Activity( type="message", recipient=ChannelAccount( - id="some_id", + agentic_user_id="some_id", agentic_app_id=DEFAULTS.agentic_instance_id, role=agentic_role, ), @@ -311,7 +311,7 @@ async def test_get_refreshed_token_success( activity = Activity( type="message", recipient=ChannelAccount( - id="some_id", + agentic_user_id="some_id", agentic_app_id=DEFAULTS.agentic_instance_id, role=agentic_role, ), @@ -357,7 +357,7 @@ async def test_get_refreshed_token_failure( activity = Activity( type="message", recipient=ChannelAccount( - id="some_id", + agentic_user_id="some_id", agentic_app_id=DEFAULTS.agentic_instance_id, role=agentic_role, ), From 89a12e8d737dac3c7820a24130209e8bf0fc368b Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Wed, 15 Oct 2025 15:26:20 -0700 Subject: [PATCH 3/7] commit --- .../authentication/msal/msal_auth.py | 2 +- .../core/connector/client/connector_client.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py b/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py index ac10e3fc..32827297 100644 --- a/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py +++ b/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py @@ -366,7 +366,7 @@ async def get_agentic_user_token( auth_result_payload = instance_app.acquire_token_for_client( scopes, data={ - "username": agentic_user_id, + "user_id": agentic_user_id, "user_federated_identity_credential": instance_token, "grant_type": "user_fic", }, diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py index a93eb1a8..d623bf6a 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py @@ -124,7 +124,7 @@ class ConversationsOperations(ConversationsBase): def __init__(self, client: ClientSession, **kwargs): self.client = client - self._max_conversation_id_length = kwargs.get("max_conversation_id_length", 200) + self._max_conversation_id_length = kwargs.get("max_conversation_id_length", 325) def _normalize_conversation_id(self, conversation_id: str) -> str: return conversation_id[: self._max_conversation_id_length] @@ -196,6 +196,18 @@ async def reply_to_activity( stack_info=True, ) raise ValueError("conversationId and activityId are required") + + from microsoft_agents.activity import Entity + body.entities = [ + Entity(**{ + "htmlBody": "\u003Cbody dir=\u0022ltr\u0022\u003E\n\u003Cdiv class=\u0022elementToProof\u0022 style=\u0022font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);\u0022\u003E\nMessage 3\u003C/div\u003E\n\n\n\u003C/body\u003E", + "type": "emailResponse" + }), + Entity(**{ + "id": "email", + "type": "ProductInfo" + }) + ] conversation_id = self._normalize_conversation_id(conversation_id) url = f"v3/conversations/{conversation_id}/activities/{activity_id}" @@ -204,6 +216,11 @@ async def reply_to_activity( f"Replying to activity: {activity_id} in conversation: {conversation_id}. Activity type is {body.type}" ) + body.conversation.id = conversation_id + + # if body.type == "message": + # breakpoint() + async with self.client.post( url, json=body.model_dump( From a5073944bc656db964f0f2d0ea8b4159c74c89a3 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Wed, 15 Oct 2025 15:41:18 -0700 Subject: [PATCH 4/7] Commit --- .../hosting/core/connector/client/connector_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py index d623bf6a..69ee48f6 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py @@ -124,7 +124,7 @@ class ConversationsOperations(ConversationsBase): def __init__(self, client: ClientSession, **kwargs): self.client = client - self._max_conversation_id_length = kwargs.get("max_conversation_id_length", 325) + self._max_conversation_id_length = kwargs.get("max_conversation_id_length", 200) def _normalize_conversation_id(self, conversation_id: str) -> str: return conversation_id[: self._max_conversation_id_length] @@ -218,8 +218,8 @@ async def reply_to_activity( body.conversation.id = conversation_id - # if body.type == "message": - # breakpoint() + if body.type == "message": + breakpoint() async with self.client.post( url, From 13831490ba2ef81dbcc34b736f6b5f63a1307c53 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Thu, 16 Oct 2025 08:20:32 -0700 Subject: [PATCH 5/7] Documenting the unexpected behavior needed to get this thing to work --- .../core/connector/client/connector_client.py | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py index 69ee48f6..744fb049 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py @@ -198,16 +198,19 @@ async def reply_to_activity( raise ValueError("conversationId and activityId are required") from microsoft_agents.activity import Entity - body.entities = [ - Entity(**{ - "htmlBody": "\u003Cbody dir=\u0022ltr\u0022\u003E\n\u003Cdiv class=\u0022elementToProof\u0022 style=\u0022font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);\u0022\u003E\nMessage 3\u003C/div\u003E\n\n\n\u003C/body\u003E", - "type": "emailResponse" - }), - Entity(**{ - "id": "email", - "type": "ProductInfo" - }) - ] + # body.entities = [ + # Entity(**{ + # "htmlBody": "\u003Cbody dir=\u0022ltr\u0022\u003E\n\u003Cdiv class=\u0022elementToProof\u0022 style=\u0022font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);\u0022\u003E\nMessage 3\u003C/div\u003E\n\n\n\u003C/body\u003E", + # "type": "emailResponse" + # }), + # Entity(**{ + # "id": "email", + # "type": "ProductInfo" + # }) + # ] + from microsoft_agents.activity import ChannelId + # assert body.channel_id + # body.channel_id = ChannelId(channel=body.channel_id.channel, sub_channel="email") conversation_id = self._normalize_conversation_id(conversation_id) url = f"v3/conversations/{conversation_id}/activities/{activity_id}" @@ -215,17 +218,22 @@ async def reply_to_activity( logger.info( f"Replying to activity: {activity_id} in conversation: {conversation_id}. Activity type is {body.type}" ) + # body.entities = None + # body.channel_id = "agents" - body.conversation.id = conversation_id - + # body.conversation.id = conversation_id + json = body.model_dump( + by_alias=True, exclude_unset=True, exclude_none=True, mode="json" + ) + json["channelId"] = "agents" if body.type == "message": - breakpoint() + print() + print(self.client.headers) + # breakpoint() async with self.client.post( url, - json=body.model_dump( - by_alias=True, exclude_unset=True, exclude_none=True, mode="json" - ), + json=json, ) as response: result = await response.json() if response.content_length else {} From ee5e03156ca8bf310aebe3bb789672bff28088e3 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Fri, 17 Oct 2025 08:12:53 -0700 Subject: [PATCH 6/7] Fixing subchannel serialization --- .../microsoft_agents/activity/activity.py | 9 +++++- .../core/connector/client/connector_client.py | 31 ++----------------- tests/activity/pydantic/test_activity_io.py | 17 +++++----- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py b/libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py index 8ed6af55..c038d0f5 100644 --- a/libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py +++ b/libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py @@ -253,7 +253,7 @@ def _serialize_sub_channel_data( product_info = entity break - # maintain consistency between ProductInfo entity and sub channel + # self.channel_id is the source of truth for serialization if self.channel_id and self.channel_id.sub_channel: if product_info and product_info.get("id") != self.channel_id.sub_channel: raise Exception( @@ -268,6 +268,13 @@ def _serialize_sub_channel_data( "id": self.channel_id.sub_channel, } ) + + # simply serialized channelId value in Activity and relatesTo + if "channelId" in serialized: + serialized["channelId"] = self.channel_id.channel + elif "channel_id" in serialized: + serialized["channel_id"] = self.channel_id.channel + elif product_info: # remove productInfo entity if sub_channel is not set del serialized["entities"][i] if not serialized["entities"]: # after removal above, list may be empty diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py index 744fb049..a93eb1a8 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py @@ -196,21 +196,6 @@ async def reply_to_activity( stack_info=True, ) raise ValueError("conversationId and activityId are required") - - from microsoft_agents.activity import Entity - # body.entities = [ - # Entity(**{ - # "htmlBody": "\u003Cbody dir=\u0022ltr\u0022\u003E\n\u003Cdiv class=\u0022elementToProof\u0022 style=\u0022font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);\u0022\u003E\nMessage 3\u003C/div\u003E\n\n\n\u003C/body\u003E", - # "type": "emailResponse" - # }), - # Entity(**{ - # "id": "email", - # "type": "ProductInfo" - # }) - # ] - from microsoft_agents.activity import ChannelId - # assert body.channel_id - # body.channel_id = ChannelId(channel=body.channel_id.channel, sub_channel="email") conversation_id = self._normalize_conversation_id(conversation_id) url = f"v3/conversations/{conversation_id}/activities/{activity_id}" @@ -218,22 +203,12 @@ async def reply_to_activity( logger.info( f"Replying to activity: {activity_id} in conversation: {conversation_id}. Activity type is {body.type}" ) - # body.entities = None - # body.channel_id = "agents" - - # body.conversation.id = conversation_id - json = body.model_dump( - by_alias=True, exclude_unset=True, exclude_none=True, mode="json" - ) - json["channelId"] = "agents" - if body.type == "message": - print() - print(self.client.headers) - # breakpoint() async with self.client.post( url, - json=json, + json=body.model_dump( + by_alias=True, exclude_unset=True, exclude_none=True, mode="json" + ), ) as response: result = await response.json() if response.content_length else {} diff --git a/tests/activity/pydantic/test_activity_io.py b/tests/activity/pydantic/test_activity_io.py index d60b11c3..2ca8734b 100644 --- a/tests/activity/pydantic/test_activity_io.py +++ b/tests/activity/pydantic/test_activity_io.py @@ -132,7 +132,10 @@ def test_channel_id_unset_becomes_set_at_init(self): activity = Activity(type="message") activity.channel_id = "channel:sub_channel" data = activity.model_dump(mode="json", exclude_unset=True, by_alias=True) - assert data["channelId"] == "channel:sub_channel" + assert data["channelId"] == "channel" + assert data["entities"] == [ + {"type": EntityTypes.PRODUCT_INFO.value, "id": "sub_channel"} + ] def test_channel_id_unset_at_init_not_included(self): activity = Activity(type="message") @@ -156,14 +159,14 @@ def test_product_info_avoids_error_no_parent_channel(self): Activity(type="message", channel_id="msteams:subchannel"), { "type": "message", - "channelId": "msteams:subchannel", + "channelId": "msteams", "entities": [ {"type": EntityTypes.PRODUCT_INFO.value, "id": "subchannel"} ], }, { "type": "message", - "channel_id": "msteams:subchannel", + "channel_id": "msteams", "entities": [ {"type": EntityTypes.PRODUCT_INFO.value, "id": "subchannel"} ], @@ -177,7 +180,7 @@ def test_product_info_avoids_error_no_parent_channel(self): ), { "type": "message", - "channelId": "msteams:subchannel", + "channelId": "msteams", "entities": [ {"type": "other"}, {"type": EntityTypes.PRODUCT_INFO.value, "id": "subchannel"}, @@ -185,7 +188,7 @@ def test_product_info_avoids_error_no_parent_channel(self): }, { "type": "message", - "channel_id": "msteams:subchannel", + "channel_id": "msteams", "entities": [ {"type": "other"}, {"type": EntityTypes.PRODUCT_INFO.value, "id": "subchannel"}, @@ -200,7 +203,7 @@ def test_product_info_avoids_error_no_parent_channel(self): ), { "type": "message", - "channelId": "msteams:misc", + "channelId": "msteams", "entities": [ {"type": "other"}, {"type": EntityTypes.PRODUCT_INFO.value, "id": "misc"}, @@ -208,7 +211,7 @@ def test_product_info_avoids_error_no_parent_channel(self): }, { "type": "message", - "channel_id": "msteams:misc", + "channel_id": "msteams", "entities": [ {"type": "other"}, {"type": EntityTypes.PRODUCT_INFO.value, "id": "misc"}, From 749e2d5b235a95e3c87a6072916a7893864b1050 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Fri, 17 Oct 2025 08:25:44 -0700 Subject: [PATCH 7/7] Addressing lingering PR comment --- .../microsoft_agents/authentication/msal/msal_auth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py b/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py index 32827297..aed16156 100644 --- a/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py +++ b/libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py @@ -313,7 +313,7 @@ async def get_agentic_instance_token( async def get_agentic_user_token( self, agent_app_instance_id: str, agentic_user_id: str, scopes: list[str] ) -> Optional[str]: - """Gets the agentic user token for the given agent application instance ID and user principal name and the scopes. + """Gets the agentic user token for the given agent application instance ID and agentic user Id and the scopes. :param agent_app_instance_id: The agent application instance ID. :type agent_app_instance_id: str @@ -326,7 +326,7 @@ async def get_agentic_user_token( """ if not agent_app_instance_id or not agentic_user_id: raise ValueError( - "Agent application instance Id and user principal name must be provided." + "Agent application instance Id and agentic user Id must be provided." ) logger.info(