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
|
@@ -12,7 +12,7 @@ import shutil
|
|
|
12
12
|
import tarfile
|
|
13
13
|
import tempfile
|
|
14
14
|
from pathlib import Path
|
|
15
|
-
from typing import List, Optional, Any, Tuple
|
|
15
|
+
from typing import List, Optional, Any, Tuple, Dict
|
|
16
16
|
|
|
17
17
|
from pydantic import BaseModel
|
|
18
18
|
|
|
@@ -61,6 +61,173 @@ def _get_package_version() -> str:
|
|
|
61
61
|
return ""
|
|
62
62
|
|
|
63
63
|
|
|
64
|
+
def _prepare_custom_endpoints_for_template(
|
|
65
|
+
custom_endpoints: Optional[List[Dict]],
|
|
66
|
+
temp_dir: str,
|
|
67
|
+
) -> Tuple[Optional[List[Dict]], List[str]]:
|
|
68
|
+
"""
|
|
69
|
+
Prepare custom endpoints for template rendering.
|
|
70
|
+
Copy handler source directories to ensure all dependencies are available.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
custom_endpoints: List of custom endpoint configurations
|
|
74
|
+
temp_dir: Temporary directory where files will be copied
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
Tuple of:
|
|
78
|
+
- Prepared endpoint configurations with file information
|
|
79
|
+
- List of copied directory names (for sys.path setup)
|
|
80
|
+
"""
|
|
81
|
+
if not custom_endpoints:
|
|
82
|
+
return None, []
|
|
83
|
+
|
|
84
|
+
prepared_endpoints = []
|
|
85
|
+
handler_dirs_copied = set() # Track copied directories to avoid duplicates
|
|
86
|
+
copied_dir_names = [] # Track directory names for sys.path
|
|
87
|
+
|
|
88
|
+
for endpoint in custom_endpoints:
|
|
89
|
+
prepared_endpoint = {
|
|
90
|
+
"path": endpoint.get("path", "/unknown"),
|
|
91
|
+
"methods": endpoint.get("methods", ["POST"]),
|
|
92
|
+
"module": endpoint.get("module"),
|
|
93
|
+
"function_name": endpoint.get("function_name"),
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
# Try to get handler source file if handler is provided
|
|
97
|
+
handler = endpoint.get("handler")
|
|
98
|
+
if handler and callable(handler):
|
|
99
|
+
try:
|
|
100
|
+
# Get the source file of the handler
|
|
101
|
+
handler_file = inspect.getfile(handler)
|
|
102
|
+
handler_name = handler.__name__
|
|
103
|
+
|
|
104
|
+
# Skip if it's a built-in or from site-packages
|
|
105
|
+
if (
|
|
106
|
+
not handler_file.endswith(".py")
|
|
107
|
+
or "site-packages" in handler_file
|
|
108
|
+
):
|
|
109
|
+
raise ValueError("Handler from non-user code")
|
|
110
|
+
|
|
111
|
+
# Get the directory containing the handler file
|
|
112
|
+
handler_dir = os.path.dirname(os.path.abspath(handler_file))
|
|
113
|
+
|
|
114
|
+
# Copy the entire working directory if not already copied
|
|
115
|
+
if handler_dir not in handler_dirs_copied:
|
|
116
|
+
# Create a subdirectory name for this handler's context
|
|
117
|
+
dir_name = os.path.basename(handler_dir)
|
|
118
|
+
if not dir_name or dir_name == ".":
|
|
119
|
+
dir_name = "handler_context"
|
|
120
|
+
|
|
121
|
+
# Sanitize directory name
|
|
122
|
+
dir_name = re.sub(r"[^a-zA-Z0-9_]", "_", dir_name)
|
|
123
|
+
|
|
124
|
+
# Ensure unique directory name
|
|
125
|
+
counter = 1
|
|
126
|
+
base_dir_name = dir_name
|
|
127
|
+
dest_context_dir = os.path.join(temp_dir, dir_name)
|
|
128
|
+
while os.path.exists(dest_context_dir):
|
|
129
|
+
dir_name = f"{base_dir_name}_{counter}"
|
|
130
|
+
dest_context_dir = os.path.join(temp_dir, dir_name)
|
|
131
|
+
counter += 1
|
|
132
|
+
|
|
133
|
+
# Copy entire directory structure
|
|
134
|
+
# Exclude common non-essential directories
|
|
135
|
+
ignore_patterns = shutil.ignore_patterns(
|
|
136
|
+
"__pycache__",
|
|
137
|
+
"*.pyc",
|
|
138
|
+
"*.pyo",
|
|
139
|
+
".git",
|
|
140
|
+
".gitignore",
|
|
141
|
+
".pytest_cache",
|
|
142
|
+
".mypy_cache",
|
|
143
|
+
".tox",
|
|
144
|
+
"venv",
|
|
145
|
+
"env",
|
|
146
|
+
".venv",
|
|
147
|
+
".env",
|
|
148
|
+
"node_modules",
|
|
149
|
+
".DS_Store",
|
|
150
|
+
"*.egg-info",
|
|
151
|
+
"build",
|
|
152
|
+
"dist",
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
shutil.copytree(
|
|
156
|
+
handler_dir,
|
|
157
|
+
dest_context_dir,
|
|
158
|
+
ignore=ignore_patterns,
|
|
159
|
+
dirs_exist_ok=True,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
handler_dirs_copied.add(handler_dir)
|
|
163
|
+
copied_dir_names.append(dir_name)
|
|
164
|
+
else:
|
|
165
|
+
# Find the existing copied directory name
|
|
166
|
+
for existing_dir in os.listdir(temp_dir):
|
|
167
|
+
existing_path = os.path.join(temp_dir, existing_dir)
|
|
168
|
+
if os.path.isdir(existing_path):
|
|
169
|
+
# Check if this is the directory we already copied
|
|
170
|
+
original_handler_basename = os.path.basename(
|
|
171
|
+
handler_dir,
|
|
172
|
+
)
|
|
173
|
+
if existing_dir.startswith(
|
|
174
|
+
re.sub(
|
|
175
|
+
r"[^a-zA-Z0-9_]",
|
|
176
|
+
"_",
|
|
177
|
+
original_handler_basename,
|
|
178
|
+
),
|
|
179
|
+
):
|
|
180
|
+
dir_name = existing_dir
|
|
181
|
+
break
|
|
182
|
+
else:
|
|
183
|
+
# Fallback if not found
|
|
184
|
+
dir_name = re.sub(
|
|
185
|
+
r"[^a-zA-Z0-9_]",
|
|
186
|
+
"_",
|
|
187
|
+
os.path.basename(handler_dir),
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
# Calculate the module path relative to the handler directory
|
|
191
|
+
handler_file_rel = os.path.relpath(handler_file, handler_dir)
|
|
192
|
+
# Convert file path to module path
|
|
193
|
+
module_parts = os.path.splitext(handler_file_rel)[0].split(
|
|
194
|
+
os.sep,
|
|
195
|
+
)
|
|
196
|
+
if module_parts[-1] == "__init__":
|
|
197
|
+
module_parts = module_parts[:-1]
|
|
198
|
+
|
|
199
|
+
# Construct the full import path
|
|
200
|
+
if module_parts:
|
|
201
|
+
module_path = f"{dir_name}.{'.'.join(module_parts)}"
|
|
202
|
+
else:
|
|
203
|
+
module_path = dir_name
|
|
204
|
+
|
|
205
|
+
# Set the module and function name for template
|
|
206
|
+
prepared_endpoint["handler_module"] = module_path
|
|
207
|
+
prepared_endpoint["function_name"] = handler_name
|
|
208
|
+
|
|
209
|
+
except (OSError, TypeError, ValueError) as e:
|
|
210
|
+
# If source file extraction fails, try module/function_name
|
|
211
|
+
import traceback
|
|
212
|
+
|
|
213
|
+
print(f"Warning: Failed to copy handler directory: {e}")
|
|
214
|
+
traceback.print_exc()
|
|
215
|
+
|
|
216
|
+
# Add inline code if no handler module/function available
|
|
217
|
+
if not prepared_endpoint.get("handler_module") and (
|
|
218
|
+
not prepared_endpoint["module"]
|
|
219
|
+
or not prepared_endpoint["function_name"]
|
|
220
|
+
):
|
|
221
|
+
prepared_endpoint["inline_code"] = endpoint.get(
|
|
222
|
+
"inline_code",
|
|
223
|
+
'lambda request: {"error": "Handler not available"}',
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
prepared_endpoints.append(prepared_endpoint)
|
|
227
|
+
|
|
228
|
+
return prepared_endpoints, copied_dir_names
|
|
229
|
+
|
|
230
|
+
|
|
64
231
|
class PackageConfig(BaseModel):
|
|
65
232
|
"""Configuration for project packaging"""
|
|
66
233
|
|
|
@@ -73,6 +240,13 @@ class PackageConfig(BaseModel):
|
|
|
73
240
|
ServicesConfig
|
|
74
241
|
] = None # New: services configuration
|
|
75
242
|
protocol_adapters: Optional[List[Any]] = None # New: protocol adapters
|
|
243
|
+
custom_endpoints: Optional[
|
|
244
|
+
List[Dict]
|
|
245
|
+
] = None # New: custom endpoints configuration
|
|
246
|
+
# Celery configuration parameters
|
|
247
|
+
broker_url: Optional[str] = None
|
|
248
|
+
backend_url: Optional[str] = None
|
|
249
|
+
enable_embedded_worker: bool = False
|
|
76
250
|
|
|
77
251
|
|
|
78
252
|
def _find_agent_source_file(
|
|
@@ -742,6 +916,41 @@ def package_project(
|
|
|
742
916
|
f"# Protocol adapters\nprotocol_adapters = {instances_str}"
|
|
743
917
|
)
|
|
744
918
|
|
|
919
|
+
# Convert celery_config to string representation for template
|
|
920
|
+
celery_config_str = None
|
|
921
|
+
config_lines = []
|
|
922
|
+
|
|
923
|
+
# Generate celery configuration code
|
|
924
|
+
config_lines.append("# Celery configuration")
|
|
925
|
+
|
|
926
|
+
if config.broker_url:
|
|
927
|
+
config_lines.append(
|
|
928
|
+
f'celery_config["broker_url"] = "{config.broker_url}"',
|
|
929
|
+
)
|
|
930
|
+
|
|
931
|
+
if config.backend_url:
|
|
932
|
+
config_lines.append(
|
|
933
|
+
f'celery_config["backend_url"] = "{config.backend_url}"',
|
|
934
|
+
)
|
|
935
|
+
|
|
936
|
+
if config.enable_embedded_worker:
|
|
937
|
+
config_lines.append(
|
|
938
|
+
f'celery_config["enable_embedded_worker"] = '
|
|
939
|
+
f"{config.enable_embedded_worker}",
|
|
940
|
+
)
|
|
941
|
+
|
|
942
|
+
if config_lines:
|
|
943
|
+
celery_config_str = "\n".join(config_lines)
|
|
944
|
+
|
|
945
|
+
# Prepare custom endpoints and get copied directory names
|
|
946
|
+
(
|
|
947
|
+
custom_endpoints_data,
|
|
948
|
+
handler_dirs,
|
|
949
|
+
) = _prepare_custom_endpoints_for_template(
|
|
950
|
+
config.custom_endpoints,
|
|
951
|
+
temp_dir,
|
|
952
|
+
)
|
|
953
|
+
|
|
745
954
|
# Render template - use template file by default,
|
|
746
955
|
# or user-provided string
|
|
747
956
|
if template is None:
|
|
@@ -751,6 +960,9 @@ def package_project(
|
|
|
751
960
|
endpoint_path=config.endpoint_path or "/process",
|
|
752
961
|
deployment_mode=config.deployment_mode or "standalone",
|
|
753
962
|
protocol_adapters=protocol_adapters_str,
|
|
963
|
+
celery_config=celery_config_str,
|
|
964
|
+
custom_endpoints=custom_endpoints_data,
|
|
965
|
+
handler_dirs=handler_dirs,
|
|
754
966
|
)
|
|
755
967
|
else:
|
|
756
968
|
# Use user-provided template string
|
|
@@ -760,6 +972,9 @@ def package_project(
|
|
|
760
972
|
endpoint_path=config.endpoint_path,
|
|
761
973
|
deployment_mode=config.deployment_mode or "standalone",
|
|
762
974
|
protocol_adapters=protocol_adapters_str,
|
|
975
|
+
celery_config=celery_config_str,
|
|
976
|
+
custom_endpoints=custom_endpoints_data,
|
|
977
|
+
handler_dirs=handler_dirs,
|
|
763
978
|
)
|
|
764
979
|
|
|
765
980
|
# Write main.py
|
|
@@ -802,9 +1017,25 @@ def package_project(
|
|
|
802
1017
|
if not config.requirements:
|
|
803
1018
|
config.requirements = []
|
|
804
1019
|
|
|
805
|
-
#
|
|
1020
|
+
# Add Celery requirements if Celery is configured
|
|
1021
|
+
celery_requirements = []
|
|
1022
|
+
if (
|
|
1023
|
+
config.broker_url
|
|
1024
|
+
or config.backend_url
|
|
1025
|
+
or config.enable_embedded_worker
|
|
1026
|
+
):
|
|
1027
|
+
celery_requirements = ["celery", "redis"]
|
|
1028
|
+
|
|
1029
|
+
# Combine base requirements with user requirements and Celery
|
|
1030
|
+
# requirements
|
|
806
1031
|
all_requirements = sorted(
|
|
807
|
-
list(
|
|
1032
|
+
list(
|
|
1033
|
+
set(
|
|
1034
|
+
base_requirements
|
|
1035
|
+
+ config.requirements
|
|
1036
|
+
+ celery_requirements,
|
|
1037
|
+
),
|
|
1038
|
+
),
|
|
808
1039
|
)
|
|
809
1040
|
for req in all_requirements:
|
|
810
1041
|
f.write(f"{req}\n")
|