agentrun-inner-test 0.0.46__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 (135) hide show
  1. agentrun/__init__.py +325 -0
  2. agentrun/agent_runtime/__client_async_template.py +466 -0
  3. agentrun/agent_runtime/__endpoint_async_template.py +345 -0
  4. agentrun/agent_runtime/__init__.py +53 -0
  5. agentrun/agent_runtime/__runtime_async_template.py +477 -0
  6. agentrun/agent_runtime/api/__data_async_template.py +58 -0
  7. agentrun/agent_runtime/api/__init__.py +6 -0
  8. agentrun/agent_runtime/api/control.py +1362 -0
  9. agentrun/agent_runtime/api/data.py +98 -0
  10. agentrun/agent_runtime/client.py +868 -0
  11. agentrun/agent_runtime/endpoint.py +649 -0
  12. agentrun/agent_runtime/model.py +362 -0
  13. agentrun/agent_runtime/runtime.py +904 -0
  14. agentrun/credential/__client_async_template.py +177 -0
  15. agentrun/credential/__credential_async_template.py +216 -0
  16. agentrun/credential/__init__.py +28 -0
  17. agentrun/credential/api/__init__.py +5 -0
  18. agentrun/credential/api/control.py +606 -0
  19. agentrun/credential/client.py +319 -0
  20. agentrun/credential/credential.py +381 -0
  21. agentrun/credential/model.py +248 -0
  22. agentrun/integration/__init__.py +21 -0
  23. agentrun/integration/agentscope/__init__.py +12 -0
  24. agentrun/integration/agentscope/adapter.py +17 -0
  25. agentrun/integration/agentscope/builtin.py +65 -0
  26. agentrun/integration/agentscope/message_adapter.py +185 -0
  27. agentrun/integration/agentscope/model_adapter.py +60 -0
  28. agentrun/integration/agentscope/tool_adapter.py +59 -0
  29. agentrun/integration/builtin/__init__.py +16 -0
  30. agentrun/integration/builtin/model.py +93 -0
  31. agentrun/integration/builtin/sandbox.py +1234 -0
  32. agentrun/integration/builtin/toolset.py +47 -0
  33. agentrun/integration/crewai/__init__.py +12 -0
  34. agentrun/integration/crewai/adapter.py +9 -0
  35. agentrun/integration/crewai/builtin.py +65 -0
  36. agentrun/integration/crewai/model_adapter.py +31 -0
  37. agentrun/integration/crewai/tool_adapter.py +26 -0
  38. agentrun/integration/google_adk/__init__.py +12 -0
  39. agentrun/integration/google_adk/adapter.py +15 -0
  40. agentrun/integration/google_adk/builtin.py +65 -0
  41. agentrun/integration/google_adk/message_adapter.py +144 -0
  42. agentrun/integration/google_adk/model_adapter.py +46 -0
  43. agentrun/integration/google_adk/tool_adapter.py +235 -0
  44. agentrun/integration/langchain/__init__.py +30 -0
  45. agentrun/integration/langchain/adapter.py +15 -0
  46. agentrun/integration/langchain/builtin.py +71 -0
  47. agentrun/integration/langchain/message_adapter.py +141 -0
  48. agentrun/integration/langchain/model_adapter.py +37 -0
  49. agentrun/integration/langchain/tool_adapter.py +50 -0
  50. agentrun/integration/langgraph/__init__.py +35 -0
  51. agentrun/integration/langgraph/adapter.py +20 -0
  52. agentrun/integration/langgraph/agent_converter.py +1073 -0
  53. agentrun/integration/langgraph/builtin.py +65 -0
  54. agentrun/integration/pydantic_ai/__init__.py +12 -0
  55. agentrun/integration/pydantic_ai/adapter.py +13 -0
  56. agentrun/integration/pydantic_ai/builtin.py +65 -0
  57. agentrun/integration/pydantic_ai/model_adapter.py +44 -0
  58. agentrun/integration/pydantic_ai/tool_adapter.py +19 -0
  59. agentrun/integration/utils/__init__.py +112 -0
  60. agentrun/integration/utils/adapter.py +560 -0
  61. agentrun/integration/utils/canonical.py +164 -0
  62. agentrun/integration/utils/converter.py +134 -0
  63. agentrun/integration/utils/model.py +110 -0
  64. agentrun/integration/utils/tool.py +1759 -0
  65. agentrun/model/__client_async_template.py +357 -0
  66. agentrun/model/__init__.py +57 -0
  67. agentrun/model/__model_proxy_async_template.py +270 -0
  68. agentrun/model/__model_service_async_template.py +267 -0
  69. agentrun/model/api/__init__.py +6 -0
  70. agentrun/model/api/control.py +1173 -0
  71. agentrun/model/api/data.py +196 -0
  72. agentrun/model/client.py +674 -0
  73. agentrun/model/model.py +235 -0
  74. agentrun/model/model_proxy.py +439 -0
  75. agentrun/model/model_service.py +438 -0
  76. agentrun/sandbox/__aio_sandbox_async_template.py +523 -0
  77. agentrun/sandbox/__browser_sandbox_async_template.py +110 -0
  78. agentrun/sandbox/__client_async_template.py +491 -0
  79. agentrun/sandbox/__code_interpreter_sandbox_async_template.py +463 -0
  80. agentrun/sandbox/__init__.py +69 -0
  81. agentrun/sandbox/__sandbox_async_template.py +463 -0
  82. agentrun/sandbox/__template_async_template.py +152 -0
  83. agentrun/sandbox/aio_sandbox.py +905 -0
  84. agentrun/sandbox/api/__aio_data_async_template.py +335 -0
  85. agentrun/sandbox/api/__browser_data_async_template.py +140 -0
  86. agentrun/sandbox/api/__code_interpreter_data_async_template.py +206 -0
  87. agentrun/sandbox/api/__init__.py +19 -0
  88. agentrun/sandbox/api/__sandbox_data_async_template.py +107 -0
  89. agentrun/sandbox/api/aio_data.py +551 -0
  90. agentrun/sandbox/api/browser_data.py +172 -0
  91. agentrun/sandbox/api/code_interpreter_data.py +396 -0
  92. agentrun/sandbox/api/control.py +1051 -0
  93. agentrun/sandbox/api/playwright_async.py +492 -0
  94. agentrun/sandbox/api/playwright_sync.py +492 -0
  95. agentrun/sandbox/api/sandbox_data.py +154 -0
  96. agentrun/sandbox/browser_sandbox.py +185 -0
  97. agentrun/sandbox/client.py +925 -0
  98. agentrun/sandbox/code_interpreter_sandbox.py +823 -0
  99. agentrun/sandbox/model.py +397 -0
  100. agentrun/sandbox/sandbox.py +848 -0
  101. agentrun/sandbox/template.py +217 -0
  102. agentrun/server/__init__.py +191 -0
  103. agentrun/server/agui_normalizer.py +180 -0
  104. agentrun/server/agui_protocol.py +797 -0
  105. agentrun/server/invoker.py +309 -0
  106. agentrun/server/model.py +427 -0
  107. agentrun/server/openai_protocol.py +535 -0
  108. agentrun/server/protocol.py +140 -0
  109. agentrun/server/server.py +208 -0
  110. agentrun/toolset/__client_async_template.py +62 -0
  111. agentrun/toolset/__init__.py +51 -0
  112. agentrun/toolset/__toolset_async_template.py +204 -0
  113. agentrun/toolset/api/__init__.py +17 -0
  114. agentrun/toolset/api/control.py +262 -0
  115. agentrun/toolset/api/mcp.py +100 -0
  116. agentrun/toolset/api/openapi.py +1251 -0
  117. agentrun/toolset/client.py +102 -0
  118. agentrun/toolset/model.py +321 -0
  119. agentrun/toolset/toolset.py +270 -0
  120. agentrun/utils/__data_api_async_template.py +720 -0
  121. agentrun/utils/__init__.py +5 -0
  122. agentrun/utils/__resource_async_template.py +158 -0
  123. agentrun/utils/config.py +258 -0
  124. agentrun/utils/control_api.py +78 -0
  125. agentrun/utils/data_api.py +1120 -0
  126. agentrun/utils/exception.py +151 -0
  127. agentrun/utils/helper.py +108 -0
  128. agentrun/utils/log.py +77 -0
  129. agentrun/utils/model.py +168 -0
  130. agentrun/utils/resource.py +291 -0
  131. agentrun_inner_test-0.0.46.dist-info/METADATA +263 -0
  132. agentrun_inner_test-0.0.46.dist-info/RECORD +135 -0
  133. agentrun_inner_test-0.0.46.dist-info/WHEEL +5 -0
  134. agentrun_inner_test-0.0.46.dist-info/licenses/LICENSE +201 -0
  135. agentrun_inner_test-0.0.46.dist-info/top_level.txt +1 -0
