agentarts-sdk 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.
Files changed (237) hide show
  1. agentarts/__init__.py +22 -0
  2. agentarts/sdk/__init__.py +60 -0
  3. agentarts/sdk/identity/__init__.py +22 -0
  4. agentarts/sdk/identity/auth.py +304 -0
  5. agentarts/sdk/identity/config.py +36 -0
  6. agentarts/sdk/identity/types.py +60 -0
  7. agentarts/sdk/integration/__init__.py +65 -0
  8. agentarts/sdk/integration/langgraph/__init__.py +23 -0
  9. agentarts/sdk/integration/langgraph/config.py +100 -0
  10. agentarts/sdk/integration/langgraph/converter.py +261 -0
  11. agentarts/sdk/integration/langgraph/saver.py +542 -0
  12. agentarts/sdk/mcpgateway/__init__.py +9 -0
  13. agentarts/sdk/mcpgateway/mcp_gateway_client.py +386 -0
  14. agentarts/sdk/memory/__init__.py +97 -0
  15. agentarts/sdk/memory/client.py +989 -0
  16. agentarts/sdk/memory/inner/__init__.py +11 -0
  17. agentarts/sdk/memory/inner/config.py +978 -0
  18. agentarts/sdk/memory/inner/controlplane.py +185 -0
  19. agentarts/sdk/memory/inner/dataplane.py +286 -0
  20. agentarts/sdk/memory/session.py +421 -0
  21. agentarts/sdk/py.typed +1 -0
  22. agentarts/sdk/runtime/__init__.py +16 -0
  23. agentarts/sdk/runtime/app.py +626 -0
  24. agentarts/sdk/runtime/context.py +298 -0
  25. agentarts/sdk/runtime/model.py +40 -0
  26. agentarts/sdk/service/__init__.py +26 -0
  27. agentarts/sdk/service/http_client.py +474 -0
  28. agentarts/sdk/service/iam_client.py +97 -0
  29. agentarts/sdk/service/identity/__init__.py +0 -0
  30. agentarts/sdk/service/identity/identity_client.py +630 -0
  31. agentarts/sdk/service/identity/polling/__init__.py +0 -0
  32. agentarts/sdk/service/identity/polling/token_poller.py +114 -0
  33. agentarts/sdk/service/memory_service.py +690 -0
  34. agentarts/sdk/service/runtime_client.py +891 -0
  35. agentarts/sdk/service/swr_client.py +374 -0
  36. agentarts/sdk/service/tools_http.py +151 -0
  37. agentarts/sdk/tools/__init__.py +14 -0
  38. agentarts/sdk/tools/code_interpreter/__init__.py +12 -0
  39. agentarts/sdk/tools/code_interpreter/code_interpreter_client.py +905 -0
  40. agentarts/sdk/utils/__init__.py +7 -0
  41. agentarts/sdk/utils/common.py +24 -0
  42. agentarts/sdk/utils/constant.py +276 -0
  43. agentarts/sdk/utils/metadata.py +113 -0
  44. agentarts/sdk/utils/signer.py +181 -0
  45. agentarts/sdk/utils/signer_v11.py +195 -0
  46. agentarts/toolkit/__init__.py +7 -0
  47. agentarts/toolkit/cli/__init__.py +5 -0
  48. agentarts/toolkit/cli/common.py +23 -0
  49. agentarts/toolkit/cli/mcp_gateway/__init__.py +7 -0
  50. agentarts/toolkit/cli/mcp_gateway/mcp_gateway.py +419 -0
  51. agentarts/toolkit/cli/memory/__init__.py +5 -0
  52. agentarts/toolkit/cli/memory/commands.py +504 -0
  53. agentarts/toolkit/cli/runtime/__init__.py +20 -0
  54. agentarts/toolkit/cli/runtime/config.py +269 -0
  55. agentarts/toolkit/cli/runtime/deploy.py +100 -0
  56. agentarts/toolkit/cli/runtime/destroy.py +53 -0
  57. agentarts/toolkit/cli/runtime/dev.py +56 -0
  58. agentarts/toolkit/cli/runtime/init.py +134 -0
  59. agentarts/toolkit/cli/runtime/invoke.py +165 -0
  60. agentarts/toolkit/main.py +116 -0
  61. agentarts/toolkit/operations/__init__.py +7 -0
  62. agentarts/toolkit/operations/mcp_gateway/__init__.py +5 -0
  63. agentarts/toolkit/operations/memory/__init__.py +20 -0
  64. agentarts/toolkit/operations/memory/models.py +44 -0
  65. agentarts/toolkit/operations/memory/space.py +302 -0
  66. agentarts/toolkit/operations/runtime/__init__.py +63 -0
  67. agentarts/toolkit/operations/runtime/config.py +514 -0
  68. agentarts/toolkit/operations/runtime/deploy.py +358 -0
  69. agentarts/toolkit/operations/runtime/destroy.py +62 -0
  70. agentarts/toolkit/operations/runtime/dev.py +257 -0
  71. agentarts/toolkit/operations/runtime/init.py +291 -0
  72. agentarts/toolkit/operations/runtime/invoke.py +360 -0
  73. agentarts/toolkit/utils/__init__.py +5 -0
  74. agentarts/toolkit/utils/common.py +73 -0
  75. agentarts/toolkit/utils/runtime/__init__.py +53 -0
  76. agentarts/toolkit/utils/runtime/config.py +667 -0
  77. agentarts/toolkit/utils/runtime/container.py +386 -0
  78. agentarts/toolkit/utils/templates/__init__.py +10 -0
  79. agentarts/toolkit/utils/templates/basic/__init__.py +1 -0
  80. agentarts/toolkit/utils/templates/basic/agent.py.j2 +44 -0
  81. agentarts/toolkit/utils/templates/basic/requirements.txt.j2 +1 -0
  82. agentarts/toolkit/utils/templates/docker/Dockerfile.j2 +24 -0
  83. agentarts/toolkit/utils/templates/docker/__init__.py +92 -0
  84. agentarts/toolkit/utils/templates/google-adk/__init__.py +1 -0
  85. agentarts/toolkit/utils/templates/google-adk/agent.py.j2 +160 -0
  86. agentarts/toolkit/utils/templates/google-adk/requirements.txt.j2 +3 -0
  87. agentarts/toolkit/utils/templates/langchain/__init__.py +1 -0
  88. agentarts/toolkit/utils/templates/langchain/agent.py.j2 +139 -0
  89. agentarts/toolkit/utils/templates/langchain/requirements.txt.j2 +4 -0
  90. agentarts/toolkit/utils/templates/langgraph/__init__.py +1 -0
  91. agentarts/toolkit/utils/templates/langgraph/agent.py.j2 +170 -0
  92. agentarts/toolkit/utils/templates/langgraph/requirements.txt.j2 +5 -0
  93. agentarts/toolkit/utils/templates/manager.py +126 -0
  94. agentarts_sdk-0.1.0.dist-info/METADATA +482 -0
  95. agentarts_sdk-0.1.0.dist-info/RECORD +237 -0
  96. agentarts_sdk-0.1.0.dist-info/WHEEL +4 -0
  97. agentarts_sdk-0.1.0.dist-info/entry_points.txt +3 -0
  98. huaweicloudsdkagentidentity/__init__.py +0 -0
  99. huaweicloudsdkagentidentity/v1/__init__.py +324 -0
  100. huaweicloudsdkagentidentity/v1/agentidentity_async_client.py +2090 -0
  101. huaweicloudsdkagentidentity/v1/agentidentity_client.py +2087 -0
  102. huaweicloudsdkagentidentity/v1/model/__init__.py +322 -0
  103. huaweicloudsdkagentidentity/v1/model/agency_urn.py +72 -0
  104. huaweicloudsdkagentidentity/v1/model/allowed_resource_oauth2_return_url.py +72 -0
  105. huaweicloudsdkagentidentity/v1/model/api_key_credential_provider.py +239 -0
  106. huaweicloudsdkagentidentity/v1/model/api_key_credential_provider_summary.py +215 -0
  107. huaweicloudsdkagentidentity/v1/model/api_key_info.py +131 -0
  108. huaweicloudsdkagentidentity/v1/model/authorizer_configuration.py +124 -0
  109. huaweicloudsdkagentidentity/v1/model/authorizer_type.py +78 -0
  110. huaweicloudsdkagentidentity/v1/model/authorizing_claim_match_value.py +126 -0
  111. huaweicloudsdkagentidentity/v1/model/claim_match_value.py +128 -0
  112. huaweicloudsdkagentidentity/v1/model/client_id.py +72 -0
  113. huaweicloudsdkagentidentity/v1/model/client_secret.py +72 -0
  114. huaweicloudsdkagentidentity/v1/model/complete_resource_token_auth_request.py +99 -0
  115. huaweicloudsdkagentidentity/v1/model/complete_resource_token_auth_request_body.py +126 -0
  116. huaweicloudsdkagentidentity/v1/model/complete_resource_token_auth_response.py +76 -0
  117. huaweicloudsdkagentidentity/v1/model/create_api_key_credential_provider_req_body.py +159 -0
  118. huaweicloudsdkagentidentity/v1/model/create_api_key_credential_provider_request.py +99 -0
  119. huaweicloudsdkagentidentity/v1/model/create_api_key_credential_provider_response.py +103 -0
  120. huaweicloudsdkagentidentity/v1/model/create_oauth2_credential_provider_req_body.py +179 -0
  121. huaweicloudsdkagentidentity/v1/model/create_oauth2_credential_provider_request.py +99 -0
  122. huaweicloudsdkagentidentity/v1/model/create_oauth2_credential_provider_response.py +103 -0
  123. huaweicloudsdkagentidentity/v1/model/create_sts_credential_provider_req_body.py +159 -0
  124. huaweicloudsdkagentidentity/v1/model/create_sts_credential_provider_request.py +99 -0
  125. huaweicloudsdkagentidentity/v1/model/create_sts_credential_provider_response.py +103 -0
  126. huaweicloudsdkagentidentity/v1/model/create_workload_access_token_for_jwt_request.py +99 -0
  127. huaweicloudsdkagentidentity/v1/model/create_workload_access_token_for_jwt_request_body.py +130 -0
  128. huaweicloudsdkagentidentity/v1/model/create_workload_access_token_for_jwt_response.py +107 -0
  129. huaweicloudsdkagentidentity/v1/model/create_workload_access_token_for_user_id_request.py +99 -0
  130. huaweicloudsdkagentidentity/v1/model/create_workload_access_token_for_user_id_request_body.py +130 -0
  131. huaweicloudsdkagentidentity/v1/model/create_workload_access_token_for_user_id_response.py +107 -0
  132. huaweicloudsdkagentidentity/v1/model/create_workload_access_token_request.py +99 -0
  133. huaweicloudsdkagentidentity/v1/model/create_workload_access_token_request_body.py +102 -0
  134. huaweicloudsdkagentidentity/v1/model/create_workload_access_token_response.py +107 -0
  135. huaweicloudsdkagentidentity/v1/model/create_workload_identity_req_body.py +205 -0
  136. huaweicloudsdkagentidentity/v1/model/create_workload_identity_request.py +99 -0
  137. huaweicloudsdkagentidentity/v1/model/create_workload_identity_response.py +103 -0
  138. huaweicloudsdkagentidentity/v1/model/created_by.py +130 -0
  139. huaweicloudsdkagentidentity/v1/model/credential_provider_name.py +72 -0
  140. huaweicloudsdkagentidentity/v1/model/credential_provider_vendor.py +78 -0
  141. huaweicloudsdkagentidentity/v1/model/custom_claim_validation.py +154 -0
  142. huaweicloudsdkagentidentity/v1/model/custom_jwt_authorizer_configuration.py +206 -0
  143. huaweicloudsdkagentidentity/v1/model/custom_oauth2_provider_config_input.py +154 -0
  144. huaweicloudsdkagentidentity/v1/model/custom_oauth2_provider_config_output.py +127 -0
  145. huaweicloudsdkagentidentity/v1/model/delete_api_key_credential_provider_request.py +102 -0
  146. huaweicloudsdkagentidentity/v1/model/delete_api_key_credential_provider_response.py +76 -0
  147. huaweicloudsdkagentidentity/v1/model/delete_oauth2_credential_provider_request.py +102 -0
  148. huaweicloudsdkagentidentity/v1/model/delete_oauth2_credential_provider_response.py +76 -0
  149. huaweicloudsdkagentidentity/v1/model/delete_sts_credential_provider_request.py +102 -0
  150. huaweicloudsdkagentidentity/v1/model/delete_sts_credential_provider_response.py +76 -0
  151. huaweicloudsdkagentidentity/v1/model/delete_workload_identity_request.py +102 -0
  152. huaweicloudsdkagentidentity/v1/model/delete_workload_identity_response.py +76 -0
  153. huaweicloudsdkagentidentity/v1/model/discovery_url.py +72 -0
  154. huaweicloudsdkagentidentity/v1/model/get_api_key_credential_provider_request.py +102 -0
  155. huaweicloudsdkagentidentity/v1/model/get_api_key_credential_provider_response.py +103 -0
  156. huaweicloudsdkagentidentity/v1/model/get_oauth2_credential_provider_request.py +102 -0
  157. huaweicloudsdkagentidentity/v1/model/get_oauth2_credential_provider_response.py +103 -0
  158. huaweicloudsdkagentidentity/v1/model/get_resource_api_key_request.py +99 -0
  159. huaweicloudsdkagentidentity/v1/model/get_resource_api_key_request_body.py +131 -0
  160. huaweicloudsdkagentidentity/v1/model/get_resource_api_key_response.py +107 -0
  161. huaweicloudsdkagentidentity/v1/model/get_resource_oauth2_token_request.py +99 -0
  162. huaweicloudsdkagentidentity/v1/model/get_resource_oauth2_token_request_body.py +362 -0
  163. huaweicloudsdkagentidentity/v1/model/get_resource_oauth2_token_response.py +194 -0
  164. huaweicloudsdkagentidentity/v1/model/get_resource_sts_token_request.py +99 -0
  165. huaweicloudsdkagentidentity/v1/model/get_resource_sts_token_request_body.py +304 -0
  166. huaweicloudsdkagentidentity/v1/model/get_resource_sts_token_response.py +157 -0
  167. huaweicloudsdkagentidentity/v1/model/get_resource_sts_token_response_body_assumed_agency.py +130 -0
  168. huaweicloudsdkagentidentity/v1/model/get_resource_sts_token_response_body_credentials.py +186 -0
  169. huaweicloudsdkagentidentity/v1/model/get_sts_credential_provider_request.py +102 -0
  170. huaweicloudsdkagentidentity/v1/model/get_sts_credential_provider_response.py +103 -0
  171. huaweicloudsdkagentidentity/v1/model/get_token_vault_request.py +102 -0
  172. huaweicloudsdkagentidentity/v1/model/get_token_vault_response.py +103 -0
  173. huaweicloudsdkagentidentity/v1/model/get_workload_identity_authorizer_configuration_request.py +102 -0
  174. huaweicloudsdkagentidentity/v1/model/get_workload_identity_authorizer_configuration_response.py +103 -0
  175. huaweicloudsdkagentidentity/v1/model/get_workload_identity_request.py +102 -0
  176. huaweicloudsdkagentidentity/v1/model/get_workload_identity_response.py +103 -0
  177. huaweicloudsdkagentidentity/v1/model/github_oauth2_provider_config_input.py +130 -0
  178. huaweicloudsdkagentidentity/v1/model/github_oauth2_provider_config_output.py +127 -0
  179. huaweicloudsdkagentidentity/v1/model/google_oauth2_provider_config_input.py +130 -0
  180. huaweicloudsdkagentidentity/v1/model/google_oauth2_provider_config_output.py +127 -0
  181. huaweicloudsdkagentidentity/v1/model/key_auth_authorizer_configuration.py +98 -0
  182. huaweicloudsdkagentidentity/v1/model/kms_configuration.py +127 -0
  183. huaweicloudsdkagentidentity/v1/model/kms_key_id.py +72 -0
  184. huaweicloudsdkagentidentity/v1/model/kms_key_type.py +76 -0
  185. huaweicloudsdkagentidentity/v1/model/limit.py +72 -0
  186. huaweicloudsdkagentidentity/v1/model/list_api_key_credential_providers_request.py +132 -0
  187. huaweicloudsdkagentidentity/v1/model/list_api_key_credential_providers_response.py +128 -0
  188. huaweicloudsdkagentidentity/v1/model/list_oauth2_credential_providers_request.py +132 -0
  189. huaweicloudsdkagentidentity/v1/model/list_oauth2_credential_providers_response.py +128 -0
  190. huaweicloudsdkagentidentity/v1/model/list_sts_credential_providers_request.py +132 -0
  191. huaweicloudsdkagentidentity/v1/model/list_sts_credential_providers_response.py +128 -0
  192. huaweicloudsdkagentidentity/v1/model/list_workload_identities_request.py +132 -0
  193. huaweicloudsdkagentidentity/v1/model/list_workload_identities_response.py +128 -0
  194. huaweicloudsdkagentidentity/v1/model/marker.py +72 -0
  195. huaweicloudsdkagentidentity/v1/model/microsoft_oauth2_provider_config_input.py +158 -0
  196. huaweicloudsdkagentidentity/v1/model/microsoft_oauth2_provider_config_output.py +127 -0
  197. huaweicloudsdkagentidentity/v1/model/oauth2_authorization_server_metadata.py +216 -0
  198. huaweicloudsdkagentidentity/v1/model/oauth2_authorize_request.py +102 -0
  199. huaweicloudsdkagentidentity/v1/model/oauth2_authorize_response.py +76 -0
  200. huaweicloudsdkagentidentity/v1/model/oauth2_callback_request.py +217 -0
  201. huaweicloudsdkagentidentity/v1/model/oauth2_callback_response.py +76 -0
  202. huaweicloudsdkagentidentity/v1/model/oauth2_credential_provider.py +316 -0
  203. huaweicloudsdkagentidentity/v1/model/oauth2_credential_provider_summary.py +239 -0
  204. huaweicloudsdkagentidentity/v1/model/oauth2_discovery.py +128 -0
  205. huaweicloudsdkagentidentity/v1/model/oauth2_provider_config_input.py +174 -0
  206. huaweicloudsdkagentidentity/v1/model/oauth2_provider_config_output.py +174 -0
  207. huaweicloudsdkagentidentity/v1/model/page_info.py +131 -0
  208. huaweicloudsdkagentidentity/v1/model/rich_authorization_detail.py +276 -0
  209. huaweicloudsdkagentidentity/v1/model/secret.py +130 -0
  210. huaweicloudsdkagentidentity/v1/model/sts_credential_provider.py +243 -0
  211. huaweicloudsdkagentidentity/v1/model/sts_credential_provider_summary.py +243 -0
  212. huaweicloudsdkagentidentity/v1/model/sts_tag.py +130 -0
  213. huaweicloudsdkagentidentity/v1/model/tag.py +130 -0
  214. huaweicloudsdkagentidentity/v1/model/token_vault.py +183 -0
  215. huaweicloudsdkagentidentity/v1/model/token_vault_id.py +72 -0
  216. huaweicloudsdkagentidentity/v1/model/update_api_key_credential_provider_req_body.py +132 -0
  217. huaweicloudsdkagentidentity/v1/model/update_api_key_credential_provider_request.py +127 -0
  218. huaweicloudsdkagentidentity/v1/model/update_api_key_credential_provider_response.py +103 -0
  219. huaweicloudsdkagentidentity/v1/model/update_oauth2_credential_provider_req_body.py +128 -0
  220. huaweicloudsdkagentidentity/v1/model/update_oauth2_credential_provider_request.py +127 -0
  221. huaweicloudsdkagentidentity/v1/model/update_oauth2_credential_provider_response.py +103 -0
  222. huaweicloudsdkagentidentity/v1/model/update_sts_credential_provider_req_body.py +132 -0
  223. huaweicloudsdkagentidentity/v1/model/update_sts_credential_provider_request.py +127 -0
  224. huaweicloudsdkagentidentity/v1/model/update_sts_credential_provider_response.py +103 -0
  225. huaweicloudsdkagentidentity/v1/model/update_workload_identity_req_body.py +153 -0
  226. huaweicloudsdkagentidentity/v1/model/update_workload_identity_request.py +127 -0
  227. huaweicloudsdkagentidentity/v1/model/update_workload_identity_response.py +103 -0
  228. huaweicloudsdkagentidentity/v1/model/user_identifier.py +132 -0
  229. huaweicloudsdkagentidentity/v1/model/utc_date_time.py +72 -0
  230. huaweicloudsdkagentidentity/v1/model/workload_access_token.py +72 -0
  231. huaweicloudsdkagentidentity/v1/model/workload_identity.py +313 -0
  232. huaweicloudsdkagentidentity/v1/model/workload_identity_authorizer_configuration.py +151 -0
  233. huaweicloudsdkagentidentity/v1/model/workload_identity_name.py +72 -0
  234. huaweicloudsdkagentidentity/v1/model/workload_identity_summary.py +263 -0
  235. huaweicloudsdkagentidentity/v1/model/workload_identity_urn.py +72 -0
  236. huaweicloudsdkagentidentity/v1/region/__init__.py +0 -0
  237. huaweicloudsdkagentidentity/v1/region/agentidentity_region.py +35 -0
