agentrun-inner-test 0.0.62__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.
Potentially problematic release.
This version of agentrun-inner-test might be problematic. Click here for more details.
- agentrun/__init__.py +358 -0
- agentrun/agent_runtime/__client_async_template.py +466 -0
- agentrun/agent_runtime/__endpoint_async_template.py +345 -0
- agentrun/agent_runtime/__init__.py +53 -0
- agentrun/agent_runtime/__runtime_async_template.py +477 -0
- agentrun/agent_runtime/api/__data_async_template.py +58 -0
- agentrun/agent_runtime/api/__init__.py +6 -0
- agentrun/agent_runtime/api/control.py +1362 -0
- agentrun/agent_runtime/api/data.py +98 -0
- agentrun/agent_runtime/client.py +868 -0
- agentrun/agent_runtime/endpoint.py +649 -0
- agentrun/agent_runtime/model.py +362 -0
- agentrun/agent_runtime/runtime.py +904 -0
- agentrun/credential/__client_async_template.py +177 -0
- agentrun/credential/__credential_async_template.py +216 -0
- agentrun/credential/__init__.py +28 -0
- agentrun/credential/api/__init__.py +5 -0
- agentrun/credential/api/control.py +606 -0
- agentrun/credential/client.py +319 -0
- agentrun/credential/credential.py +381 -0
- agentrun/credential/model.py +248 -0
- agentrun/integration/__init__.py +21 -0
- agentrun/integration/agentscope/__init__.py +13 -0
- agentrun/integration/agentscope/adapter.py +17 -0
- agentrun/integration/agentscope/builtin.py +88 -0
- agentrun/integration/agentscope/message_adapter.py +185 -0
- agentrun/integration/agentscope/model_adapter.py +60 -0
- agentrun/integration/agentscope/tool_adapter.py +59 -0
- agentrun/integration/builtin/__init__.py +18 -0
- agentrun/integration/builtin/knowledgebase.py +137 -0
- agentrun/integration/builtin/model.py +93 -0
- agentrun/integration/builtin/sandbox.py +1234 -0
- agentrun/integration/builtin/toolset.py +47 -0
- agentrun/integration/crewai/__init__.py +13 -0
- agentrun/integration/crewai/adapter.py +9 -0
- agentrun/integration/crewai/builtin.py +88 -0
- agentrun/integration/crewai/model_adapter.py +31 -0
- agentrun/integration/crewai/tool_adapter.py +26 -0
- agentrun/integration/google_adk/__init__.py +13 -0
- agentrun/integration/google_adk/adapter.py +15 -0
- agentrun/integration/google_adk/builtin.py +88 -0
- agentrun/integration/google_adk/message_adapter.py +144 -0
- agentrun/integration/google_adk/model_adapter.py +46 -0
- agentrun/integration/google_adk/tool_adapter.py +235 -0
- agentrun/integration/langchain/__init__.py +31 -0
- agentrun/integration/langchain/adapter.py +15 -0
- agentrun/integration/langchain/builtin.py +94 -0
- agentrun/integration/langchain/message_adapter.py +141 -0
- agentrun/integration/langchain/model_adapter.py +37 -0
- agentrun/integration/langchain/tool_adapter.py +50 -0
- agentrun/integration/langgraph/__init__.py +36 -0
- agentrun/integration/langgraph/adapter.py +20 -0
- agentrun/integration/langgraph/agent_converter.py +1073 -0
- agentrun/integration/langgraph/builtin.py +88 -0
- agentrun/integration/pydantic_ai/__init__.py +13 -0
- agentrun/integration/pydantic_ai/adapter.py +13 -0
- agentrun/integration/pydantic_ai/builtin.py +88 -0
- agentrun/integration/pydantic_ai/model_adapter.py +44 -0
- agentrun/integration/pydantic_ai/tool_adapter.py +19 -0
- agentrun/integration/utils/__init__.py +112 -0
- agentrun/integration/utils/adapter.py +560 -0
- agentrun/integration/utils/canonical.py +164 -0
- agentrun/integration/utils/converter.py +134 -0
- agentrun/integration/utils/model.py +110 -0
- agentrun/integration/utils/tool.py +1759 -0
- agentrun/knowledgebase/__client_async_template.py +173 -0
- agentrun/knowledgebase/__init__.py +53 -0
- agentrun/knowledgebase/__knowledgebase_async_template.py +438 -0
- agentrun/knowledgebase/api/__data_async_template.py +414 -0
- agentrun/knowledgebase/api/__init__.py +19 -0
- agentrun/knowledgebase/api/control.py +606 -0
- agentrun/knowledgebase/api/data.py +624 -0
- agentrun/knowledgebase/client.py +311 -0
- agentrun/knowledgebase/knowledgebase.py +748 -0
- agentrun/knowledgebase/model.py +270 -0
- agentrun/memory_collection/__client_async_template.py +178 -0
- agentrun/memory_collection/__init__.py +37 -0
- agentrun/memory_collection/__memory_collection_async_template.py +457 -0
- agentrun/memory_collection/api/__init__.py +5 -0
- agentrun/memory_collection/api/control.py +610 -0
- agentrun/memory_collection/client.py +323 -0
- agentrun/memory_collection/memory_collection.py +844 -0
- agentrun/memory_collection/model.py +162 -0
- agentrun/model/__client_async_template.py +357 -0
- agentrun/model/__init__.py +57 -0
- agentrun/model/__model_proxy_async_template.py +270 -0
- agentrun/model/__model_service_async_template.py +267 -0
- agentrun/model/api/__init__.py +6 -0
- agentrun/model/api/control.py +1173 -0
- agentrun/model/api/data.py +196 -0
- agentrun/model/client.py +674 -0
- agentrun/model/model.py +235 -0
- agentrun/model/model_proxy.py +439 -0
- agentrun/model/model_service.py +438 -0
- agentrun/sandbox/__aio_sandbox_async_template.py +523 -0
- agentrun/sandbox/__browser_sandbox_async_template.py +110 -0
- agentrun/sandbox/__client_async_template.py +491 -0
- agentrun/sandbox/__code_interpreter_sandbox_async_template.py +463 -0
- agentrun/sandbox/__init__.py +69 -0
- agentrun/sandbox/__sandbox_async_template.py +463 -0
- agentrun/sandbox/__template_async_template.py +152 -0
- agentrun/sandbox/aio_sandbox.py +912 -0
- agentrun/sandbox/api/__aio_data_async_template.py +335 -0
- agentrun/sandbox/api/__browser_data_async_template.py +140 -0
- agentrun/sandbox/api/__code_interpreter_data_async_template.py +206 -0
- agentrun/sandbox/api/__init__.py +19 -0
- agentrun/sandbox/api/__sandbox_data_async_template.py +107 -0
- agentrun/sandbox/api/aio_data.py +551 -0
- agentrun/sandbox/api/browser_data.py +172 -0
- agentrun/sandbox/api/code_interpreter_data.py +396 -0
- agentrun/sandbox/api/control.py +1051 -0
- agentrun/sandbox/api/playwright_async.py +492 -0
- agentrun/sandbox/api/playwright_sync.py +492 -0
- agentrun/sandbox/api/sandbox_data.py +154 -0
- agentrun/sandbox/browser_sandbox.py +185 -0
- agentrun/sandbox/client.py +925 -0
- agentrun/sandbox/code_interpreter_sandbox.py +823 -0
- agentrun/sandbox/model.py +384 -0
- agentrun/sandbox/sandbox.py +848 -0
- agentrun/sandbox/template.py +217 -0
- agentrun/server/__init__.py +191 -0
- agentrun/server/agui_normalizer.py +180 -0
- agentrun/server/agui_protocol.py +797 -0
- agentrun/server/invoker.py +309 -0
- agentrun/server/model.py +427 -0
- agentrun/server/openai_protocol.py +535 -0
- agentrun/server/protocol.py +140 -0
- agentrun/server/server.py +208 -0
- agentrun/toolset/__client_async_template.py +62 -0
- agentrun/toolset/__init__.py +51 -0
- agentrun/toolset/__toolset_async_template.py +204 -0
- agentrun/toolset/api/__init__.py +17 -0
- agentrun/toolset/api/control.py +262 -0
- agentrun/toolset/api/mcp.py +100 -0
- agentrun/toolset/api/openapi.py +1251 -0
- agentrun/toolset/client.py +102 -0
- agentrun/toolset/model.py +321 -0
- agentrun/toolset/toolset.py +271 -0
- agentrun/utils/__data_api_async_template.py +721 -0
- agentrun/utils/__init__.py +5 -0
- agentrun/utils/__resource_async_template.py +158 -0
- agentrun/utils/config.py +270 -0
- agentrun/utils/control_api.py +105 -0
- agentrun/utils/data_api.py +1121 -0
- agentrun/utils/exception.py +151 -0
- agentrun/utils/helper.py +108 -0
- agentrun/utils/log.py +77 -0
- agentrun/utils/model.py +168 -0
- agentrun/utils/resource.py +291 -0
- agentrun_inner_test-0.0.62.dist-info/METADATA +265 -0
- agentrun_inner_test-0.0.62.dist-info/RECORD +154 -0
- agentrun_inner_test-0.0.62.dist-info/WHEEL +5 -0
- agentrun_inner_test-0.0.62.dist-info/licenses/LICENSE +201 -0
- agentrun_inner_test-0.0.62.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
"""Agent Runtime 高层 API / Agent Runtime High-Level API
|
|
2
|
+
|
|
3
|
+
此模块定义 Agent Runtime 资源的高级API。
|
|
4
|
+
This module defines the high-level API for Agent Runtime resources.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import time # noqa: F401
|
|
8
|
+
from typing import Dict, List, Optional
|
|
9
|
+
|
|
10
|
+
from typing_extensions import Unpack
|
|
11
|
+
|
|
12
|
+
from agentrun.agent_runtime.api.data import AgentRuntimeDataAPI, InvokeArgs
|
|
13
|
+
from agentrun.utils.config import Config
|
|
14
|
+
from agentrun.utils.model import PageableInput
|
|
15
|
+
from agentrun.utils.resource import ResourceBase
|
|
16
|
+
|
|
17
|
+
from .endpoint import AgentRuntimeEndpoint
|
|
18
|
+
from .model import (
|
|
19
|
+
AgentRuntimeCreateInput,
|
|
20
|
+
AgentRuntimeEndpointCreateInput,
|
|
21
|
+
AgentRuntimeEndpointUpdateInput,
|
|
22
|
+
AgentRuntimeImmutableProps,
|
|
23
|
+
AgentRuntimeListInput,
|
|
24
|
+
AgentRuntimeMutableProps,
|
|
25
|
+
AgentRuntimeSystemProps,
|
|
26
|
+
AgentRuntimeUpdateInput,
|
|
27
|
+
AgentRuntimeVersion,
|
|
28
|
+
AgentRuntimeVersionListInput,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class AgentRuntime(
|
|
33
|
+
AgentRuntimeMutableProps,
|
|
34
|
+
AgentRuntimeImmutableProps,
|
|
35
|
+
AgentRuntimeSystemProps,
|
|
36
|
+
ResourceBase,
|
|
37
|
+
):
|
|
38
|
+
"""Agent Runtime 资源 / Agent Runtime Resource
|
|
39
|
+
|
|
40
|
+
提供 Agent Runtime 的完整生命周期管理,包括创建、删除、更新、查询,
|
|
41
|
+
以及端点和版本管理。
|
|
42
|
+
Provides complete lifecycle management for Agent Runtime, including create,
|
|
43
|
+
delete, update, query, and endpoint/version management.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def __get_client(cls):
|
|
48
|
+
"""获取客户端实例 / Get client instance
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
AgentRuntimeClient: 客户端实例 / Client instance
|
|
52
|
+
"""
|
|
53
|
+
from .client import AgentRuntimeClient
|
|
54
|
+
|
|
55
|
+
return AgentRuntimeClient()
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
async def create_async(
|
|
59
|
+
cls, input: AgentRuntimeCreateInput, config: Optional[Config] = None
|
|
60
|
+
):
|
|
61
|
+
"""异步创建 Agent Runtime / Create Agent Runtime asynchronously
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
input: Agent Runtime 创建配置 / Agent Runtime creation configuration
|
|
65
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
AgentRuntime: 创建的 Agent Runtime 对象 / Created Agent Runtime object
|
|
69
|
+
|
|
70
|
+
Raises:
|
|
71
|
+
ValueError: 配置参数错误 / Configuration parameter error
|
|
72
|
+
ResourceAlreadyExistError: 资源已存在 / Resource already exists
|
|
73
|
+
HTTPError: HTTP 请求错误 / HTTP request error
|
|
74
|
+
"""
|
|
75
|
+
return await cls.__get_client().create_async(input, config=config)
|
|
76
|
+
|
|
77
|
+
@classmethod
|
|
78
|
+
async def delete_by_id_async(cls, id: str, config: Optional[Config] = None):
|
|
79
|
+
"""根据 ID 异步删除 Agent Runtime / Delete Agent Runtime by ID asynchronously
|
|
80
|
+
|
|
81
|
+
此方法会先删除所有关联的端点,然后再删除 Agent Runtime。
|
|
82
|
+
This method will first delete all associated endpoints, then delete the Agent Runtime.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
id: Agent Runtime ID
|
|
86
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
AgentRuntime: 删除的 Agent Runtime 对象 / Deleted Agent Runtime object
|
|
90
|
+
|
|
91
|
+
Raises:
|
|
92
|
+
ResourceNotExistError: 资源不存在 / Resource does not exist
|
|
93
|
+
HTTPError: HTTP 请求错误 / HTTP request error
|
|
94
|
+
"""
|
|
95
|
+
cli = cls.__get_client()
|
|
96
|
+
|
|
97
|
+
# 删除所有的 endpoint / Delete all endpoints
|
|
98
|
+
endpoints = await cli.list_endpoints_async(id, config=config)
|
|
99
|
+
for endpoint in endpoints:
|
|
100
|
+
await endpoint.delete_async(config=config)
|
|
101
|
+
|
|
102
|
+
# 等待所有端点删除完成 / Wait for all endpoints to be deleted
|
|
103
|
+
while len(await cli.list_endpoints_async(id, config=config)) > 0:
|
|
104
|
+
import asyncio
|
|
105
|
+
|
|
106
|
+
await asyncio.sleep(1)
|
|
107
|
+
|
|
108
|
+
return await cli.delete_async(
|
|
109
|
+
id,
|
|
110
|
+
config=config,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
async def update_by_id_async(
|
|
115
|
+
cls,
|
|
116
|
+
id: str,
|
|
117
|
+
input: AgentRuntimeUpdateInput,
|
|
118
|
+
config: Optional[Config] = None,
|
|
119
|
+
):
|
|
120
|
+
"""根据 ID 异步更新 Agent Runtime / Update Agent Runtime by ID asynchronously
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
id: Agent Runtime ID
|
|
124
|
+
input: Agent Runtime 更新配置 / Agent Runtime update configuration
|
|
125
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
AgentRuntime: 更新后的 Agent Runtime 对象 / Updated Agent Runtime object
|
|
129
|
+
|
|
130
|
+
Raises:
|
|
131
|
+
ResourceNotExistError: 资源不存在 / Resource does not exist
|
|
132
|
+
HTTPError: HTTP 请求错误 / HTTP request error
|
|
133
|
+
"""
|
|
134
|
+
return await cls.__get_client().update_async(id, input, config=config)
|
|
135
|
+
|
|
136
|
+
@classmethod
|
|
137
|
+
async def get_by_id_async(cls, id: str, config: Optional[Config] = None):
|
|
138
|
+
"""根据 ID 异步获取 Agent Runtime / Get Agent Runtime by ID asynchronously
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
id: Agent Runtime ID
|
|
142
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
AgentRuntime: Agent Runtime 对象 / Agent Runtime object
|
|
146
|
+
|
|
147
|
+
Raises:
|
|
148
|
+
ResourceNotExistError: 资源不存在 / Resource does not exist
|
|
149
|
+
HTTPError: HTTP 请求错误 / HTTP request error
|
|
150
|
+
"""
|
|
151
|
+
return await cls.__get_client().get_async(id, config=config)
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
async def _list_page_async(
|
|
155
|
+
cls, page_input: PageableInput, config: Config | None = None, **kwargs
|
|
156
|
+
):
|
|
157
|
+
return await cls.__get_client().list_async(
|
|
158
|
+
input=AgentRuntimeListInput(
|
|
159
|
+
**kwargs,
|
|
160
|
+
**page_input.model_dump(),
|
|
161
|
+
),
|
|
162
|
+
config=config,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
@classmethod
|
|
166
|
+
async def list_all_async(
|
|
167
|
+
cls,
|
|
168
|
+
*,
|
|
169
|
+
agent_runtime_name: Optional[str] = None,
|
|
170
|
+
tags: Optional[str] = None,
|
|
171
|
+
search_mode: Optional[str] = None,
|
|
172
|
+
config: Optional[Config] = None,
|
|
173
|
+
) -> List["AgentRuntime"]:
|
|
174
|
+
return await cls._list_all_async(
|
|
175
|
+
lambda ar: ar.agent_runtime_id or "",
|
|
176
|
+
config=config,
|
|
177
|
+
agent_runtime_name=agent_runtime_name,
|
|
178
|
+
tags=tags,
|
|
179
|
+
search_mode=search_mode,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
@classmethod
|
|
183
|
+
async def list_async(cls, config: Optional[Config] = None):
|
|
184
|
+
"""异步列出所有 Agent Runtimes / List all Agent Runtimes asynchronously
|
|
185
|
+
|
|
186
|
+
此方法会自动分页获取所有 Agent Runtimes 并去重。
|
|
187
|
+
This method automatically paginates to get all Agent Runtimes and deduplicates them.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
List[AgentRuntime]: Agent Runtime 对象列表 / List of Agent Runtime objects
|
|
194
|
+
|
|
195
|
+
Raises:
|
|
196
|
+
HTTPError: HTTP 请求错误 / HTTP request error
|
|
197
|
+
"""
|
|
198
|
+
cli = cls.__get_client()
|
|
199
|
+
|
|
200
|
+
runtimes: List[AgentRuntime] = []
|
|
201
|
+
page = 1
|
|
202
|
+
page_size = 50
|
|
203
|
+
while True:
|
|
204
|
+
result = await cli.list_async(
|
|
205
|
+
AgentRuntimeListInput(
|
|
206
|
+
page_number=page,
|
|
207
|
+
page_size=page_size,
|
|
208
|
+
),
|
|
209
|
+
config=config,
|
|
210
|
+
)
|
|
211
|
+
page += 1
|
|
212
|
+
runtimes.extend(result) # type: ignore
|
|
213
|
+
if len(result) < page_size:
|
|
214
|
+
break
|
|
215
|
+
|
|
216
|
+
# 去重 / Deduplicate
|
|
217
|
+
runtime_id_set = set()
|
|
218
|
+
results: List[AgentRuntime] = []
|
|
219
|
+
for runtime in runtimes:
|
|
220
|
+
if runtime.agent_runtime_id not in runtime_id_set:
|
|
221
|
+
runtime_id_set.add(runtime.agent_runtime_id)
|
|
222
|
+
results.append(runtime)
|
|
223
|
+
|
|
224
|
+
return results
|
|
225
|
+
|
|
226
|
+
@classmethod
|
|
227
|
+
async def create_endpoint_by_id_async(
|
|
228
|
+
cls,
|
|
229
|
+
agent_runtime_id: str,
|
|
230
|
+
input: AgentRuntimeEndpointCreateInput,
|
|
231
|
+
config: Optional[Config] = None,
|
|
232
|
+
) -> AgentRuntimeEndpoint:
|
|
233
|
+
return await AgentRuntimeEndpoint.create_by_id_async(
|
|
234
|
+
agent_runtime_id,
|
|
235
|
+
input,
|
|
236
|
+
config=config,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
@classmethod
|
|
240
|
+
async def delete_endpoint_by_id_async(
|
|
241
|
+
cls,
|
|
242
|
+
agent_runtime_id: str,
|
|
243
|
+
endpoint_id: str,
|
|
244
|
+
config: Optional[Config] = None,
|
|
245
|
+
) -> AgentRuntimeEndpoint:
|
|
246
|
+
return await AgentRuntimeEndpoint.delete_by_id_async(
|
|
247
|
+
agent_runtime_id,
|
|
248
|
+
endpoint_id,
|
|
249
|
+
config=config,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
@classmethod
|
|
253
|
+
async def update_endpoint_by_id_async(
|
|
254
|
+
cls,
|
|
255
|
+
agent_runtime_id: str,
|
|
256
|
+
endpoint_id: str,
|
|
257
|
+
input: AgentRuntimeEndpointUpdateInput,
|
|
258
|
+
config: Optional[Config] = None,
|
|
259
|
+
) -> AgentRuntimeEndpoint:
|
|
260
|
+
return await AgentRuntimeEndpoint.update_by_id_async(
|
|
261
|
+
agent_runtime_id,
|
|
262
|
+
endpoint_id,
|
|
263
|
+
input,
|
|
264
|
+
config=config,
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
@classmethod
|
|
268
|
+
async def get_endpoint_by_id_async(
|
|
269
|
+
cls,
|
|
270
|
+
agent_runtime_id: str,
|
|
271
|
+
endpoint_id: str,
|
|
272
|
+
config: Optional[Config] = None,
|
|
273
|
+
) -> AgentRuntimeEndpoint:
|
|
274
|
+
return await AgentRuntimeEndpoint.get_by_id_async(
|
|
275
|
+
agent_runtime_id,
|
|
276
|
+
endpoint_id,
|
|
277
|
+
config=config,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
@classmethod
|
|
281
|
+
async def list_endpoints_by_id_async(
|
|
282
|
+
cls, agent_runtime_id: str, config: Optional[Config] = None
|
|
283
|
+
) -> List[AgentRuntimeEndpoint]:
|
|
284
|
+
return await AgentRuntimeEndpoint.list_by_id_async(
|
|
285
|
+
agent_runtime_id,
|
|
286
|
+
config=config,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
@classmethod
|
|
290
|
+
async def list_versions_by_id_async(
|
|
291
|
+
cls,
|
|
292
|
+
agent_runtime_id: str,
|
|
293
|
+
config: Optional[Config] = None,
|
|
294
|
+
):
|
|
295
|
+
cli = cls.__get_client()
|
|
296
|
+
|
|
297
|
+
versions: List[AgentRuntimeVersion] = []
|
|
298
|
+
page = 1
|
|
299
|
+
page_size = 50
|
|
300
|
+
while True:
|
|
301
|
+
result = await cli.list_versions_async(
|
|
302
|
+
agent_runtime_id,
|
|
303
|
+
AgentRuntimeVersionListInput(
|
|
304
|
+
page_number=page,
|
|
305
|
+
page_size=page_size,
|
|
306
|
+
),
|
|
307
|
+
config=config,
|
|
308
|
+
)
|
|
309
|
+
page += 1
|
|
310
|
+
versions.extend(result)
|
|
311
|
+
if len(result) < page_size:
|
|
312
|
+
break
|
|
313
|
+
|
|
314
|
+
version_id_set = set()
|
|
315
|
+
results: List[AgentRuntimeVersion] = []
|
|
316
|
+
for version in versions:
|
|
317
|
+
if version.agent_runtime_version not in version_id_set:
|
|
318
|
+
version_id_set.add(version.agent_runtime_version)
|
|
319
|
+
results.append(version)
|
|
320
|
+
|
|
321
|
+
return results
|
|
322
|
+
|
|
323
|
+
async def delete_async(self, config: Optional[Config] = None):
|
|
324
|
+
if self.agent_runtime_id is None:
|
|
325
|
+
raise ValueError(
|
|
326
|
+
"agent_runtime_id is required to delete an Agent Runtime"
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
result = await self.delete_by_id_async(
|
|
330
|
+
self.agent_runtime_id, config=config
|
|
331
|
+
)
|
|
332
|
+
self.update_self(result)
|
|
333
|
+
return self
|
|
334
|
+
|
|
335
|
+
async def update_async(
|
|
336
|
+
self, input: AgentRuntimeUpdateInput, config: Optional[Config] = None
|
|
337
|
+
):
|
|
338
|
+
if self.agent_runtime_id is None:
|
|
339
|
+
raise ValueError(
|
|
340
|
+
"agent_runtime_id is required to delete an Agent Runtime"
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
result = await self.update_by_id_async(
|
|
344
|
+
self.agent_runtime_id, input=input, config=config
|
|
345
|
+
)
|
|
346
|
+
self.update_self(result)
|
|
347
|
+
return self
|
|
348
|
+
|
|
349
|
+
async def get_async(self, config: Optional[Config] = None):
|
|
350
|
+
if self.agent_runtime_id is None:
|
|
351
|
+
raise ValueError(
|
|
352
|
+
"agent_runtime_id is required to get an Agent Runtime"
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
result = await self.get_by_id_async(
|
|
356
|
+
self.agent_runtime_id, config=config
|
|
357
|
+
)
|
|
358
|
+
self.update_self(result)
|
|
359
|
+
return self
|
|
360
|
+
|
|
361
|
+
async def refresh_async(self, config: Optional[Config] = None):
|
|
362
|
+
return await self.get_async(config=config)
|
|
363
|
+
|
|
364
|
+
async def create_endpoint_async(
|
|
365
|
+
self,
|
|
366
|
+
input: AgentRuntimeEndpointCreateInput,
|
|
367
|
+
config: Optional[Config] = None,
|
|
368
|
+
):
|
|
369
|
+
if self.agent_runtime_id is None:
|
|
370
|
+
raise ValueError(
|
|
371
|
+
"agent_runtime_id is required to create an Agent Runtime"
|
|
372
|
+
" Endpoint"
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
return await self.create_endpoint_by_id_async(
|
|
376
|
+
self.agent_runtime_id, input=input, config=config
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
async def delete_endpoint_async(
|
|
380
|
+
self,
|
|
381
|
+
endpoint_id: str,
|
|
382
|
+
config: Optional[Config] = None,
|
|
383
|
+
):
|
|
384
|
+
if self.agent_runtime_id is None:
|
|
385
|
+
raise ValueError(
|
|
386
|
+
"agent_runtime_id is required to delete an Agent Runtime"
|
|
387
|
+
" Endpoint"
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
return await self.delete_endpoint_by_id_async(
|
|
391
|
+
self.agent_runtime_id, endpoint_id, config=config
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
async def update_endpoint_async(
|
|
395
|
+
self,
|
|
396
|
+
endpoint_id: str,
|
|
397
|
+
endpoint: AgentRuntimeEndpointUpdateInput,
|
|
398
|
+
config: Optional[Config] = None,
|
|
399
|
+
) -> AgentRuntimeEndpoint:
|
|
400
|
+
if self.agent_runtime_id is None:
|
|
401
|
+
raise ValueError(
|
|
402
|
+
"agent_runtime_id is required to update an Agent Runtime"
|
|
403
|
+
" Endpoint"
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
return await self.update_endpoint_by_id_async(
|
|
407
|
+
self.agent_runtime_id,
|
|
408
|
+
endpoint_id,
|
|
409
|
+
endpoint,
|
|
410
|
+
config=config,
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
async def get_endpoint_async(
|
|
414
|
+
self,
|
|
415
|
+
endpoint_id: str,
|
|
416
|
+
config: Optional[Config] = None,
|
|
417
|
+
) -> AgentRuntimeEndpoint:
|
|
418
|
+
if self.agent_runtime_id is None:
|
|
419
|
+
raise ValueError(
|
|
420
|
+
"agent_runtime_id is required to get an Agent Runtime Endpoint"
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
return await self.get_endpoint_by_id_async(
|
|
424
|
+
self.agent_runtime_id,
|
|
425
|
+
endpoint_id,
|
|
426
|
+
config=config,
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
async def list_endpoints_async(
|
|
430
|
+
self,
|
|
431
|
+
config: Optional[Config] = None,
|
|
432
|
+
) -> List[AgentRuntimeEndpoint]:
|
|
433
|
+
if self.agent_runtime_id is None:
|
|
434
|
+
raise ValueError(
|
|
435
|
+
"agent_runtime_id is required to list Agent Runtime Endpoints"
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
return await self.list_endpoints_by_id_async(
|
|
439
|
+
self.agent_runtime_id,
|
|
440
|
+
config=config,
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
async def list_versions_async(
|
|
444
|
+
self,
|
|
445
|
+
config: Optional[Config] = None,
|
|
446
|
+
) -> List[AgentRuntimeVersion]:
|
|
447
|
+
if self.agent_runtime_id is None:
|
|
448
|
+
raise ValueError(
|
|
449
|
+
"agent_runtime_id is required to list Agent Runtime Versions"
|
|
450
|
+
)
|
|
451
|
+
|
|
452
|
+
return await self.list_versions_by_id_async(
|
|
453
|
+
self.agent_runtime_id,
|
|
454
|
+
config=config,
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
async def invoke_openai_async(
|
|
458
|
+
self,
|
|
459
|
+
agent_runtime_endpoint_name: str = "Default",
|
|
460
|
+
**kwargs: Unpack[InvokeArgs],
|
|
461
|
+
):
|
|
462
|
+
cfg = Config.with_configs(self._config, kwargs.get("config"))
|
|
463
|
+
kwargs["config"] = cfg
|
|
464
|
+
|
|
465
|
+
if not self.__data_api:
|
|
466
|
+
self.__data_api: Dict[str, AgentRuntimeDataAPI] = {}
|
|
467
|
+
|
|
468
|
+
if self.__data_api[agent_runtime_endpoint_name] is None:
|
|
469
|
+
self.__data_api[agent_runtime_endpoint_name] = AgentRuntimeDataAPI(
|
|
470
|
+
agent_runtime_name=self.agent_runtime_name or "",
|
|
471
|
+
agent_runtime_endpoint_name=agent_runtime_endpoint_name or "",
|
|
472
|
+
config=cfg,
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
return await self.__data_api[
|
|
476
|
+
agent_runtime_endpoint_name
|
|
477
|
+
].invoke_openai_async(**kwargs)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Iterable, Optional, TypedDict
|
|
2
|
+
|
|
3
|
+
from openai.types.chat import ChatCompletionMessageParam
|
|
4
|
+
from typing_extensions import Required, Unpack
|
|
5
|
+
|
|
6
|
+
from agentrun.utils.config import Config
|
|
7
|
+
from agentrun.utils.data_api import DataAPI, ResourceType
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class InvokeArgs(TypedDict):
|
|
11
|
+
messages: Required[Iterable[ChatCompletionMessageParam]]
|
|
12
|
+
stream: Required[bool]
|
|
13
|
+
config: Optional[Config]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AgentRuntimeDataAPI(DataAPI):
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
agent_runtime_name: str,
|
|
21
|
+
agent_runtime_endpoint_name: str = "Default",
|
|
22
|
+
config: Optional[Config] = None,
|
|
23
|
+
):
|
|
24
|
+
super().__init__(
|
|
25
|
+
resource_name=agent_runtime_name,
|
|
26
|
+
resource_type=ResourceType.Runtime,
|
|
27
|
+
namespace=f"agent-runtimes/{agent_runtime_name}/endpoints/{agent_runtime_endpoint_name}/invocations",
|
|
28
|
+
config=config,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
async def invoke_openai_async(
|
|
32
|
+
self,
|
|
33
|
+
**kwargs: Unpack[InvokeArgs],
|
|
34
|
+
):
|
|
35
|
+
messages = kwargs.get("messages", [])
|
|
36
|
+
stream = kwargs.get("stream", False)
|
|
37
|
+
config = kwargs.get("config", None)
|
|
38
|
+
|
|
39
|
+
cfg = Config.with_configs(self.config, config)
|
|
40
|
+
api_base = self.with_path("openai/v1")
|
|
41
|
+
_, headers, _ = self.auth(headers=cfg.get_headers())
|
|
42
|
+
|
|
43
|
+
from httpx import AsyncClient
|
|
44
|
+
from openai import AsyncOpenAI
|
|
45
|
+
|
|
46
|
+
client = AsyncOpenAI(
|
|
47
|
+
api_key="",
|
|
48
|
+
base_url=api_base,
|
|
49
|
+
http_client=AsyncClient(headers=headers),
|
|
50
|
+
)
|
|
51
|
+
timeout = cfg.get_timeout()
|
|
52
|
+
|
|
53
|
+
return client.chat.completions.create(
|
|
54
|
+
model=self.resource_name,
|
|
55
|
+
messages=messages,
|
|
56
|
+
timeout=timeout,
|
|
57
|
+
stream=stream,
|
|
58
|
+
)
|