@@ -0,0 +1,5 @@
1
+ """Utils 模块 / Utils Module
2
+
3
+ 此模块提供通用工具函数和基础设施。
4
+ This module provides common utility functions and infrastructure.
5
+ """
@@ -0,0 +1,158 @@
1
+ """资源基类模板 / Resource Base Template
2
+
3
+ 此模板用于生成资源对象的基类代码。
4
+ This template is used to generate base class code for resource objects.
5
+ """
6
+
7
+ from abc import abstractmethod
8
+ import asyncio
9
+ import time
10
+ from typing import Awaitable, Callable, List, Optional
11
+
12
+ from typing_extensions import Self
13
+
14
+ from agentrun.utils.config import Config
15
+ from agentrun.utils.exception import DeleteResourceError, ResourceNotExistError
16
+ from agentrun.utils.log import logger
17
+
18
+ from .model import BaseModel, PageableInput, Status
19
+
20
+
21
+ class ResourceBase(BaseModel):
22
+ status: Optional[Status] = None
23
+ _config: Optional[Config] = None
24
+
25
+ @classmethod
26
+ @abstractmethod
27
+ async def _list_page_async(
28
+ cls,
29
+ page_input: PageableInput,
30
+ config: Optional[Config] = None,
31
+ **kwargs,
32
+ ) -> list:
33
+ ...
34
+
35
+ @classmethod
36
+ async def _list_all_async(
37
+ cls,
38
+ uniq_id_callback: Callable[[Self], str],
39
+ config: Optional[Config] = None,
40
+ **kwargs,
41
+ ) -> list:
42
+ all_results: List[Self] = []
43
+ page = 1
44
+ page_size = 50
45
+ while True:
46
+ page_results = await cls._list_page_async(
47
+ PageableInput(
48
+ page_number=page,
49
+ page_size=page_size,
50
+ ),
51
+ config=config,
52
+ **kwargs,
53
+ )
54
+ page += 1
55
+ all_results.extend(page_results) # type: ignore
56
+ if len(page_results) < page_size:
57
+ break
58
+
59
+ result_set = set()
60
+ results: list = []
61
+ for item in all_results:
62
+ uniq_id = uniq_id_callback(item)
63
+ if uniq_id not in result_set:
64
+ result_set.add(uniq_id)
65
+ results.append(item)
66
+
67
+ return results
68
+
69
+ @abstractmethod
70
+ async def refresh_async(self, config: Optional[Config] = None) -> Self:
71
+ ...
72
+
73
+ @abstractmethod
74
+ async def delete_async(self, config: Optional[Config] = None) -> Self:
75
+ ...
76
+
77
+ async def __wait_until_async(
78
+ self,
79
+ check_finished_callback_async: Callable[[Self], Awaitable[bool]],
80
+ interval_seconds: int = 5,
81
+ timeout_seconds: int = 300,
82
+ ) -> Self:
83
+ """等待智能体运行时进入就绪状态"""
84
+
85
+ start_time = time.time()
86
+ while True:
87
+ if await check_finished_callback_async(self):
88
+ return self
89
+
90
+ if time.time() - start_time > timeout_seconds:
91
+ raise TimeoutError("等待就绪超时")
92
+
93
+ await asyncio.sleep(interval_seconds)
94
+
95
+ async def wait_until_ready_or_failed_async(
96
+ self,
97
+ callback: Optional[Callable[[Self], None]] = None,
98
+ interval_seconds: int = 5,
99
+ timeout_seconds: int = 300,
100
+ ):
101
+ """等待智能体运行时进入就绪状态"""
102
+
103
+ async def check_ready_callback(resource: Self) -> bool:
104
+ await resource.refresh_async()
105
+ if callback:
106
+ callback(resource)
107
+ logger.debug("当前状态:%s", resource.status)
108
+
109
+ return Status.is_final_status(resource.status)
110
+
111
+ await self.__wait_until_async(
112
+ check_ready_callback,
113
+ interval_seconds=interval_seconds,
114
+ timeout_seconds=timeout_seconds,
115
+ )
116
+
117
+ async def delete_and_wait_until_finished_async(
118
+ self,
119
+ callback: Optional[Callable[[Self], None]] = None,
120
+ interval_seconds: int = 5,
121
+ timeout_seconds: int = 300,
122
+ ):
123
+ """等待智能体运行时被删除"""
124
+ try:
125
+ await self.delete_async()
126
+ except ResourceNotExistError:
127
+ return
128
+
129
+ async def check_deleted_callback(resource: Self) -> bool:
130
+ try:
131
+ await resource.refresh_async()
132
+ if callback:
133
+ callback(resource)
134
+ except ResourceNotExistError:
135
+ return True
136
+
137
+ if resource.status == Status.DELETING:
138
+ return False
139
+
140
+ raise DeleteResourceError(f"Resource status is {resource.status}")
141
+
142
+ await self.__wait_until_async(
143
+ check_deleted_callback,
144
+ interval_seconds=interval_seconds,
145
+ timeout_seconds=timeout_seconds,
146
+ )
147
+
148
+ def set_config(self, config: Config) -> Self:
149
+ """设置配置
150
+
151
+ Args:
152
+ config: 配置
153
+
154
+ Returns:
155
+ Self: 当前对象
156
+ """
157
+ self._config = config
158
+ return self
@@ -0,0 +1,258 @@
1
+ """配置管理模块 / Configuration Management Module
2
+
3
+ 此模块提供 AgentRun SDK 的全局配置管理功能。
4
+ This module provides global configuration management for AgentRun SDK.
5
+ """
6
+
7
+ import os
8
+ from typing import Dict, Optional
9
+
10
+ from dotenv import load_dotenv
11
+
12
+ load_dotenv()
13
+
14
+
15
+ def get_env_with_default(default: str, *key: str) -> str:
16
+ """从环境变量获取值,支持多个候选键 / Get value from environment variables with multiple fallback keys
17
+
18
+ Args:
19
+ default: 默认值 / Default value
20
+ *key: 候选环境变量名 / Candidate environment variable names
21
+
22
+ Returns:
23
+ str: 环境变量值或默认值 / Environment variable value or default value
24
+ """
25
+ for k in key:
26
+ v = os.getenv(k)
27
+ if v is not None:
28
+ return v
29
+ return default
30
+
31
+
32
+ class Config:
33
+ """AgentRun SDK 全局配置类 / AgentRun SDK Global Configuration Class
34
+
35
+ 用于管理账号凭证和客户端配置。
36
+ Used for managing account credentials and client configuration.
37
+
38
+ 支持从参数或环境变量读取配置。
39
+ Supports reading configuration from parameters or environment variables.
40
+
41
+ Examples:
42
+ >>> # 从参数创建配置 / Create config from parameters
43
+ >>> config = Config(
44
+ ... account_id="your-account-id",
45
+ ... access_key_id="your-key-id",
46
+ ... access_key_secret="your-secret"
47
+ ... )
48
+ >>> # 或从环境变量读取 / Or read from environment variables
49
+ >>> config = Config()
50
+ """
51
+
52
+ __slots__ = (
53
+ "_access_key_id",
54
+ "_access_key_secret",
55
+ "_security_token",
56
+ "_account_id",
57
+ "_token",
58
+ "_region_id",
59
+ "_timeout",
60
+ "_read_timeout",
61
+ "_control_endpoint",
62
+ "_data_endpoint",
63
+ "_devs_endpoint",
64
+ "_headers",
65
+ "__weakref__",
66
+ )
67
+
68
+ def __init__(
69
+ self,
70
+ access_key_id: Optional[str] = None,
71
+ access_key_secret: Optional[str] = None,
72
+ security_token: Optional[str] = None,
73
+ account_id: Optional[str] = None,
74
+ token: Optional[str] = None,
75
+ region_id: Optional[str] = None,
76
+ timeout: Optional[int] = 600,
77
+ read_timeout: Optional[int] = 100000,
78
+ control_endpoint: Optional[str] = None,
79
+ data_endpoint: Optional[str] = None,
80
+ devs_endpoint: Optional[str] = None,
81
+ headers: Optional[Dict[str, str]] = None,
82
+ ) -> None:
83
+ """初始化配置 / Initialize configuration
84
+
85
+ Args:
86
+ access_key_id: Access Key ID / Access Key ID
87
+ 未提供时从环境变量读取: AGENTRUN_ACCESS_KEY_ID 或 ALIBABA_CLOUD_ACCESS_KEY_ID
88
+ Read from env vars if not provided: AGENTRUN_ACCESS_KEY_ID or ALIBABA_CLOUD_ACCESS_KEY_ID
89
+ access_key_secret: Access Key Secret / Access Key Secret
90
+ 未提供时从环境变量读取: AGENTRUN_ACCESS_KEY_SECRET 或 ALIBABA_CLOUD_ACCESS_KEY_SECRET
91
+ Read from env vars if not provided: AGENTRUN_ACCESS_KEY_SECRET or ALIBABA_CLOUD_ACCESS_KEY_SECRET
92
+ security_token: 安全令牌 / Security token
93
+ 未提供时从环境变量读取: AGENTRUN_SECURITY_TOKEN 或 ALIBABA_CLOUD_SECURITY_TOKEN
94
+ Read from env vars if not provided: AGENTRUN_SECURITY_TOKEN or ALIBABA_CLOUD_SECURITY_TOKEN
95
+ account_id: 账号 ID / Account ID
96
+ 未提供时从环境变量读取: AGENTRUN_ACCOUNT_ID 或 FC_ACCOUNT_ID
97
+ Read from env vars if not provided: AGENTRUN_ACCOUNT_ID or FC_ACCOUNT_ID
98
+ token: 自定义令牌,用于数据链路调用 / Custom token for data API calls
99
+ region_id: 区域 ID,默认 cn-hangzhou / Region ID, defaults to cn-hangzhou
100
+ timeout: 请求超时时间(秒),默认 600 / Request timeout in seconds, defaults to 600
101
+ read_timeout: 读取超时时间(秒),默认 100000 / Read timeout in seconds, defaults to 100000
102
+ control_endpoint: 自定义控制链路端点,可选 / Custom control endpoint, optional
103
+ data_endpoint: 自定义数据链路端点,可选 / Custom data endpoint, optional
104
+ devs_endpoint: 自定义 DevS 端点,可选 / Custom DevS endpoint, optional
105
+ headers: 自定义请求头,可选 / Custom request headers, optional
106
+ """
107
+
108
+ if access_key_id is None:
109
+ access_key_id = get_env_with_default(
110
+ "", "AGENTRUN_ACCESS_KEY_ID", "ALIBABA_CLOUD_ACCESS_KEY_ID"
111
+ )
112
+ if access_key_secret is None:
113
+ access_key_secret = get_env_with_default(
114
+ "",
115
+ "AGENTRUN_ACCESS_KEY_SECRET",
116
+ "ALIBABA_CLOUD_ACCESS_KEY_SECRET",
117
+ )
118
+ if security_token is None:
119
+ security_token = get_env_with_default(
120
+ "", "AGENTRUN_SECURITY_TOKEN", "ALIBABA_CLOUD_SECURITY_TOKEN"
121
+ )
122
+ if account_id is None:
123
+ account_id = get_env_with_default(
124
+ "", "AGENTRUN_ACCOUNT_ID", "FC_ACCOUNT_ID"
125
+ )
126
+ if region_id is None:
127
+ region_id = get_env_with_default(
128
+ "cn-hangzhou", "AGENTRUN_REGION", "FC_REGION"
129
+ )
130
+ if control_endpoint is None:
131
+ control_endpoint = get_env_with_default(
132
+ "", "AGENTRUN_CONTROL_ENDPOINT"
133
+ )
134
+ if data_endpoint is None:
135
+ data_endpoint = get_env_with_default("", "AGENTRUN_DATA_ENDPOINT")
136
+ if devs_endpoint is None:
137
+ devs_endpoint = get_env_with_default("", "DEVS_ENDPOINT")
138
+
139
+ self._access_key_id = access_key_id
140
+ self._access_key_secret = access_key_secret
141
+ self._security_token = security_token
142
+ self._account_id = account_id
143
+ self._token = token
144
+ self._region_id = region_id
145
+ self._timeout = timeout
146
+ self._read_timeout = read_timeout
147
+ self._control_endpoint = control_endpoint
148
+ self._data_endpoint = data_endpoint
149
+ self._devs_endpoint = devs_endpoint
150
+ self._headers = headers or {}
151
+
152
+ @classmethod
153
+ def with_configs(cls, *configs: Optional["Config"]) -> "Config":
154
+ return cls().update(*configs)
155
+
156
+ def update(self, *configs: Optional["Config"]) -> "Config":
157
+ """
158
+ 使用给定的配置对象,返回新的实例,优先使用靠后的值
159
+
160
+ Args:
161
+ configs: 要合并的配置对象
162
+
163
+ Returns:
164
+ 合并后的新配置对象
165
+ """
166
+
167
+ for config in configs:
168
+ if config is None:
169
+ continue
170
+
171
+ for attr in filter(
172
+ lambda x: x != "__weakref__",
173
+ self.__slots__,
174
+ ):
175
+ value = getattr(config, attr)
176
+ if value is not None:
177
+ if type(value) is dict:
178
+ getattr(self, attr).update(getattr(config, attr) or {})
179
+ else:
180
+ setattr(self, attr, value)
181
+
182
+ return self
183
+
184
+ def __repr__(self) -> str:
185
+
186
+ return "Config{%s}" % (
187
+ ", ".join([
188
+ f'"{key}": "{getattr(self, key)}"'
189
+ for key in self.__slots__
190
+ if key != "__weakref__"
191
+ ])
192
+ )
193
+
194
+ def get_access_key_id(self) -> str:
195
+ """获取 Access Key ID"""
196
+ return self._access_key_id
197
+
198
+ def get_access_key_secret(self) -> str:
199
+ """获取 Access Key Secret"""
200
+ return self._access_key_secret
201
+
202
+ def get_security_token(self) -> str:
203
+ """获取安全令牌"""
204
+ return self._security_token
205
+
206
+ def get_account_id(self) -> str:
207
+ """获取账号 ID"""
208
+ if not self._account_id:
209
+ raise ValueError(
210
+ "account id is not set, please add AGENTRUN_ACCOUNT_ID env"
211
+ " variable or set it in code."
212
+ )
213
+
214
+ return self._account_id
215
+
216
+ def get_token(self) -> Optional[str]:
217
+ """获取自定义令牌"""
218
+ return self._token
219
+
220
+ def get_region_id(self) -> str:
221
+ """获取区域 ID"""
222
+ if self._region_id:
223
+ return self._region_id
224
+
225
+ return "cn-hangzhou"
226
+
227
+ def get_timeout(self) -> Optional[int]:
228
+ """获取请求超时时间"""
229
+ return self._timeout or 600
230
+
231
+ def get_read_timeout(self) -> Optional[int]:
232
+ """获取请求超时时间"""
233
+ return self._read_timeout or 100000
234
+
235
+ def get_control_endpoint(self) -> str:
236
+ """获取控制链路端点"""
237
+ if self._control_endpoint:
238
+ return self._control_endpoint
239
+
240
+ return f"https://agentrun.{self.get_region_id()}.aliyuncs.com"
241
+
242
+ def get_data_endpoint(self) -> str:
243
+ """获取数据链路端点"""
244
+ if self._data_endpoint:
245
+ return self._data_endpoint
246
+
247
+ return f"https://{self.get_account_id()}.agentrun-data.{self.get_region_id()}.aliyuncs.com"
248
+
249
+ def get_devs_endpoint(self) -> str:
250
+ """获取 Devs 端点"""
251
+ if self._devs_endpoint:
252
+ return self._devs_endpoint
253
+
254
+ return f"https://devs.{self.get_region_id()}.aliyuncs.com"
255
+
256
+ def get_headers(self) -> Dict[str, str]:
257
+ """获取自定义请求头"""
258
+ return self._headers or {}
@@ -0,0 +1,78 @@
1
+ """控制 API 基类模块 / Control API Base Module
2
+
3
+ 此模块定义控制链路 API 的基类。
4
+ This module defines the base class for control API.
5
+ """
6
+
7
+ from typing import Optional
8
+
9
+ from alibabacloud_agentrun20250910.client import Client as AgentRunClient
10
+ from alibabacloud_devs20230714.client import Client as DevsClient
11
+ from alibabacloud_tea_openapi import utils_models as open_api_util_models
12
+
13
+ from agentrun.utils.config import Config
14
+
15
+
16
+ class ControlAPI:
17
+ """控制链路客户端基类 / Control API Client Base Class
18
+
19
+ 提供控制链路和 DevS API 客户端的获取功能。
20
+ Provides functionality to get control API and DevS API clients.
21
+ """
22
+
23
+ def __init__(self, config: Optional[Config] = None):
24
+ """初始化 Control API 客户端 / Initialize Control API client
25
+
26
+ Args:
27
+ config: 全局配置对象,可选 / Global configuration object, optional
28
+ """
29
+ self.config = config
30
+
31
+ def _get_client(self, config: Optional[Config] = None) -> "AgentRunClient":
32
+ """获取 Control API 客户端实例 / Get Control API client instance
33
+
34
+ Args:
35
+ config: 配置对象,可选,用于覆盖默认配置 / Configuration object, optional, to override default config
36
+
37
+ Returns:
38
+ AgentRunClient: Control API 客户端实例 / Control API client instance
39
+ """
40
+
41
+ cfg = Config.with_configs(self.config, config)
42
+ endpoint = cfg.get_control_endpoint()
43
+ if endpoint.startswith("http://") or endpoint.startswith("https://"):
44
+ endpoint = endpoint.split("://", 1)[1]
45
+ return AgentRunClient(
46
+ open_api_util_models.Config(
47
+ access_key_id=cfg.get_access_key_id(),
48
+ access_key_secret=cfg.get_access_key_secret(),
49
+ security_token=cfg.get_security_token(),
50
+ region_id=cfg.get_region_id(),
51
+ endpoint=endpoint,
52
+ connect_timeout=cfg.get_timeout(), # type: ignore
53
+ )
54
+ )
55
+
56
+ def _get_devs_client(self, config: Optional[Config] = None) -> "DevsClient":
57
+ """
58
+ 获取 Devs API 客户端实例
59
+
60
+ Returns:
61
+ DevsClient: Devs API 客户端实例
62
+ """
63
+
64
+ cfg = Config.with_configs(self.config, config)
65
+ endpoint = cfg.get_devs_endpoint()
66
+ if endpoint.startswith("http://") or endpoint.startswith("https://"):
67
+ endpoint = endpoint.split("://", 1)[1]
68
+ return DevsClient(
69
+ open_api_util_models.Config(
70
+ access_key_id=cfg.get_access_key_id(),
71
+ access_key_secret=cfg.get_access_key_secret(),
72
+ security_token=cfg.get_security_token(),
73
+ region_id=cfg.get_region_id(),
74
+ endpoint=endpoint,
75
+ connect_timeout=cfg.get_timeout(), # type: ignore
76
+ read_timeout=cfg.get_read_timeout(), # type: ignore
77
+ )
78
+ )