Skip to content

Commit deb01ed

Browse files
CopilotnikhilNava
andcommitted
Use MiddlewareSet type for adapter and Activity helper methods instead of direct attribute access
- Change adapter param type from ChannelAdapter to MiddlewareSet (the actual middleware registration object) - Use activity.get_agentic_instance_id() instead of recipient.agentic_app_id - Use activity.get_agentic_user() instead of recipient.agentic_user_id - Update test to use agentic role for proper helper method behavior Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
1 parent 64ce06e commit deb01ed

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

libraries/microsoft-agents-a365-observability-hosting/microsoft_agents_a365/observability/hosting/middleware/observability_hosting_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import logging
99
from dataclasses import dataclass
1010

11-
from microsoft_agents.hosting.core import ChannelAdapter
11+
from microsoft_agents.hosting.core.middleware_set import MiddlewareSet
1212

1313
from .baggage_middleware import BaggageMiddleware
1414
from .output_logging_middleware import OutputLoggingMiddleware
@@ -46,15 +46,15 @@ def __init__(self) -> None:
4646
@classmethod
4747
def configure(
4848
cls,
49-
adapter: ChannelAdapter,
49+
adapter: MiddlewareSet,
5050
options: ObservabilityHostingOptions,
5151
) -> ObservabilityHostingManager:
5252
"""Configure the singleton instance and register middleware on the adapter.
5353
5454
Subsequent calls after the first are no-ops and return the existing instance.
5555
5656
Args:
57-
adapter: The channel adapter to register middleware on.
57+
adapter: The middleware set to register middleware on.
5858
options: Configuration options controlling which middleware to enable.
5959
6060
Returns:

libraries/microsoft-agents-a365-observability-hosting/microsoft_agents_a365/observability/hosting/middleware/output_logging_middleware.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@
4343

4444
def _derive_agent_details(context: TurnContext) -> AgentDetails | None:
4545
"""Derive target agent details from the activity recipient."""
46-
recipient = getattr(context.activity, "recipient", None)
46+
activity = context.activity
47+
recipient = getattr(activity, "recipient", None)
4748
if not recipient:
4849
return None
4950
return AgentDetails(
50-
agent_id=getattr(recipient, "agentic_app_id", None) or "",
51+
agent_id=activity.get_agentic_instance_id() or "",
5152
agent_name=getattr(recipient, "name", None),
5253
agent_auid=getattr(recipient, "aad_object_id", None),
53-
agent_upn=getattr(recipient, "agentic_user_id", None),
54+
agent_upn=activity.get_agentic_user(),
5455
agent_description=getattr(recipient, "role", None),
5556
tenant_id=getattr(recipient, "tenant_id", None),
5657
)

libraries/microsoft-agents-a365-observability-hosting/microsoft_agents_a365/observability/hosting/scope_helpers/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ def get_target_agent_pairs(activity: Activity) -> Iterator[tuple[str, Any]]:
6262
rec = activity.recipient
6363
if not rec:
6464
return
65-
yield GEN_AI_AGENT_ID_KEY, rec.agentic_app_id
65+
yield GEN_AI_AGENT_ID_KEY, activity.get_agentic_instance_id()
6666
yield GEN_AI_AGENT_NAME_KEY, rec.name
6767
yield GEN_AI_AGENT_AUID_KEY, rec.aad_object_id
68-
yield GEN_AI_AGENT_UPN_KEY, rec.agentic_user_id
68+
yield GEN_AI_AGENT_UPN_KEY, activity.get_agentic_user()
6969
yield (
7070
GEN_AI_AGENT_DESCRIPTION_KEY,
7171
rec.role,

tests/observability/hosting/scope_helpers/test_scope_helper_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_get_target_agent_pairs():
6666
name="Test Agent",
6767
aad_object_id="agent-auid",
6868
agentic_user_id="agent-upn",
69-
role="Assistant",
69+
role="agenticAppInstance",
7070
)
7171
activity = Activity(type="message", recipient=recipient)
7272

@@ -76,7 +76,7 @@ def test_get_target_agent_pairs():
7676
assert (GEN_AI_AGENT_NAME_KEY, "Test Agent") in result
7777
assert (GEN_AI_AGENT_AUID_KEY, "agent-auid") in result
7878
assert (GEN_AI_AGENT_UPN_KEY, "agent-upn") in result
79-
assert (GEN_AI_AGENT_DESCRIPTION_KEY, "Assistant") in result
79+
assert (GEN_AI_AGENT_DESCRIPTION_KEY, "agenticAppInstance") in result
8080

8181

8282
def test_get_tenant_id_pair():

0 commit comments

Comments
 (0)