agentarts/__init__.py ADDED
@@ -0,0 +1,22 @@
1
+ """
2
+ Huawei Cloud AgentArts SDK
3
+
4
+ Build, deploy and manage AI agents with cloud capabilities.
5
+
6
+ Usage:
7
+ from agentarts.sdk import AgentArtsRuntimeApp, CodeInterpreter, MemoryClient
8
+ """
9
+
10
+ from importlib.metadata import PackageNotFoundError, version
11
+
12
+ try:
13
+ __version__ = version("agentarts-sdk")
14
+ except PackageNotFoundError:
15
+ __version__ = "0.1.0"
16
+
17
+ __author__ = "Huawei Cloud AgentArts Team"
18
+
19
+ __all__ = [
20
+ "__author__",
21
+ "__version__",
22
+ ]
@@ -0,0 +1,60 @@
1
+ """
2
+ Huawei Cloud AgentArts SDK
3
+
4
+ Build, deploy and manage AI agents with cloud capabilities.
5
+
6
+ Quick Start:
7
+ # Runtime
8
+ from agentarts.sdk import AgentArtsRuntimeApp, RequestContext
9
+ app = AgentArtsRuntimeApp()
10
+
11
+ # Tools
12
+ from agentarts.sdk import CodeInterpreter, code_session
13
+
14
+ # Memory
15
+ from agentarts.sdk import MemoryClient
16
+
17
+ # MCP Gateway
18
+ from agentarts.sdk import MCPGatewayClient
19
+
20
+ # Identity
21
+ from agentarts.sdk import require_access_token, require_api_key, IdentityClient
22
+ """
23
+
24
+ import warnings
25
+
26
+ import urllib3
27
+
28
+ warnings.filterwarnings("ignore", message="Unverified HTTPS request")
29
+ warnings.filterwarnings("ignore", category=urllib3.exceptions.InsecureRequestWarning)
30
+
31
+ from agentarts import __author__, __version__
32
+ from agentarts.sdk.identity import (
33
+ IdentityClient,
34
+ require_access_token,
35
+ require_api_key,
36
+ require_sts_token,
37
+ )
38
+ from agentarts.sdk.mcpgateway import MCPGatewayClient
39
+ from agentarts.sdk.memory import MemoryClient
40
+ from agentarts.sdk.runtime.app import AgentArtsRuntimeApp
41
+ from agentarts.sdk.runtime.context import AgentArtsRuntimeContext, RequestContext
42
+ from agentarts.sdk.runtime.model import PingStatus
43
+ from agentarts.sdk.tools import CodeInterpreter, code_session
44
+
45
+ __all__ = [
46
+ "AgentArtsRuntimeApp",
47
+ "AgentArtsRuntimeContext",
48
+ "CodeInterpreter",
49
+ "IdentityClient",
50
+ "MCPGatewayClient",
51
+ "MemoryClient",
52
+ "PingStatus",
53
+ "RequestContext",
54
+ "__author__",
55
+ "__version__",
56
+ "code_session",
57
+ "require_access_token",
58
+ "require_api_key",
59
+ "require_sts_token",
60
+ ]
@@ -0,0 +1,22 @@
1
+ """
2
+ AgentArts Identity Module
3
+
4
+ Provides authentication, authorization, and multi-tenant support.
5
+
6
+ Usage:
7
+ from agentarts.sdk.identity import require_access_token, require_api_key, IdentityClient
8
+ """
9
+
10
+ from agentarts.sdk.identity.auth import (
11
+ require_access_token,
12
+ require_api_key,
13
+ require_sts_token,
14
+ )
15
+ from agentarts.sdk.service.identity.identity_client import IdentityClient
16
+
17
+ __all__ = [
18
+ "IdentityClient",
19
+ "require_access_token",
20
+ "require_api_key",
21
+ "require_sts_token",
22
+ ]
@@ -0,0 +1,304 @@
1
+ import asyncio
2
+ import logging
3
+ import uuid
4
+ from collections.abc import Callable
5
+ from functools import wraps
6
+ from typing import Any, Literal
7
+
8
+ from agentarts.sdk.identity.config import Config
9
+ from agentarts.sdk.runtime.context import (
10
+ AgentArtsRuntimeContext,
11
+ run_async_in_sync_context,
12
+ )
13
+ from agentarts.sdk.service.identity.identity_client import IdentityClient
14
+ from agentarts.sdk.service.identity.polling.token_poller import TokenPoller
15
+ from agentarts.sdk.utils.constant import get_region
16
+ from huaweicloudsdkagentidentity.v1 import (
17
+ GetResourceStsTokenResponseBodyCredentials,
18
+ StsTag,
19
+ WorkloadIdentity,
20
+ )
21
+
22
+ logger = logging.getLogger(__name__)
23
+
24
+
25
+ def require_access_token(
26
+ *,
27
+ provider_name: str,
28
+ into: str = "access_token",
29
+ scopes: list[str] | None = None,
30
+ on_auth_url: Callable[[str], Any] | None = None,
31
+ auth_flow: Literal["M2M", "USER_FEDERATION"],
32
+ callback_url: str | None = None,
33
+ force_authentication: bool = False,
34
+ token_poller: TokenPoller | None = None,
35
+ custom_state: str | None = None,
36
+ custom_parameters: dict[str, str] | None = None,
37
+ ignore_ssl_verification: bool | None = None,
38
+ ) -> Callable:
39
+ """Decorator that fetches an OAuth2 access token before calling the decorated function.
40
+
41
+ Args:
42
+ provider_name: The credential provider name
43
+ into: Parameter name to inject the token into
44
+ scopes: OAuth2 scopes to request
45
+ on_auth_url: Callback for handling authorization URLs
46
+ auth_flow: Authentication flow type ("M2M" or "USER_FEDERATION")
47
+ callback_url: OAuth2 callback URL
48
+ force_authentication: Force re-authentication
49
+ token_poller: Custom token poller implementation
50
+ custom_state: A state that allows applications to verify the validity of callbacks to callback_url
51
+ custom_parameters: A map of custom parameters to include in authorization request to the credential provider
52
+ Note: these parameters are in addition to standard OAuth 2.0 flow parameters
53
+ ignore_ssl_verification: Whether to ignore SSL verification
54
+
55
+ Returns:
56
+ Decorator function
57
+ """
58
+
59
+ def decorator(func: Callable) -> Callable:
60
+ @wraps(func)
61
+ async def async_wrapper(*args: Any, **kwargs_func: Any) -> Any:
62
+ client = IdentityClient(
63
+ region=get_region(), ignore_ssl_verification=ignore_ssl_verification
64
+ )
65
+ token = await _get_resource_oauth2_token(client)
66
+ kwargs_func[into] = token
67
+ return await func(*args, **kwargs_func)
68
+
69
+ @wraps(func)
70
+ def sync_wrapper(*args: Any, **kwargs_func: Any) -> Any:
71
+ client = IdentityClient(
72
+ region=get_region(), ignore_ssl_verification=ignore_ssl_verification
73
+ )
74
+ token = run_async_in_sync_context(_get_resource_oauth2_token(client))
75
+ kwargs_func[into] = token
76
+ return func(*args, **kwargs_func)
77
+
78
+ if asyncio.iscoroutinefunction(func):
79
+ return async_wrapper
80
+ return sync_wrapper
81
+
82
+ async def _get_resource_oauth2_token(client: IdentityClient) -> str:
83
+ """Common token fetching logic."""
84
+ return await client.get_resource_oauth2_token(
85
+ provider_name=provider_name,
86
+ workload_access_token=_get_workload_access_token(client),
87
+ scopes=scopes,
88
+ on_auth_url=on_auth_url,
89
+ auth_flow=auth_flow,
90
+ callback_url=_get_oauth2_callback_url(callback_url),
91
+ force_authentication=force_authentication,
92
+ token_poller=token_poller,
93
+ custom_state=_get_oauth2_custom_state(custom_state),
94
+ custom_parameters=custom_parameters,
95
+ )
96
+
97
+ return decorator
98
+
99
+
100
+ def require_api_key(
101
+ *,
102
+ provider_name: str,
103
+ into: str = "api_key",
104
+ ignore_ssl_verification: bool | None = None,
105
+ ) -> Callable:
106
+ """Decorator that fetches an API key before calling the decorated function.
107
+
108
+ Args:
109
+ provider_name: The credential provider name
110
+ into: Parameter name to inject the API key into
111
+ ignore_ssl_verification: Whether to ignore SSL verification
112
+
113
+ Returns:
114
+ Decorator function
115
+ """
116
+
117
+ def decorator(func: Callable) -> Callable:
118
+ @wraps(func)
119
+ async def async_wrapper(*args: Any, **kwargs: Any) -> Any:
120
+ client = IdentityClient(
121
+ region=get_region(), ignore_ssl_verification=ignore_ssl_verification
122
+ )
123
+ kwargs[into] = _get_api_key(client)
124
+ return await func(*args, **kwargs)
125
+
126
+ @wraps(func)
127
+ def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
128
+ client = IdentityClient(
129
+ region=get_region(), ignore_ssl_verification=ignore_ssl_verification
130
+ )
131
+ kwargs[into] = _get_api_key(client)
132
+ return func(*args, **kwargs)
133
+
134
+ if asyncio.iscoroutinefunction(func):
135
+ return async_wrapper
136
+ return sync_wrapper
137
+
138
+ def _get_api_key(client: IdentityClient):
139
+ return client.get_resource_api_key(
140
+ provider_name=provider_name,
141
+ workload_access_token=_get_workload_access_token(client),
142
+ )
143
+
144
+ return decorator
145
+
146
+
147
+ def require_sts_token(
148
+ *,
149
+ provider_name: str,
150
+ agency_session_name: str,
151
+ duration_seconds: int | None = None,
152
+ policy: str | None = None,
153
+ source_identity: str | None = None,
154
+ tags: list[StsTag] | None = None,
155
+ transitive_tag_keys: list[str] | None = None,
156
+ into: str = "sts_credentials",
157
+ ignore_ssl_verification: bool | None = None,
158
+ ) -> Callable:
159
+ """Decorator that fetches an STS token before calling the decorated function.
160
+
161
+ The decorator injects STS credentials into the decorated function's keyword
162
+ arguments. The injected value is of type :class:`StsCredentials` (aliased from
163
+ ``GetResourceStsTokenResponseBodyCredentials``).
164
+
165
+ **Injected Type:** :class:`~agent_identity_dev_sdk.types.StsCredentials`
166
+
167
+ **Injected Type Attributes:**
168
+ - ``access_key_id`` (str): The access key ID for authentication
169
+ - ``secret_access_key`` (str): The secret access key for authentication
170
+ - ``security_token`` (str): The temporary security token
171
+ - ``expiration`` (str): The expiration time of the credentials
172
+
173
+ Args:
174
+ provider_name: The credential provider name
175
+ agency_session_name: An identifier for the assumed agency session.
176
+ duration_seconds: The duration, in seconds, of the agency session
177
+ policy: IAM policy to further restrict the permissions of the STS token
178
+ source_identity: The source identity specified by the user
179
+ tags: A list of session tags to apply to the STS token
180
+ transitive_tag_keys: A list of keys for session tags that are transitive
181
+ into: Parameter name to inject the STS token into
182
+ ignore_ssl_verification: Whether to ignore SSL verification
183
+
184
+ Returns:
185
+ Decorator function
186
+
187
+ Example:
188
+ >>> from agentarts.sdk import require_sts_token
189
+ >>> @require_sts_token(provider_name="huaweicloud-iam", agency_session_name="example-session")
190
+ ... async def access_resource(sts_credentials: StsCredentials | None = None):
191
+ ... print(f"AK: {sts_credentials.access_key_id}")
192
+ ... print(f"SK: {sts_credentials.secret_access_key}")
193
+ """
194
+
195
+ def decorator(func: Callable) -> Callable:
196
+ @wraps(func)
197
+ async def async_wrapper(*args: Any, **kwargs: Any) -> Any:
198
+ client = IdentityClient(
199
+ region=get_region(), ignore_ssl_verification=ignore_ssl_verification
200
+ )
201
+ kwargs[into] = _get_sts_token(client)
202
+ return await func(*args, **kwargs)
203
+
204
+ @wraps(func)
205
+ def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
206
+ client = IdentityClient(
207
+ region=get_region(), ignore_ssl_verification=ignore_ssl_verification
208
+ )
209
+ kwargs[into] = _get_sts_token(client)
210
+ return func(*args, **kwargs)
211
+
212
+ if asyncio.iscoroutinefunction(func):
213
+ return async_wrapper
214
+ return sync_wrapper
215
+
216
+ def _get_sts_token(client: IdentityClient) -> GetResourceStsTokenResponseBodyCredentials:
217
+ return client.get_resource_sts_token(
218
+ provider_name=provider_name,
219
+ workload_access_token=_get_workload_access_token(client),
220
+ agency_session_name=agency_session_name,
221
+ duration_seconds=duration_seconds,
222
+ policy=policy,
223
+ source_identity=source_identity,
224
+ tags=tags,
225
+ transitive_tag_keys=transitive_tag_keys,
226
+ )
227
+
228
+ return decorator
229
+
230
+
231
+ def _get_workload_access_token(client: IdentityClient) -> str:
232
+ token = AgentArtsRuntimeContext.get_workload_access_token()
233
+ if token is not None:
234
+ logger.info("Retrieved workload access token from context")
235
+ return token
236
+ logger.info(
237
+ "No workload access token found in context. Falling back to local authentication setup."
238
+ )
239
+ return _set_up_local_auth(client)
240
+
241
+
242
+ def _get_oauth2_callback_url(
243
+ user_provided_oauth2_callback_url: str | None,
244
+ ) -> str | None:
245
+ if user_provided_oauth2_callback_url:
246
+ return user_provided_oauth2_callback_url
247
+
248
+ return AgentArtsRuntimeContext.get_oauth2_callback_url()
249
+
250
+
251
+ def _get_oauth2_custom_state(
252
+ user_provided_custom_state: str | None,
253
+ ) -> str | None:
254
+ if user_provided_custom_state:
255
+ return user_provided_custom_state
256
+
257
+ return AgentArtsRuntimeContext.get_oauth2_custom_state()
258
+
259
+
260
+ def _set_up_local_auth(client: IdentityClient) -> str:
261
+ def _ensure_workload_identity(client: IdentityClient, config: Config) -> str:
262
+ """Ensure a workload identity exists, either from config or by creating it."""
263
+ workload_identity_name = config.workload_identity_name
264
+ if workload_identity_name:
265
+ logger.info(
266
+ "Found existing workload identity from %s: %s",
267
+ config.path.absolute(),
268
+ workload_identity_name,
269
+ )
270
+ else:
271
+ workload_identity: WorkloadIdentity = client.create_workload_identity()
272
+ logger.info("Created a workload identity")
273
+ workload_identity_name = workload_identity.name
274
+ config.workload_identity_name = workload_identity.name
275
+ config.save()
276
+ return workload_identity_name
277
+
278
+ def _ensure_user_id(config: Config) -> str:
279
+ """Ensure a user ID exists, checking context, then config, then generating one."""
280
+ user_id = AgentArtsRuntimeContext.get_user_id()
281
+ if user_id:
282
+ logger.info("Using user id from context: %s", user_id)
283
+ else:
284
+ user_id = config.user_id
285
+ if user_id:
286
+ logger.info(
287
+ "Found existing user id from %s: %s",
288
+ config.path.absolute(),
289
+ user_id,
290
+ )
291
+ else:
292
+ user_id = uuid.uuid4().hex[:8]
293
+ logger.info("Created an user id")
294
+ config.user_id = user_id
295
+ config.save()
296
+ return user_id
297
+
298
+ config = Config.load()
299
+
300
+ workload_identity_name = _ensure_workload_identity(client, config)
301
+
302
+ user_id = _ensure_user_id(config)
303
+
304
+ return client.create_workload_access_token(workload_identity_name, user_id=user_id)
@@ -0,0 +1,36 @@
1
+ import json
2
+ import logging
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ from pydantic import BaseModel, ConfigDict, Field
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+
11
+ class Config(BaseModel):
12
+ model_config = ConfigDict(validate_assignment=True)
13
+
14
+ workload_identity_name: str | None = None
15
+ user_id: str | None = None
16
+ path: Path = Field(default=Path(".agent_identity.json"), repr=False, exclude=True)
17
+
18
+ @classmethod
19
+ def load(cls, path: str = ".agent_identity.json") -> "Config":
20
+ config_path = Path(path)
21
+ if config_path.exists():
22
+ try:
23
+ with open(config_path, encoding="utf-8") as f:
24
+ data: dict[str, Any] = json.load(f) or {}
25
+ return cls(**data, path=config_path)
26
+ except Exception:
27
+ logger.warning("Could not load existing config from %s", path)
28
+ return cls(path=config_path)
29
+
30
+ def save(self) -> None:
31
+ try:
32
+ data: dict[str, Any] = self.model_dump()
33
+ with open(self.path, "w", encoding="utf-8") as f:
34
+ json.dump(data, f, indent=2)
35
+ except Exception:
36
+ logger.warning("Could not write config to %s", self.path)
@@ -0,0 +1,60 @@
1
+ """Type aliases for improved developer experience.
2
+
3
+ This module provides user-friendly type aliases for types used throughout the SDK.
4
+ These aliases make injected types discoverable without reading source code.
5
+ """
6
+
7
+ import sys
8
+ from typing import TypeAlias
9
+
10
+ if sys.version_info >= (3, 11):
11
+ from enum import StrEnum
12
+ else:
13
+ from enum import Enum
14
+
15
+ class StrEnum(str, Enum):
16
+ pass
17
+
18
+
19
+ from huaweicloudsdkagentidentity.v1 import (
20
+ CredentialProviderVendor,
21
+ GetResourceStsTokenResponseBodyCredentials,
22
+ Oauth2Discovery,
23
+ )
24
+
25
+ StsCredentials: TypeAlias = GetResourceStsTokenResponseBodyCredentials
26
+ """Type alias for STS token credentials.
27
+
28
+ This type is injected by the @require_sts_token decorator into your function.
29
+
30
+ Attributes:
31
+ access_key_id: The access key ID for authentication
32
+ secret_access_key: The secret access key for authentication
33
+ security_token: The temporary security token
34
+ expiration: The expiration time of the credentials
35
+
36
+ Example:
37
+ >>> from agentarts.sdk.identity import require_sts_token, StsCredentials
38
+ >>> @require_sts_token(provider_name="huaweicloud-iam", agency_session_name="example-session")
39
+ ... async def my_func(sts_credentials: StsCredentials | None = None):
40
+ ... print(sts_credentials.access_key_id)
41
+ """
42
+
43
+ OAuth2Discovery: TypeAlias = Oauth2Discovery
44
+
45
+
46
+ class OAuth2Vendor(StrEnum):
47
+ """OAuth2 credential provider vendors.
48
+
49
+ Values are sourced from the SDK's CredentialProviderVendor class constants.
50
+
51
+ Example:
52
+ >>> from agentarts.sdk.identity import OAuth2Vendor
53
+ >>> OAuth2Vendor.GOOGLEOAUTH2
54
+ 'GoogleOauth2'
55
+ """
56
+
57
+ GITHUBOAUTH2 = CredentialProviderVendor.GITHUBOAUTH2
58
+ GOOGLEOAUTH2 = CredentialProviderVendor.GOOGLEOAUTH2
59
+ MICROSOFTOAUTH2 = CredentialProviderVendor.MICROSOFTOAUTH2
60
+ CUSTOMOAUTH2 = CredentialProviderVendor.CUSTOMOAUTH2
@@ -0,0 +1,65 @@
1
+ """
2
+ AgentArts Framework Integration Module
3
+
4
+ Provides adapters for popular agent frameworks with lazy loading support.
5
+
6
+ Supported frameworks:
7
+ - LangGraph (Priority)
8
+ - LangChain
9
+ - AutoGen
10
+ - CrewAI
11
+
12
+ Usage:
13
+ from agentarts.sdk.integration import LangGraphAdapter
14
+ adapter = LangGraphAdapter()
15
+ """
16
+
17
+ from typing import TYPE_CHECKING
18
+
19
+ if TYPE_CHECKING:
20
+ from agentarts.sdk.integration.base import BaseAdapter, WrappedAgent
21
+ from agentarts.sdk.integration.langgraph import LangGraphAdapter
22
+
23
+ __all__ = [
24
+ "BaseAdapter",
25
+ "LangGraphAdapter",
26
+ "WrappedAgent",
27
+ ]
28
+
29
+ _ADAPTER_MODULES = {
30
+ "BaseAdapter": "agentarts.sdk.integration.base",
31
+ "WrappedAgent": "agentarts.sdk.integration.base",
32
+ "LangGraphAdapter": "agentarts.sdk.integration.langgraph",
33
+ }
34
+
35
+
36
+ def __getattr__(name: str):
37
+ """
38
+ Lazy import adapters with friendly error messages.
39
+
40
+ Only imports the corresponding module when the user actually uses
41
+ a specific adapter. Provides clear installation instructions if
42
+ dependencies are missing.
43
+ """
44
+ if name not in _ADAPTER_MODULES:
45
+ msg = f"module {__name__!r} has no attribute {name!r}"
46
+ raise AttributeError(msg)
47
+
48
+ module_path = _ADAPTER_MODULES[name]
49
+
50
+ try:
51
+ import importlib
52
+ module = importlib.import_module(module_path)
53
+ return getattr(module, name)
54
+ except ImportError as e:
55
+ if name == "LangGraphAdapter":
56
+ msg = (
57
+ f"{name} requires the 'langgraph' extra to be installed. "
58
+ f"Install it with:\n"
59
+ f" pip install agentarts-sdk[langgraph]\n"
60
+ f"Original error: {e}"
61
+ )
62
+ raise ImportError(
63
+ msg
64
+ ) from e
65
+ raise
@@ -0,0 +1,23 @@
1
+ """
2
+ AgentArts LangGraph Integration
3
+
4
+ Provides adapter for LangGraph framework.
5
+ """
6
+
7
+ from agentarts.sdk.integration.langgraph.config import CheckpointerConfig
8
+ from agentarts.sdk.integration.langgraph.converter import (
9
+ langgraph_messages_to_memory,
10
+ langgraph_to_memory_message,
11
+ memory_messages_to_langgraph,
12
+ memory_to_langgraph_message,
13
+ )
14
+ from agentarts.sdk.integration.langgraph.saver import AgentArtsMemorySessionSaver
15
+
16
+ __all__ = [
17
+ "AgentArtsMemorySessionSaver",
18
+ "CheckpointerConfig",
19
+ "langgraph_messages_to_memory",
20
+ "langgraph_to_memory_message",
21
+ "memory_messages_to_langgraph",
22
+ "memory_to_langgraph_message",
23
+ ]
@@ -0,0 +1,100 @@
1
+ """
2
+ Configuration for AgentArts LangGraph Integration
3
+
4
+ Provides configuration classes for checkpoint saver and other LangGraph
5
+ integration components.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+
12
+ from pydantic import BaseModel
13
+
14
+ try:
15
+ from langchain_core.runnables import RunnableConfig
16
+
17
+ LANGGRAPH_AVAILABLE = True
18
+ except ImportError:
19
+ LANGGRAPH_AVAILABLE = False
20
+ RunnableConfig = dict[str, Any]
21
+
22
+
23
+ class CheckpointerConfig(BaseModel):
24
+ """
25
+ Runtime configuration for checkpoint operations.
26
+
27
+ This class holds runtime parameters extracted from LangGraph's RunnableConfig,
28
+ used during checkpoint save/load operations.
29
+
30
+ Attributes:
31
+ thread_id: Thread/conversation ID for session management
32
+ actor_id: Actor/user ID participating in the conversation
33
+ checkpoint_ns: Checkpoint namespace for isolation
34
+ checkpoint_id: Specific checkpoint ID for retrieval
35
+
36
+ Class Methods:
37
+ from_runnable_config: Extract configuration from LangGraph RunnableConfig
38
+
39
+ Usage:
40
+ >>> # From RunnableConfig
41
+ >>> runnable_config = {"configurable": {"thread_id": "conv-123"}}
42
+ >>> config = CheckpointerConfig.from_runnable_config(runnable_config)
43
+ >>> print(config.thread_id) # "conv-123"
44
+ """
45
+
46
+ thread_id: str
47
+ actor_id: str = ""
48
+ assistant_id: str = ""
49
+ checkpoint_ns: str | None = None
50
+ checkpoint_id: str | None = None
51
+
52
+ @property
53
+ def session_id(self)->str:
54
+ return self.thread_id
55
+
56
+ @classmethod
57
+ def from_runnable_config(cls, config: RunnableConfig) -> CheckpointerConfig:
58
+ """
59
+ Extract CheckpointerConfig from LangGraph RunnableConfig.
60
+
61
+ Args:
62
+ config: LangGraph RunnableConfig containing configurable parameters
63
+
64
+ Returns:
65
+ CheckpointerConfig instance with extracted parameters
66
+ """
67
+ configurable = config.get("configurable", {})
68
+ if not configurable:
69
+ msg = "RunableConfig has no configurable parameters in AgentArtsMemorySessionSaver"
70
+ raise ValueError(msg)
71
+ thread_id = configurable.get("thread_id")
72
+ if not thread_id:
73
+ msg = "RunableConfig has no thread_id parameter in AgentArtsMemorySessionSaver"
74
+ raise ValueError(msg)
75
+
76
+ return cls(
77
+ thread_id=thread_id,
78
+ actor_id=configurable.get("actor_id", ""),
79
+ assistant_id=configurable.get("assistant_id", ""),
80
+ checkpoint_ns=configurable.get("checkpoint_ns"),
81
+ checkpoint_id=configurable.get("checkpoint_id"),
82
+ )
83
+
84
+ def to_runnable_config(self) -> RunnableConfig:
85
+ """
86
+ Convert to LangGraph RunnableConfig format.
87
+
88
+ Returns:
89
+ RunnableConfig dictionary with configurable parameters
90
+ """
91
+ configurable: dict[str, Any] = {"thread_id": self.thread_id}
92
+
93
+ if self.actor_id:
94
+ configurable["actor_id"] = self.actor_id
95
+ if self.checkpoint_ns is not None:
96
+ configurable["checkpoint_ns"] = self.checkpoint_ns
97
+ if self.checkpoint_id is not None:
98
+ configurable["checkpoint_id"] = self.checkpoint_id
99
+
100
+ return {"configurable": configurable}