agentscope-runtime 0.1.5b1__py3-none-any.whl → 0.2.0b1__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.
- agentscope_runtime/common/__init__.py +0 -0
- agentscope_runtime/common/collections/in_memory_mapping.py +27 -0
- agentscope_runtime/common/collections/redis_mapping.py +42 -0
- agentscope_runtime/common/container_clients/__init__.py +0 -0
- agentscope_runtime/common/container_clients/agentrun_client.py +1098 -0
- agentscope_runtime/common/container_clients/docker_client.py +250 -0
- agentscope_runtime/engine/__init__.py +12 -0
- agentscope_runtime/engine/agents/agentscope_agent.py +488 -0
- agentscope_runtime/engine/agents/agno_agent.py +19 -18
- agentscope_runtime/engine/agents/autogen_agent.py +13 -8
- agentscope_runtime/engine/agents/utils.py +53 -0
- agentscope_runtime/engine/app/__init__.py +6 -0
- agentscope_runtime/engine/app/agent_app.py +239 -0
- agentscope_runtime/engine/app/base_app.py +181 -0
- agentscope_runtime/engine/app/celery_mixin.py +92 -0
- agentscope_runtime/engine/deployers/base.py +1 -0
- agentscope_runtime/engine/deployers/cli_fc_deploy.py +72 -12
- agentscope_runtime/engine/deployers/kubernetes_deployer.py +12 -5
- agentscope_runtime/engine/deployers/local_deployer.py +61 -3
- agentscope_runtime/engine/deployers/modelstudio_deployer.py +77 -27
- agentscope_runtime/engine/deployers/utils/docker_image_utils/docker_image_builder.py +3 -3
- agentscope_runtime/engine/deployers/utils/docker_image_utils/runner_image_factory.py +9 -0
- agentscope_runtime/engine/deployers/utils/package_project_utils.py +234 -3
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py +567 -7
- agentscope_runtime/engine/deployers/utils/service_utils/standalone_main.py.j2 +211 -0
- agentscope_runtime/engine/deployers/utils/wheel_packager.py +1 -1
- agentscope_runtime/engine/helpers/helper.py +60 -41
- agentscope_runtime/engine/runner.py +35 -24
- agentscope_runtime/engine/schemas/agent_schemas.py +42 -0
- agentscope_runtime/engine/schemas/modelstudio_llm.py +14 -14
- agentscope_runtime/engine/services/sandbox_service.py +62 -70
- agentscope_runtime/engine/services/tablestore_memory_service.py +304 -0
- agentscope_runtime/engine/services/tablestore_rag_service.py +143 -0
- agentscope_runtime/engine/services/tablestore_session_history_service.py +293 -0
- agentscope_runtime/engine/services/utils/__init__.py +0 -0
- agentscope_runtime/engine/services/utils/tablestore_service_utils.py +352 -0
- agentscope_runtime/engine/tracing/__init__.py +9 -3
- agentscope_runtime/engine/tracing/asyncio_util.py +24 -0
- agentscope_runtime/engine/tracing/base.py +66 -34
- agentscope_runtime/engine/tracing/local_logging_handler.py +45 -31
- agentscope_runtime/engine/tracing/message_util.py +528 -0
- agentscope_runtime/engine/tracing/tracing_metric.py +20 -8
- agentscope_runtime/engine/tracing/tracing_util.py +130 -0
- agentscope_runtime/engine/tracing/wrapper.py +794 -169
- agentscope_runtime/sandbox/__init__.py +2 -0
- agentscope_runtime/sandbox/box/base/__init__.py +4 -0
- agentscope_runtime/sandbox/box/base/base_sandbox.py +6 -4
- agentscope_runtime/sandbox/box/browser/__init__.py +4 -0
- agentscope_runtime/sandbox/box/browser/browser_sandbox.py +10 -14
- agentscope_runtime/sandbox/box/dummy/__init__.py +4 -0
- agentscope_runtime/sandbox/box/dummy/dummy_sandbox.py +2 -1
- agentscope_runtime/sandbox/box/filesystem/__init__.py +4 -0
- agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +10 -7
- agentscope_runtime/sandbox/box/gui/__init__.py +4 -0
- agentscope_runtime/sandbox/box/gui/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/gui/gui_sandbox.py +81 -0
- agentscope_runtime/sandbox/box/sandbox.py +5 -2
- agentscope_runtime/sandbox/box/shared/routers/generic.py +20 -1
- agentscope_runtime/sandbox/box/training_box/__init__.py +4 -0
- agentscope_runtime/sandbox/box/training_box/training_box.py +10 -15
- agentscope_runtime/sandbox/build.py +143 -58
- agentscope_runtime/sandbox/client/http_client.py +87 -59
- agentscope_runtime/sandbox/client/training_client.py +0 -1
- agentscope_runtime/sandbox/constant.py +27 -1
- agentscope_runtime/sandbox/custom/custom_sandbox.py +7 -6
- agentscope_runtime/sandbox/custom/example.py +4 -3
- agentscope_runtime/sandbox/enums.py +1 -0
- agentscope_runtime/sandbox/manager/sandbox_manager.py +212 -106
- agentscope_runtime/sandbox/manager/server/app.py +82 -14
- agentscope_runtime/sandbox/manager/server/config.py +50 -3
- agentscope_runtime/sandbox/model/container.py +12 -23
- agentscope_runtime/sandbox/model/manager_config.py +93 -5
- agentscope_runtime/sandbox/registry.py +1 -1
- agentscope_runtime/sandbox/tools/gui/__init__.py +7 -0
- agentscope_runtime/sandbox/tools/gui/tool.py +77 -0
- agentscope_runtime/sandbox/tools/mcp_tool.py +6 -2
- agentscope_runtime/sandbox/tools/tool.py +4 -0
- agentscope_runtime/sandbox/utils.py +124 -0
- agentscope_runtime/version.py +1 -1
- {agentscope_runtime-0.1.5b1.dist-info → agentscope_runtime-0.2.0b1.dist-info}/METADATA +209 -101
- {agentscope_runtime-0.1.5b1.dist-info → agentscope_runtime-0.2.0b1.dist-info}/RECORD +95 -79
- agentscope_runtime/engine/agents/agentscope_agent/__init__.py +0 -6
- agentscope_runtime/engine/agents/agentscope_agent/agent.py +0 -401
- agentscope_runtime/engine/agents/agentscope_agent/hooks.py +0 -169
- agentscope_runtime/engine/agents/llm_agent.py +0 -51
- agentscope_runtime/engine/llms/__init__.py +0 -3
- agentscope_runtime/engine/llms/base_llm.py +0 -60
- agentscope_runtime/engine/llms/qwen_llm.py +0 -47
- agentscope_runtime/sandbox/manager/collections/in_memory_mapping.py +0 -22
- agentscope_runtime/sandbox/manager/collections/redis_mapping.py +0 -26
- agentscope_runtime/sandbox/manager/container_clients/__init__.py +0 -10
- agentscope_runtime/sandbox/manager/container_clients/docker_client.py +0 -422
- /agentscope_runtime/{sandbox/manager → common}/collections/__init__.py +0 -0
- /agentscope_runtime/{sandbox/manager → common}/collections/base_mapping.py +0 -0
- /agentscope_runtime/{sandbox/manager → common}/collections/base_queue.py +0 -0
- /agentscope_runtime/{sandbox/manager → common}/collections/base_set.py +0 -0
- /agentscope_runtime/{sandbox/manager → common}/collections/in_memory_queue.py +0 -0
- /agentscope_runtime/{sandbox/manager → common}/collections/in_memory_set.py +0 -0
- /agentscope_runtime/{sandbox/manager → common}/collections/redis_queue.py +0 -0
- /agentscope_runtime/{sandbox/manager → common}/collections/redis_set.py +0 -0
- /agentscope_runtime/{sandbox/manager → common}/container_clients/base_client.py +0 -0
- /agentscope_runtime/{sandbox/manager → common}/container_clients/kubernetes_client.py +0 -0
- {agentscope_runtime-0.1.5b1.dist-info → agentscope_runtime-0.2.0b1.dist-info}/WHEEL +0 -0
- {agentscope_runtime-0.1.5b1.dist-info → agentscope_runtime-0.2.0b1.dist-info}/entry_points.txt +0 -0
- {agentscope_runtime-0.1.5b1.dist-info → agentscope_runtime-0.2.0b1.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-0.1.5b1.dist-info → agentscope_runtime-0.2.0b1.dist-info}/top_level.txt +0 -0
|
@@ -6,10 +6,6 @@ from typing import Optional, Dict, List, Union, Any
|
|
|
6
6
|
|
|
7
7
|
from pydantic import BaseModel, Field
|
|
8
8
|
|
|
9
|
-
from agentscope_runtime.engine.runner import Runner
|
|
10
|
-
from agentscope_runtime.sandbox.manager.container_clients import (
|
|
11
|
-
KubernetesClient,
|
|
12
|
-
)
|
|
13
9
|
from .adapter.protocol_adapter import ProtocolAdapter
|
|
14
10
|
from .base import DeployManager
|
|
15
11
|
from .utils.docker_image_utils import (
|
|
@@ -19,6 +15,10 @@ from .utils.docker_image_utils import (
|
|
|
19
15
|
from .utils.service_utils import (
|
|
20
16
|
ServicesConfig,
|
|
21
17
|
)
|
|
18
|
+
from ..runner import Runner
|
|
19
|
+
from ...common.container_clients.kubernetes_client import (
|
|
20
|
+
KubernetesClient,
|
|
21
|
+
)
|
|
22
22
|
|
|
23
23
|
logger = logging.getLogger(__name__)
|
|
24
24
|
|
|
@@ -77,6 +77,7 @@ class KubernetesDeployManager(DeployManager):
|
|
|
77
77
|
endpoint_path: str = "/process",
|
|
78
78
|
stream: bool = True,
|
|
79
79
|
services_config: Optional[Union[ServicesConfig, dict]] = None,
|
|
80
|
+
custom_endpoints: Optional[List[Dict]] = None,
|
|
80
81
|
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
81
82
|
requirements: Optional[Union[str, List[str]]] = None,
|
|
82
83
|
extra_packages: Optional[List[str]] = None,
|
|
@@ -100,6 +101,7 @@ class KubernetesDeployManager(DeployManager):
|
|
|
100
101
|
endpoint_path: API endpoint path
|
|
101
102
|
stream: Enable streaming responses
|
|
102
103
|
services_config: Services configuration for context manager
|
|
104
|
+
custom_endpoints: Custom endpoints from agent app
|
|
103
105
|
protocol_adapters: protocol adapters
|
|
104
106
|
requirements: PyPI dependencies (following _agent_engines.py
|
|
105
107
|
pattern)
|
|
@@ -156,6 +158,7 @@ class KubernetesDeployManager(DeployManager):
|
|
|
156
158
|
port=port,
|
|
157
159
|
services_config=services_config, # type: ignore[arg-type]
|
|
158
160
|
protocol_adapters=protocol_adapters,
|
|
161
|
+
custom_endpoints=custom_endpoints,
|
|
159
162
|
**kwargs,
|
|
160
163
|
)
|
|
161
164
|
if not built_image_name:
|
|
@@ -205,7 +208,11 @@ class KubernetesDeployManager(DeployManager):
|
|
|
205
208
|
f"{resource_name}, {traceback.format_exc()}",
|
|
206
209
|
)
|
|
207
210
|
|
|
208
|
-
|
|
211
|
+
if ports:
|
|
212
|
+
url = f"http://{ip}:{ports[0]}"
|
|
213
|
+
else:
|
|
214
|
+
url = f"http://{ip}:8080"
|
|
215
|
+
|
|
209
216
|
logger.info(f"Deployment {deploy_id} successful: {url}")
|
|
210
217
|
|
|
211
218
|
self._deployed_resources[deploy_id] = {
|
|
@@ -29,7 +29,8 @@ class LocalDeployManager(DeployManager):
|
|
|
29
29
|
self,
|
|
30
30
|
host: str = "127.0.0.1",
|
|
31
31
|
port: int = 8000,
|
|
32
|
-
shutdown_timeout: int =
|
|
32
|
+
shutdown_timeout: int = 30,
|
|
33
|
+
startup_timeout: int = 30,
|
|
33
34
|
logger: Optional[logging.Logger] = None,
|
|
34
35
|
):
|
|
35
36
|
"""Initialize LocalDeployManager.
|
|
@@ -44,6 +45,7 @@ class LocalDeployManager(DeployManager):
|
|
|
44
45
|
self.host = host
|
|
45
46
|
self.port = port
|
|
46
47
|
self._shutdown_timeout = shutdown_timeout
|
|
48
|
+
self._startup_timeout = startup_timeout
|
|
47
49
|
self._logger = logger or logging.getLogger(__name__)
|
|
48
50
|
|
|
49
51
|
# State management
|
|
@@ -66,6 +68,7 @@ class LocalDeployManager(DeployManager):
|
|
|
66
68
|
|
|
67
69
|
async def deploy(
|
|
68
70
|
self,
|
|
71
|
+
app=None,
|
|
69
72
|
runner: Optional[Any] = None,
|
|
70
73
|
endpoint_path: str = "/process",
|
|
71
74
|
request_model: Optional[Type] = None,
|
|
@@ -75,7 +78,11 @@ class LocalDeployManager(DeployManager):
|
|
|
75
78
|
after_finish: Optional[Callable] = None,
|
|
76
79
|
mode: DeploymentMode = DeploymentMode.DAEMON_THREAD,
|
|
77
80
|
services_config: Optional[ServicesConfig] = None,
|
|
81
|
+
custom_endpoints: Optional[List[Dict]] = None,
|
|
78
82
|
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
83
|
+
broker_url: Optional[str] = None,
|
|
84
|
+
backend_url: Optional[str] = None,
|
|
85
|
+
enable_embedded_worker: bool = False,
|
|
79
86
|
**kwargs: Any,
|
|
80
87
|
) -> Dict[str, str]:
|
|
81
88
|
"""Deploy using unified FastAPI architecture.
|
|
@@ -90,7 +97,12 @@ class LocalDeployManager(DeployManager):
|
|
|
90
97
|
after_finish: Callback function called after server finishes
|
|
91
98
|
mode: Deployment mode
|
|
92
99
|
services_config: Services configuration
|
|
100
|
+
custom_endpoints: Custom endpoints from agent app
|
|
93
101
|
protocol_adapters: Protocol adapters
|
|
102
|
+
broker_url: Celery broker URL for background task processing
|
|
103
|
+
backend_url: Celery backend URL for result storage
|
|
104
|
+
enable_embedded_worker: Whether to run Celery worker
|
|
105
|
+
embedded in the app
|
|
94
106
|
**kwargs: Additional keyword arguments
|
|
95
107
|
|
|
96
108
|
Returns:
|
|
@@ -102,6 +114,19 @@ class LocalDeployManager(DeployManager):
|
|
|
102
114
|
if self.is_running:
|
|
103
115
|
raise RuntimeError("Service is already running")
|
|
104
116
|
|
|
117
|
+
self._app = app
|
|
118
|
+
if self._app is not None:
|
|
119
|
+
runner = self._app._runner
|
|
120
|
+
endpoint_path = self._app.endpoint_path
|
|
121
|
+
response_type = self._app.response_type
|
|
122
|
+
stream = self._app.stream
|
|
123
|
+
request_model = self._app.request_model
|
|
124
|
+
before_start = self._app.before_start
|
|
125
|
+
after_finish = self._app.after_finish
|
|
126
|
+
backend_url = self._app.backend_url
|
|
127
|
+
broker_url = self._app.broker_url
|
|
128
|
+
custom_endpoints = self._app.custom_endpoints
|
|
129
|
+
protocol_adapters = self._app.protocol_adapters
|
|
105
130
|
try:
|
|
106
131
|
if mode == DeploymentMode.DAEMON_THREAD:
|
|
107
132
|
return await self._deploy_daemon_thread(
|
|
@@ -113,7 +138,11 @@ class LocalDeployManager(DeployManager):
|
|
|
113
138
|
before_start=before_start,
|
|
114
139
|
after_finish=after_finish,
|
|
115
140
|
services_config=services_config,
|
|
141
|
+
custom_endpoints=custom_endpoints,
|
|
116
142
|
protocol_adapters=protocol_adapters,
|
|
143
|
+
broker_url=broker_url,
|
|
144
|
+
backend_url=backend_url,
|
|
145
|
+
enable_embedded_worker=enable_embedded_worker,
|
|
117
146
|
**kwargs,
|
|
118
147
|
)
|
|
119
148
|
elif mode == DeploymentMode.DETACHED_PROCESS:
|
|
@@ -126,6 +155,7 @@ class LocalDeployManager(DeployManager):
|
|
|
126
155
|
before_start=before_start,
|
|
127
156
|
after_finish=after_finish,
|
|
128
157
|
services_config=services_config,
|
|
158
|
+
custom_endpoints=custom_endpoints,
|
|
129
159
|
protocol_adapters=protocol_adapters,
|
|
130
160
|
**kwargs,
|
|
131
161
|
)
|
|
@@ -143,16 +173,22 @@ class LocalDeployManager(DeployManager):
|
|
|
143
173
|
self,
|
|
144
174
|
runner: Optional[Any] = None,
|
|
145
175
|
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
176
|
+
broker_url: Optional[str] = None,
|
|
177
|
+
backend_url: Optional[str] = None,
|
|
178
|
+
enable_embedded_worker: bool = False,
|
|
146
179
|
**kwargs,
|
|
147
180
|
) -> Dict[str, str]:
|
|
148
181
|
"""Deploy in daemon thread mode."""
|
|
149
182
|
self._logger.info("Deploying FastAPI service in daemon thread mode...")
|
|
150
183
|
|
|
151
|
-
# Create FastAPI app using factory
|
|
184
|
+
# Create FastAPI app using factory with Celery support
|
|
152
185
|
app = FastAPIAppFactory.create_app(
|
|
153
186
|
runner=runner,
|
|
154
187
|
mode=DeploymentMode.DAEMON_THREAD,
|
|
155
188
|
protocol_adapters=protocol_adapters,
|
|
189
|
+
broker_url=broker_url,
|
|
190
|
+
backend_url=backend_url,
|
|
191
|
+
enable_embedded_worker=enable_embedded_worker,
|
|
156
192
|
**kwargs,
|
|
157
193
|
)
|
|
158
194
|
|
|
@@ -174,7 +210,7 @@ class LocalDeployManager(DeployManager):
|
|
|
174
210
|
self._server_thread.start()
|
|
175
211
|
|
|
176
212
|
# Wait for server to start
|
|
177
|
-
await self._wait_for_server_ready()
|
|
213
|
+
await self._wait_for_server_ready(self._startup_timeout)
|
|
178
214
|
|
|
179
215
|
self.is_running = True
|
|
180
216
|
self.deploy_id = f"daemon_{self.host}_{self.port}"
|
|
@@ -207,6 +243,8 @@ class LocalDeployManager(DeployManager):
|
|
|
207
243
|
)
|
|
208
244
|
|
|
209
245
|
agent = runner._agent
|
|
246
|
+
if "agent" in kwargs:
|
|
247
|
+
kwargs.pop("agent")
|
|
210
248
|
|
|
211
249
|
# Create package project for detached deployment
|
|
212
250
|
project_dir = await self.create_detached_project(
|
|
@@ -272,6 +310,13 @@ class LocalDeployManager(DeployManager):
|
|
|
272
310
|
extra_packages: Optional[List[str]] = None,
|
|
273
311
|
services_config: Optional[ServicesConfig] = None,
|
|
274
312
|
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
313
|
+
custom_endpoints: Optional[
|
|
314
|
+
List[Dict]
|
|
315
|
+
] = None, # New parameter for custom endpoints
|
|
316
|
+
# Celery parameters
|
|
317
|
+
broker_url: Optional[str] = None,
|
|
318
|
+
backend_url: Optional[str] = None,
|
|
319
|
+
enable_embedded_worker: bool = False,
|
|
275
320
|
**kwargs, # pylint: disable=unused-argument
|
|
276
321
|
) -> str:
|
|
277
322
|
"""Create detached project using package_project method."""
|
|
@@ -288,6 +333,11 @@ class LocalDeployManager(DeployManager):
|
|
|
288
333
|
extra_packages=extra_packages,
|
|
289
334
|
protocol_adapters=protocol_adapters,
|
|
290
335
|
services_config=services_config,
|
|
336
|
+
custom_endpoints=custom_endpoints, # Add custom endpoints
|
|
337
|
+
# Celery configuration
|
|
338
|
+
broker_url=broker_url,
|
|
339
|
+
backend_url=backend_url,
|
|
340
|
+
enable_embedded_worker=enable_embedded_worker,
|
|
291
341
|
requirements=requirements
|
|
292
342
|
+ (
|
|
293
343
|
["redis"]
|
|
@@ -301,6 +351,14 @@ class LocalDeployManager(DeployManager):
|
|
|
301
351
|
if config
|
|
302
352
|
)
|
|
303
353
|
else []
|
|
354
|
+
)
|
|
355
|
+
+ (
|
|
356
|
+
[
|
|
357
|
+
"celery",
|
|
358
|
+
"redis",
|
|
359
|
+
] # Add Celery and Redis if Celery is configured
|
|
360
|
+
if broker_url or backend_url
|
|
361
|
+
else []
|
|
304
362
|
),
|
|
305
363
|
)
|
|
306
364
|
|
|
@@ -163,7 +163,24 @@ async def _oss_create_bucket_if_not_exists(client, bucket_name: str) -> None:
|
|
|
163
163
|
storage_class="IA",
|
|
164
164
|
),
|
|
165
165
|
)
|
|
166
|
-
|
|
166
|
+
try:
|
|
167
|
+
put_bucket_result = client.put_bucket(req)
|
|
168
|
+
logger.info(
|
|
169
|
+
f"put bucket status code: {put_bucket_result.status_code},"
|
|
170
|
+
f" request id: {put_bucket_result.request_id}",
|
|
171
|
+
)
|
|
172
|
+
except oss.exceptions.OperationError as e:
|
|
173
|
+
logger.error(
|
|
174
|
+
"OSS PutBucket failed: Http Status: %s, ErrorCode: %s, RequestId: %s, Message: %s",
|
|
175
|
+
getattr(e, "http_code", None),
|
|
176
|
+
getattr(e, "error_code", None),
|
|
177
|
+
getattr(e, "request_id", None),
|
|
178
|
+
getattr(e, "message", str(e)),
|
|
179
|
+
)
|
|
180
|
+
raise
|
|
181
|
+
except Exception as e:
|
|
182
|
+
logger.error("Unexpected put bucket failure: %s", e, exc_info=True)
|
|
183
|
+
raise
|
|
167
184
|
result = client.put_bucket_tags(
|
|
168
185
|
oss.PutBucketTagsRequest(
|
|
169
186
|
bucket=bucket_name,
|
|
@@ -184,16 +201,6 @@ async def _oss_create_bucket_if_not_exists(client, bucket_name: str) -> None:
|
|
|
184
201
|
)
|
|
185
202
|
|
|
186
203
|
|
|
187
|
-
def _create_bucket_name(prefix: str, base_name: str) -> str:
|
|
188
|
-
import re as _re
|
|
189
|
-
|
|
190
|
-
ts = time.strftime("%Y%m%d-%H%M%S", time.gmtime())
|
|
191
|
-
base = _re.sub(r"\s+", "-", base_name)
|
|
192
|
-
base = _re.sub(r"[^a-zA-Z0-9-]", "", base).lower().strip("-")
|
|
193
|
-
name = f"{prefix}-{base}-{ts}"
|
|
194
|
-
return name[:63]
|
|
195
|
-
|
|
196
|
-
|
|
197
204
|
async def _oss_put_and_presign(
|
|
198
205
|
client,
|
|
199
206
|
bucket_name: str,
|
|
@@ -220,6 +227,8 @@ async def _modelstudio_deploy(
|
|
|
220
227
|
file_url: str,
|
|
221
228
|
filename: str,
|
|
222
229
|
deploy_name: str,
|
|
230
|
+
agent_id: Optional[str] = None,
|
|
231
|
+
agent_desc: Optional[str] = None,
|
|
223
232
|
telemetry_enabled: bool = True,
|
|
224
233
|
) -> str:
|
|
225
234
|
cfg.ensure_valid()
|
|
@@ -230,6 +239,8 @@ async def _modelstudio_deploy(
|
|
|
230
239
|
config.endpoint = cfg.endpoint
|
|
231
240
|
client_modelstudio = ModelstudioClient(config)
|
|
232
241
|
req = ModelstudioTypes.HighCodeDeployRequest(
|
|
242
|
+
agent_desc=agent_desc,
|
|
243
|
+
agent_id=agent_id,
|
|
233
244
|
source_code_name=filename,
|
|
234
245
|
source_code_oss_url=file_url,
|
|
235
246
|
agent_name=deploy_name,
|
|
@@ -244,6 +255,10 @@ async def _modelstudio_deploy(
|
|
|
244
255
|
runtime,
|
|
245
256
|
)
|
|
246
257
|
|
|
258
|
+
# logger.info(json.dumps(resp.to_map(), indent=2, ensure_ascii=False))
|
|
259
|
+
request_id = resp.to_map()["headers"].get("x-acs-request-id")
|
|
260
|
+
logger.info("deploy request id: %s", request_id)
|
|
261
|
+
|
|
247
262
|
# Extract deploy identifier string from response
|
|
248
263
|
def _extract_deploy_identifier(response_obj) -> str:
|
|
249
264
|
try:
|
|
@@ -473,14 +488,17 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
473
488
|
self,
|
|
474
489
|
wheel_path: Path,
|
|
475
490
|
name: str,
|
|
491
|
+
agent_id: Optional[str] = None,
|
|
492
|
+
agent_desc: Optional[str] = None,
|
|
476
493
|
telemetry_enabled: bool = True,
|
|
477
|
-
) -> Tuple[str, str]:
|
|
494
|
+
) -> Tuple[str, str, str]:
|
|
478
495
|
logger.info("Uploading wheel to OSS and generating presigned URL")
|
|
479
496
|
client = _oss_get_client(self.oss_config)
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
)
|
|
497
|
+
|
|
498
|
+
bucket_suffix = (
|
|
499
|
+
os.getenv("MODELSTUDIO_WORKSPACE_ID", str(uuid.uuid4()))
|
|
500
|
+
).lower()
|
|
501
|
+
bucket_name = (f"tmp-code-deploy-" f"{bucket_suffix}")[:63]
|
|
484
502
|
await _oss_create_bucket_if_not_exists(client, bucket_name)
|
|
485
503
|
filename = wheel_path.name
|
|
486
504
|
with wheel_path.open("rb") as f:
|
|
@@ -494,6 +512,8 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
494
512
|
|
|
495
513
|
logger.info("Triggering Modelstudio Full-Code deploy for %s", name)
|
|
496
514
|
deploy_identifier = await _modelstudio_deploy(
|
|
515
|
+
agent_desc=agent_desc,
|
|
516
|
+
agent_id=agent_id,
|
|
497
517
|
cfg=self.modelstudio_config,
|
|
498
518
|
file_url=artifact_url,
|
|
499
519
|
filename=filename,
|
|
@@ -501,25 +521,24 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
501
521
|
telemetry_enabled=telemetry_enabled,
|
|
502
522
|
)
|
|
503
523
|
|
|
504
|
-
def _build_console_url(endpoint: str
|
|
524
|
+
def _build_console_url(endpoint: str) -> str:
|
|
505
525
|
# Map API endpoint to console domain (no fragment in base)
|
|
506
526
|
base = (
|
|
507
|
-
"https://pre-bailian.console.aliyun.com/?tab=app
|
|
527
|
+
"https://pre-bailian.console.aliyun.com/?tab=app#"
|
|
508
528
|
if ("bailian-pre" in endpoint or "pre" in endpoint)
|
|
509
|
-
else "https://bailian.console.aliyun.com/?tab=app"
|
|
529
|
+
else "https://bailian.console.aliyun.com/?tab=app#"
|
|
510
530
|
)
|
|
511
531
|
# Optional query can be appended if needed; keep path clean
|
|
512
|
-
return f"{base}/app-center
|
|
532
|
+
return f"{base}/app-center"
|
|
513
533
|
|
|
514
534
|
console_url = (
|
|
515
535
|
_build_console_url(
|
|
516
536
|
self.modelstudio_config.endpoint,
|
|
517
|
-
deploy_identifier,
|
|
518
537
|
)
|
|
519
538
|
if deploy_identifier
|
|
520
539
|
else ""
|
|
521
540
|
)
|
|
522
|
-
return artifact_url, console_url
|
|
541
|
+
return artifact_url, console_url, deploy_identifier
|
|
523
542
|
|
|
524
543
|
async def deploy(
|
|
525
544
|
self,
|
|
@@ -538,6 +557,11 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
538
557
|
skip_upload: bool = False,
|
|
539
558
|
telemetry_enabled: bool = True,
|
|
540
559
|
external_whl_path: Optional[str] = None,
|
|
560
|
+
agent_id: Optional[str] = None,
|
|
561
|
+
agent_desc: Optional[str] = None,
|
|
562
|
+
custom_endpoints: Optional[
|
|
563
|
+
List[Dict]
|
|
564
|
+
] = None, # New parameter for custom endpoints
|
|
541
565
|
**kwargs,
|
|
542
566
|
) -> Dict[str, str]:
|
|
543
567
|
"""
|
|
@@ -546,8 +570,12 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
546
570
|
Returns a dict containing deploy_id, wheel_path, artifact_url (if uploaded),
|
|
547
571
|
resource_name (deploy_name), and workspace_id.
|
|
548
572
|
"""
|
|
549
|
-
if not
|
|
550
|
-
|
|
573
|
+
if not agent_id:
|
|
574
|
+
if not runner and not project_dir and not external_whl_path:
|
|
575
|
+
raise ValueError(
|
|
576
|
+
"Either runner, project_dir, "
|
|
577
|
+
"or external_whl_path must be provided.",
|
|
578
|
+
)
|
|
551
579
|
|
|
552
580
|
# convert services_config to Model body
|
|
553
581
|
if services_config and isinstance(services_config, dict):
|
|
@@ -556,6 +584,8 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
556
584
|
try:
|
|
557
585
|
if runner:
|
|
558
586
|
agent = runner._agent
|
|
587
|
+
if "agent" in kwargs:
|
|
588
|
+
kwargs.pop("agent")
|
|
559
589
|
|
|
560
590
|
# Create package project for detached deployment
|
|
561
591
|
project_dir = await LocalDeployManager.create_detached_project(
|
|
@@ -563,14 +593,23 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
563
593
|
endpoint_path=endpoint_path,
|
|
564
594
|
services_config=services_config, # type: ignore[arg-type]
|
|
565
595
|
protocol_adapters=protocol_adapters,
|
|
596
|
+
custom_endpoints=custom_endpoints, # Pass custom endpoints
|
|
566
597
|
requirements=requirements,
|
|
567
598
|
extra_packages=extra_packages,
|
|
568
599
|
**kwargs,
|
|
569
600
|
)
|
|
570
|
-
|
|
601
|
+
if project_dir:
|
|
602
|
+
self._generate_env_file(project_dir, environment)
|
|
571
603
|
cmd = "python main.py"
|
|
572
604
|
deploy_name = deploy_name or default_deploy_name()
|
|
573
605
|
|
|
606
|
+
if agent_id:
|
|
607
|
+
if not external_whl_path:
|
|
608
|
+
raise FileNotFoundError(
|
|
609
|
+
"wheel file not found. "
|
|
610
|
+
"Please specify your .whl file path by "
|
|
611
|
+
"'--whl-path <whlpath>' in command line.",
|
|
612
|
+
)
|
|
574
613
|
# if whl exists then skip the project package method
|
|
575
614
|
if external_whl_path:
|
|
576
615
|
wheel_path = Path(external_whl_path).resolve()
|
|
@@ -579,6 +618,9 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
579
618
|
f"External wheel file not found: {wheel_path}",
|
|
580
619
|
)
|
|
581
620
|
name = deploy_name or default_deploy_name()
|
|
621
|
+
# 如果是更新agent,且没有传deploy_name, 则不更新名字
|
|
622
|
+
if agent_id and (deploy_name is None):
|
|
623
|
+
name = None
|
|
582
624
|
else:
|
|
583
625
|
(
|
|
584
626
|
wheel_path,
|
|
@@ -592,25 +634,33 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
592
634
|
|
|
593
635
|
artifact_url = ""
|
|
594
636
|
console_url = ""
|
|
637
|
+
deploy_identifier = ""
|
|
595
638
|
if not skip_upload:
|
|
596
639
|
# Only require cloud SDKs and credentials when performing upload/deploy
|
|
597
640
|
_assert_cloud_sdks_available()
|
|
598
641
|
self.oss_config.ensure_valid()
|
|
599
642
|
self.modelstudio_config.ensure_valid()
|
|
600
|
-
|
|
643
|
+
(
|
|
644
|
+
artifact_url,
|
|
645
|
+
console_url,
|
|
646
|
+
deploy_identifier,
|
|
647
|
+
) = await self._upload_and_deploy(
|
|
601
648
|
wheel_path,
|
|
602
649
|
name,
|
|
650
|
+
agent_id,
|
|
651
|
+
agent_desc,
|
|
603
652
|
telemetry_enabled,
|
|
604
653
|
)
|
|
605
654
|
|
|
606
655
|
result: Dict[str, str] = {
|
|
607
|
-
"deploy_id": self.deploy_id,
|
|
608
656
|
"wheel_path": str(wheel_path),
|
|
609
657
|
"artifact_url": artifact_url,
|
|
610
658
|
"resource_name": name,
|
|
611
659
|
"workspace_id": self.modelstudio_config.workspace_id or "",
|
|
612
660
|
"url": console_url,
|
|
613
661
|
}
|
|
662
|
+
if deploy_identifier:
|
|
663
|
+
result["deploy_id"] = deploy_identifier
|
|
614
664
|
|
|
615
665
|
return result
|
|
616
666
|
except Exception as e:
|
|
@@ -103,12 +103,12 @@ class DockerImageBuilder:
|
|
|
103
103
|
"""
|
|
104
104
|
if not os.path.exists(build_context):
|
|
105
105
|
raise ValueError(f"Build context does not exist: {build_context}")
|
|
106
|
-
|
|
107
106
|
config = config or BuildConfig()
|
|
108
107
|
full_image_name = self.get_full_name(image_name, image_tag)
|
|
109
108
|
|
|
110
|
-
if not source_updated:
|
|
111
|
-
|
|
109
|
+
# if not source_updated:
|
|
110
|
+
# return full_image_name
|
|
111
|
+
logger.info(f"Source Updated: {source_updated}")
|
|
112
112
|
|
|
113
113
|
# Prepare docker build command
|
|
114
114
|
build_cmd = ["docker", "build", "-t", full_image_name]
|
|
@@ -39,6 +39,9 @@ class RunnerImageConfig(BaseModel):
|
|
|
39
39
|
endpoint_path: str = "/process"
|
|
40
40
|
protocol_adapters: Optional[List] = None # New: protocol adapters
|
|
41
41
|
services_config: Optional[ServicesConfig] = None
|
|
42
|
+
custom_endpoints: Optional[
|
|
43
|
+
List[Dict]
|
|
44
|
+
] = None # New: custom endpoints configuration
|
|
42
45
|
|
|
43
46
|
# Docker configuration
|
|
44
47
|
base_image: str = "python:3.10-slim-bookworm"
|
|
@@ -184,6 +187,7 @@ class RunnerImageFactory:
|
|
|
184
187
|
endpoint_path=config.endpoint_path,
|
|
185
188
|
protocol_adapters=config.protocol_adapters,
|
|
186
189
|
services_config=config.services_config,
|
|
190
|
+
custom_endpoints=config.custom_endpoints,
|
|
187
191
|
),
|
|
188
192
|
dockerfile_path=dockerfile_path,
|
|
189
193
|
# caller_depth is no longer needed due to automatic
|
|
@@ -245,6 +249,9 @@ class RunnerImageFactory:
|
|
|
245
249
|
push_to_registry: bool = False,
|
|
246
250
|
services_config: Optional[ServicesConfig] = None,
|
|
247
251
|
protocol_adapters: Optional[List] = None, # New: protocol adapters
|
|
252
|
+
custom_endpoints: Optional[
|
|
253
|
+
List[Dict]
|
|
254
|
+
] = None, # New parameter for custom endpoints
|
|
248
255
|
**kwargs,
|
|
249
256
|
) -> str:
|
|
250
257
|
"""
|
|
@@ -261,6 +268,7 @@ class RunnerImageFactory:
|
|
|
261
268
|
push_to_registry: Whether to push to registry
|
|
262
269
|
services_config: Optional services config
|
|
263
270
|
protocol_adapters: Protocol adapters
|
|
271
|
+
custom_endpoints: Custom endpoints from agent app
|
|
264
272
|
**kwargs: Additional configuration options
|
|
265
273
|
|
|
266
274
|
Returns:
|
|
@@ -276,6 +284,7 @@ class RunnerImageFactory:
|
|
|
276
284
|
push_to_registry=push_to_registry,
|
|
277
285
|
protocol_adapters=protocol_adapters,
|
|
278
286
|
services_config=services_config,
|
|
287
|
+
custom_endpoints=custom_endpoints,
|
|
279
288
|
**kwargs,
|
|
280
289
|
)
|
|
281
290
|
|