microsoft-agents-a365-runtime 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ # Copyright (c) Microsoft. All rights reserved.
2
+
3
+ from .environment_utils import get_observability_authentication_scope
4
+ from .power_platform_api_discovery import ClusterCategory, PowerPlatformApiDiscovery
5
+ from .utility import Utility
6
+
7
+ __all__ = [
8
+ "get_observability_authentication_scope",
9
+ "PowerPlatformApiDiscovery",
10
+ "ClusterCategory",
11
+ "Utility",
12
+ ]
13
+
14
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__)
@@ -0,0 +1,56 @@
1
+ # Copyright (c) Microsoft. All rights reserved.
2
+
3
+ """
4
+ Utility logic for environment-related operations.
5
+ """
6
+
7
+ import os
8
+
9
+ # Authentication scopes for different environments
10
+ PROD_OBSERVABILITY_SCOPE = "https://api.powerplatform.com/.default"
11
+
12
+ # Cluster categories for different environments
13
+ PROD_OBSERVABILITY_CLUSTER_CATEGORY = "prod"
14
+
15
+ # Default environment names
16
+ PRODUCTION_ENVIRONMENT_NAME = "production"
17
+ DEVELOPMENT_ENVIRONMENT_NAME = "Development"
18
+
19
+
20
+ def get_observability_authentication_scope() -> list[str]:
21
+ """
22
+ Returns the scope for authenticating to the observability service based on the current environment.
23
+
24
+ Returns:
25
+ list[str]: The authentication scope for the current environment.
26
+ """
27
+ return [PROD_OBSERVABILITY_SCOPE]
28
+
29
+
30
+ def is_development_environment() -> bool:
31
+ """
32
+ Returns True if the current environment is a development environment.
33
+
34
+ Returns:
35
+ bool: True if the current environment is development, False otherwise.
36
+ """
37
+ environment = _get_current_environment()
38
+ return environment.lower() == DEVELOPMENT_ENVIRONMENT_NAME.lower()
39
+
40
+
41
+ def _get_current_environment() -> str:
42
+ """
43
+ Gets the current environment name.
44
+
45
+ Returns:
46
+ str: The current environment name.
47
+ """
48
+ # Check environment variables in order of precedence
49
+
50
+ # Check Python-specific environment variables
51
+ environment = os.getenv("PYTHON_ENVIRONMENT")
52
+ if environment:
53
+ return environment
54
+
55
+ # Default to Production
56
+ return PRODUCTION_ENVIRONMENT_NAME
@@ -0,0 +1,89 @@
1
+ # Copyright (c) Microsoft. All rights reserved.
2
+
3
+ import re
4
+ from typing import Literal
5
+
6
+ ClusterCategory = Literal[
7
+ "local",
8
+ "dev",
9
+ "test",
10
+ "preprod",
11
+ "firstrelease",
12
+ "prod",
13
+ "gov",
14
+ "high",
15
+ "dod",
16
+ "mooncake",
17
+ "ex",
18
+ "rx",
19
+ ]
20
+
21
+
22
+ class PowerPlatformApiDiscovery:
23
+ """Discovery helper for Power Platform API endpoints."""
24
+
25
+ def __init__(self, cluster_category: ClusterCategory) -> None:
26
+ self.cluster_category = cluster_category
27
+
28
+ def get_token_audience(self) -> str:
29
+ return f"https://{self._get_environment_api_host_name_suffix()}"
30
+
31
+ def get_token_endpoint_host(self) -> str:
32
+ return self._get_environment_api_host_name_suffix()
33
+
34
+ def get_tenant_endpoint(self, tenant_id: str) -> str:
35
+ return self._generate_power_platform_api_domain(tenant_id)
36
+
37
+ def get_tenant_island_cluster_endpoint(self, tenant_id: str) -> str:
38
+ return self._generate_power_platform_api_domain(tenant_id, "il-")
39
+
40
+ def _generate_power_platform_api_domain(
41
+ self, host_name_identifier: str, host_name_prefix: str = ""
42
+ ) -> str:
43
+ # Validate allowed characters: alphanumeric and dash
44
+ if not re.match(r"^[a-zA-Z0-9-]+$", host_name_identifier):
45
+ raise ValueError(
46
+ f"Cannot generate Power Platform API endpoint because the tenant identifier contains invalid host name characters, only alphanumeric and dash characters are expected: {host_name_identifier}"
47
+ )
48
+
49
+ host_name_infix = "tenant"
50
+ hex_name_suffix_length = self._get_hex_api_suffix_length()
51
+ hex_name = host_name_identifier.lower().replace("-", "")
52
+
53
+ if hex_name_suffix_length >= len(hex_name):
54
+ raise ValueError(
55
+ f"Cannot generate Power Platform API endpoint because the normalized tenant identifier must be at least {hex_name_suffix_length + 1} "
56
+ f"characters in length: {hex_name}"
57
+ )
58
+
59
+ hex_name_suffix = hex_name[-hex_name_suffix_length:]
60
+ hex_name_prefix = hex_name[: len(hex_name) - hex_name_suffix_length]
61
+ host_name_suffix = self._get_environment_api_host_name_suffix()
62
+
63
+ return f"{host_name_prefix}{hex_name_prefix}.{hex_name_suffix}.{host_name_infix}.{host_name_suffix}"
64
+
65
+ def _get_hex_api_suffix_length(self) -> int:
66
+ if self.cluster_category in ("firstrelease", "prod"):
67
+ return 2
68
+ return 1
69
+
70
+ def _get_environment_api_host_name_suffix(self) -> str:
71
+ cluster_to_suffix = {
72
+ "local": "api.powerplatform.localhost",
73
+ "dev": "api.powerplatform.com", # defaulting to prod
74
+ "test": "api.powerplatform.com", # defaulting to prod
75
+ "preprod": "api.powerplatform.com", # defaulting to prod
76
+ "firstrelease": "api.powerplatform.com",
77
+ "prod": "api.powerplatform.com",
78
+ "gov": "api.gov.powerplatform.microsoft.us",
79
+ "high": "api.high.powerplatform.microsoft.us",
80
+ "dod": "api.appsplatform.us",
81
+ "mooncake": "api.powerplatform.partner.microsoftonline.cn",
82
+ "ex": "api.powerplatform.eaglex.ic.gov",
83
+ "rx": "api.powerplatform.microsoft.scloud",
84
+ }
85
+ cc = self.cluster_category
86
+ try:
87
+ return cluster_to_suffix[cc]
88
+ except KeyError as exc:
89
+ raise ValueError(f"Invalid ClusterCategory value: {self.cluster_category}") from exc
@@ -0,0 +1,82 @@
1
+ # Copyright (c) Microsoft. All rights reserved.
2
+
3
+ """
4
+ Utility functions for Microsoft Agent 365 runtime operations.
5
+
6
+ This module provides utility functions for token handling, agent identity resolution,
7
+ and other common runtime operations.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import uuid
13
+ from typing import Any, Optional
14
+
15
+ import jwt
16
+
17
+
18
+ class Utility:
19
+ """
20
+ Utility class providing common runtime operations for Agent 365.
21
+
22
+ This class contains static methods for token processing, agent identity resolution,
23
+ and other utility functions used across the Agent 365 runtime.
24
+ """
25
+
26
+ @staticmethod
27
+ def get_app_id_from_token(token: Optional[str]) -> str:
28
+ """
29
+ Decodes the current token and retrieves the App ID (appid or azp claim).
30
+
31
+ Args:
32
+ token: JWT token to decode. Can be None or empty.
33
+
34
+ Returns:
35
+ str: The App ID from the token's claims, or empty GUID if token is invalid.
36
+ Returns "00000000-0000-0000-0000-000000000000" if no valid App ID is found.
37
+ """
38
+ if not token or not token.strip():
39
+ return str(uuid.UUID(int=0))
40
+
41
+ try:
42
+ # Decode the JWT token without verification (we only need the claims)
43
+ # Note: verify=False is used because we only need to extract claims,
44
+ # not verify the token's authenticity
45
+ decoded_payload = jwt.decode(token, options={"verify_signature": False})
46
+
47
+ # Look for appid or azp claims (appid takes precedence)
48
+ app_id = decoded_payload.get("appid") or decoded_payload.get("azp")
49
+ return app_id if app_id else ""
50
+
51
+ except (jwt.DecodeError, jwt.InvalidTokenError):
52
+ # Token is malformed or invalid
53
+ return ""
54
+
55
+ @staticmethod
56
+ def resolve_agent_identity(context: Any, auth_token: Optional[str]) -> str:
57
+ """
58
+ Resolves the agent identity from the turn context or auth token.
59
+
60
+ Args:
61
+ context: Turn context of the conversation turn. Expected to have an Activity
62
+ with methods like is_agentic_request() and get_agentic_instance_id().
63
+ auth_token: Authentication token if available.
64
+
65
+ Returns:
66
+ str: The agent identity (App ID). Returns the agentic instance ID if the
67
+ request is agentic, otherwise returns the App ID from the auth token.
68
+ """
69
+ try:
70
+ # App ID is required to pass to MCP server URL
71
+ # Try to get agentic instance ID if this is an agentic request
72
+ if context and context.activity and context.activity.is_agentic_request():
73
+ agentic_id = context.activity.get_agentic_instance_id()
74
+ return agentic_id if agentic_id else ""
75
+
76
+ except (AttributeError, TypeError, Exception):
77
+ # Context/activity doesn't have the expected methods or properties
78
+ # or any other error occurred while accessing context/activity
79
+ pass
80
+
81
+ # Fallback to extracting App ID from the auth token
82
+ return Utility.get_app_id_from_token(auth_token)
@@ -0,0 +1,34 @@
1
+ # Copyright (c) Microsoft Corporation.
2
+ # Licensed under the MIT License.
3
+
4
+ """
5
+ Version utilities for Microsoft Agent 365 SDK packages.
6
+
7
+ This module is deprecated. Versioning is now handled automatically by
8
+ setuptools-git-versioning. See versioning/TARGET-VERSION and
9
+ HOW_TO_SET_A_VERSION.md for details.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import os
15
+
16
+
17
+ def build_version():
18
+ """
19
+ DEPRECATED: This function is no longer used.
20
+
21
+ Version is now automatically calculated by setuptools-git-versioning
22
+ based on Git history and tags. See HOW_TO_SET_A_VERSION.md for details.
23
+
24
+ Returns:
25
+ str: Version from AGENT365_PYTHON_SDK_PACKAGE_VERSION environment variable or "0.0.0"
26
+ """
27
+ import warnings
28
+
29
+ warnings.warn(
30
+ "build_version() is deprecated. Version is now managed by setuptools-git-versioning.",
31
+ DeprecationWarning,
32
+ stacklevel=2,
33
+ )
34
+ return os.environ.get("AGENT365_PYTHON_SDK_PACKAGE_VERSION", "0.0.0")
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: microsoft-agents-a365-runtime
3
+ Version: 0.1.0
4
+ Summary: Telemetry, tracing, and monitoring components for AI agents
5
+ Author-email: Microsoft <support@microsoft.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/microsoft/Agent365-python
8
+ Project-URL: Repository, https://github.com/microsoft/Agent365-python
9
+ Project-URL: Issues, https://github.com/microsoft/Agent365-python/issues
10
+ Project-URL: Documentation, https://github.com/microsoft/Agent365-python/tree/main/libraries/microsoft-agents-a365-runtime
11
+ Keywords: observability,telemetry,tracing,opentelemetry,monitoring,ai,agents
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: System :: Monitoring
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ Requires-Dist: PyJWT>=2.8.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
26
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
27
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
28
+ Requires-Dist: black>=23.0.0; extra == "dev"
29
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
30
+ Provides-Extra: test
31
+ Requires-Dist: pytest>=7.0.0; extra == "test"
32
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
33
+
34
+ # microsoft-agents-a365-runtime
35
+
36
+ [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-a365-runtime?label=PyPI&logo=pypi)](https://pypi.org/project/microsoft-agents-a365-runtime)
37
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/microsoft-agents-a365-runtime?label=Downloads&logo=pypi)](https://pypi.org/project/microsoft-agents-a365-runtime)
38
+
39
+ Core runtime utilities and environment management for AI agent applications. This package provides essential Power Platform API discovery, environment configuration, and authentication scope resolution.
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ pip install microsoft-agents-a365-runtime
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ For usage examples and detailed documentation, see the [Microsoft Agent 365 Developer documentation](https://learn.microsoft.com/microsoft-agent-365/developer/?tabs=python) on Microsoft Learn.
50
+
51
+ ## Support
52
+
53
+ For issues, questions, or feedback:
54
+
55
+ - File issues in the [GitHub Issues](https://github.com/microsoft/Agent365-python/issues) section
56
+ - See the [main documentation](../../../README.md) for more information
57
+
58
+ ## Trademarks
59
+
60
+ *Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.*
61
+
62
+ ## License
63
+
64
+ Copyright (c) Microsoft Corporation. All rights reserved.
65
+
66
+ Licensed under the MIT License - see the [LICENSE](../../../LICENSE.md) file for details.
@@ -0,0 +1,9 @@
1
+ microsoft_agents_a365/runtime/__init__.py,sha256=g5641veSgmz8JErlGhlc-noOXcKYZpsq_yBWMg4bcyM,431
2
+ microsoft_agents_a365/runtime/environment_utils.py,sha256=T5b1DAUV1VxwcKxbjeqxfDkuhFCBZ-8kez-_yGbmv58,1524
3
+ microsoft_agents_a365/runtime/power_platform_api_discovery.py,sha256=CS-Vhd6jsMq7lSwtdZIDh-Oybzn_osOTtvml_uYZ8eQ,3435
4
+ microsoft_agents_a365/runtime/utility.py,sha256=FXrdaDHL1JypZkh8JKL0zh355xAllR5xd9bUDGgDCTI,3114
5
+ microsoft_agents_a365/runtime/version_utils.py,sha256=nkgYIaPXD9OyT_lJ8K3sqpEze_VMJzekMmjsiYNghB8,965
6
+ microsoft_agents_a365_runtime-0.1.0.dist-info/METADATA,sha256=9aej8fSLN9GuLH0jYsnLJnrWN4J4MYIfoQS6LlXFSU0,3206
7
+ microsoft_agents_a365_runtime-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ microsoft_agents_a365_runtime-0.1.0.dist-info/top_level.txt,sha256=G3c2_4sy5_EM_BWO67SbK2tKj4G8XFn-QXRbh8g9Lgk,22
9
+ microsoft_agents_a365_runtime-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ microsoft_agents_a365