Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/apps/src/microsoft_teams/apps/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,21 @@ def get_agentic_identity(
tenant_id: Optional[str] = None,
agentic_app_blueprint_id: Optional[str] = None,
) -> AgenticIdentity:
"""Get an Agent ID identity for API calls."""
"""Get an Agent ID identity for API calls.

When ``agentic_app_blueprint_id`` is omitted, it defaults to the app's own
client/app id (``self.id``).
"""
resolved_tenant_id = tenant_id or (self.credentials.tenant_id if self.credentials else None)
if resolved_tenant_id is None:
raise ValueError("tenant_id is required to get an agentic identity")

resolved_blueprint_id = agentic_app_blueprint_id or self.id
return AgenticIdentity(
agentic_app_id=agentic_app_id,
agentic_user_id=agentic_user_id,
tenant_id=resolved_tenant_id,
agentic_app_blueprint_id=agentic_app_blueprint_id,
agentic_app_blueprint_id=resolved_blueprint_id,
)

@overload
Expand Down
28 changes: 28 additions & 0 deletions packages/apps/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,34 @@ async def test_send_passes_agentic_identity_and_service_url(self, mock_storage)
}
assert result.id == "sent-activity-id"

def test_get_agentic_identity_preserves_explicit_blueprint_id(self, mock_storage) -> None:
"""An explicitly provided agentic_app_blueprint_id should be preserved."""
options = AppOptions(storage=mock_storage, client_id="test-client-id", client_secret="test-secret")
app = App(**options)

identity = app.get_agentic_identity(
"agentic-app-id",
"agentic-user-id",
tenant_id="tenant-id",
agentic_app_blueprint_id="explicit-blueprint-id",
)

assert identity.agentic_app_blueprint_id == "explicit-blueprint-id"

def test_get_agentic_identity_defaults_blueprint_id_to_client_id(self, mock_storage) -> None:
"""When agentic_app_blueprint_id is omitted, it should default to the app's client id."""
options = AppOptions(storage=mock_storage, client_id="test-client-id", client_secret="test-secret")
app = App(**options)

identity = app.get_agentic_identity(
"agentic-app-id",
"agentic-user-id",
tenant_id="tenant-id",
)

assert identity.agentic_app_blueprint_id == app.id
assert identity.agentic_app_blueprint_id == "test-client-id"


class TestAppInitialize:
"""Test cases for App.initialize() method."""
Expand Down
Loading