agentscope-runtime 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. agentscope_runtime/__init__.py +4 -0
  2. agentscope_runtime/engine/__init__.py +9 -0
  3. agentscope_runtime/engine/agents/__init__.py +2 -0
  4. agentscope_runtime/engine/agents/agentscope_agent/__init__.py +6 -0
  5. agentscope_runtime/engine/agents/agentscope_agent/agent.py +342 -0
  6. agentscope_runtime/engine/agents/agentscope_agent/hooks.py +156 -0
  7. agentscope_runtime/engine/agents/agno_agent.py +220 -0
  8. agentscope_runtime/engine/agents/base_agent.py +29 -0
  9. agentscope_runtime/engine/agents/langgraph_agent.py +59 -0
  10. agentscope_runtime/engine/agents/llm_agent.py +51 -0
  11. agentscope_runtime/engine/deployers/__init__.py +3 -0
  12. agentscope_runtime/engine/deployers/adapter/__init__.py +0 -0
  13. agentscope_runtime/engine/deployers/adapter/a2a/__init__.py +2 -0
  14. agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +425 -0
  15. agentscope_runtime/engine/deployers/adapter/a2a/a2a_agent_adapter.py +69 -0
  16. agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +60 -0
  17. agentscope_runtime/engine/deployers/adapter/protocol_adapter.py +24 -0
  18. agentscope_runtime/engine/deployers/base.py +17 -0
  19. agentscope_runtime/engine/deployers/local_deployer.py +586 -0
  20. agentscope_runtime/engine/helpers/helper.py +127 -0
  21. agentscope_runtime/engine/llms/__init__.py +3 -0
  22. agentscope_runtime/engine/llms/base_llm.py +60 -0
  23. agentscope_runtime/engine/llms/qwen_llm.py +47 -0
  24. agentscope_runtime/engine/misc/__init__.py +0 -0
  25. agentscope_runtime/engine/runner.py +186 -0
  26. agentscope_runtime/engine/schemas/__init__.py +0 -0
  27. agentscope_runtime/engine/schemas/agent_schemas.py +551 -0
  28. agentscope_runtime/engine/schemas/context.py +54 -0
  29. agentscope_runtime/engine/services/__init__.py +9 -0
  30. agentscope_runtime/engine/services/base.py +77 -0
  31. agentscope_runtime/engine/services/context_manager.py +129 -0
  32. agentscope_runtime/engine/services/environment_manager.py +50 -0
  33. agentscope_runtime/engine/services/manager.py +174 -0
  34. agentscope_runtime/engine/services/memory_service.py +270 -0
  35. agentscope_runtime/engine/services/sandbox_service.py +198 -0
  36. agentscope_runtime/engine/services/session_history_service.py +256 -0
  37. agentscope_runtime/engine/tracing/__init__.py +40 -0
  38. agentscope_runtime/engine/tracing/base.py +309 -0
  39. agentscope_runtime/engine/tracing/local_logging_handler.py +356 -0
  40. agentscope_runtime/engine/tracing/tracing_metric.py +69 -0
  41. agentscope_runtime/engine/tracing/wrapper.py +321 -0
  42. agentscope_runtime/sandbox/__init__.py +14 -0
  43. agentscope_runtime/sandbox/box/__init__.py +0 -0
  44. agentscope_runtime/sandbox/box/base/__init__.py +0 -0
  45. agentscope_runtime/sandbox/box/base/base_sandbox.py +37 -0
  46. agentscope_runtime/sandbox/box/base/box/__init__.py +0 -0
  47. agentscope_runtime/sandbox/box/browser/__init__.py +0 -0
  48. agentscope_runtime/sandbox/box/browser/box/__init__.py +0 -0
  49. agentscope_runtime/sandbox/box/browser/browser_sandbox.py +176 -0
  50. agentscope_runtime/sandbox/box/dummy/__init__.py +0 -0
  51. agentscope_runtime/sandbox/box/dummy/dummy_sandbox.py +26 -0
  52. agentscope_runtime/sandbox/box/filesystem/__init__.py +0 -0
  53. agentscope_runtime/sandbox/box/filesystem/box/__init__.py +0 -0
  54. agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +87 -0
  55. agentscope_runtime/sandbox/box/sandbox.py +115 -0
  56. agentscope_runtime/sandbox/box/shared/__init__.py +0 -0
  57. agentscope_runtime/sandbox/box/shared/app.py +44 -0
  58. agentscope_runtime/sandbox/box/shared/dependencies/__init__.py +5 -0
  59. agentscope_runtime/sandbox/box/shared/dependencies/deps.py +22 -0
  60. agentscope_runtime/sandbox/box/shared/routers/__init__.py +12 -0
  61. agentscope_runtime/sandbox/box/shared/routers/generic.py +173 -0
  62. agentscope_runtime/sandbox/box/shared/routers/mcp.py +207 -0
  63. agentscope_runtime/sandbox/box/shared/routers/mcp_utils.py +153 -0
  64. agentscope_runtime/sandbox/box/shared/routers/runtime_watcher.py +187 -0
  65. agentscope_runtime/sandbox/box/shared/routers/workspace.py +325 -0
  66. agentscope_runtime/sandbox/box/training_box/__init__.py +0 -0
  67. agentscope_runtime/sandbox/box/training_box/base.py +120 -0
  68. agentscope_runtime/sandbox/box/training_box/env_service.py +752 -0
  69. agentscope_runtime/sandbox/box/training_box/environments/__init__.py +0 -0
  70. agentscope_runtime/sandbox/box/training_box/environments/appworld/appworld_env.py +987 -0
  71. agentscope_runtime/sandbox/box/training_box/registry.py +54 -0
  72. agentscope_runtime/sandbox/box/training_box/src/trajectory.py +278 -0
  73. agentscope_runtime/sandbox/box/training_box/training_box.py +219 -0
  74. agentscope_runtime/sandbox/build.py +213 -0
  75. agentscope_runtime/sandbox/client/__init__.py +5 -0
  76. agentscope_runtime/sandbox/client/http_client.py +527 -0
  77. agentscope_runtime/sandbox/client/training_client.py +265 -0
  78. agentscope_runtime/sandbox/constant.py +5 -0
  79. agentscope_runtime/sandbox/custom/__init__.py +16 -0
  80. agentscope_runtime/sandbox/custom/custom_sandbox.py +40 -0
  81. agentscope_runtime/sandbox/custom/example.py +37 -0
  82. agentscope_runtime/sandbox/enums.py +68 -0
  83. agentscope_runtime/sandbox/manager/__init__.py +4 -0
  84. agentscope_runtime/sandbox/manager/collections/__init__.py +22 -0
  85. agentscope_runtime/sandbox/manager/collections/base_mapping.py +20 -0
  86. agentscope_runtime/sandbox/manager/collections/base_queue.py +25 -0
  87. agentscope_runtime/sandbox/manager/collections/base_set.py +25 -0
  88. agentscope_runtime/sandbox/manager/collections/in_memory_mapping.py +22 -0
  89. agentscope_runtime/sandbox/manager/collections/in_memory_queue.py +28 -0
  90. agentscope_runtime/sandbox/manager/collections/in_memory_set.py +27 -0
  91. agentscope_runtime/sandbox/manager/collections/redis_mapping.py +26 -0
  92. agentscope_runtime/sandbox/manager/collections/redis_queue.py +27 -0
  93. agentscope_runtime/sandbox/manager/collections/redis_set.py +23 -0
  94. agentscope_runtime/sandbox/manager/container_clients/__init__.py +8 -0
  95. agentscope_runtime/sandbox/manager/container_clients/base_client.py +39 -0
  96. agentscope_runtime/sandbox/manager/container_clients/docker_client.py +170 -0
  97. agentscope_runtime/sandbox/manager/sandbox_manager.py +694 -0
  98. agentscope_runtime/sandbox/manager/server/__init__.py +0 -0
  99. agentscope_runtime/sandbox/manager/server/app.py +194 -0
  100. agentscope_runtime/sandbox/manager/server/config.py +68 -0
  101. agentscope_runtime/sandbox/manager/server/models.py +17 -0
  102. agentscope_runtime/sandbox/manager/storage/__init__.py +10 -0
  103. agentscope_runtime/sandbox/manager/storage/data_storage.py +16 -0
  104. agentscope_runtime/sandbox/manager/storage/local_storage.py +44 -0
  105. agentscope_runtime/sandbox/manager/storage/oss_storage.py +89 -0
  106. agentscope_runtime/sandbox/manager/utils.py +78 -0
  107. agentscope_runtime/sandbox/mcp_server.py +192 -0
  108. agentscope_runtime/sandbox/model/__init__.py +12 -0
  109. agentscope_runtime/sandbox/model/api.py +16 -0
  110. agentscope_runtime/sandbox/model/container.py +72 -0
  111. agentscope_runtime/sandbox/model/manager_config.py +158 -0
  112. agentscope_runtime/sandbox/registry.py +129 -0
  113. agentscope_runtime/sandbox/tools/__init__.py +12 -0
  114. agentscope_runtime/sandbox/tools/base/__init__.py +8 -0
  115. agentscope_runtime/sandbox/tools/base/tool.py +52 -0
  116. agentscope_runtime/sandbox/tools/browser/__init__.py +57 -0
  117. agentscope_runtime/sandbox/tools/browser/tool.py +597 -0
  118. agentscope_runtime/sandbox/tools/filesystem/__init__.py +32 -0
  119. agentscope_runtime/sandbox/tools/filesystem/tool.py +319 -0
  120. agentscope_runtime/sandbox/tools/function_tool.py +321 -0
  121. agentscope_runtime/sandbox/tools/mcp_tool.py +191 -0
  122. agentscope_runtime/sandbox/tools/sandbox_tool.py +104 -0
  123. agentscope_runtime/sandbox/tools/tool.py +123 -0
  124. agentscope_runtime/sandbox/tools/utils.py +68 -0
  125. agentscope_runtime/version.py +2 -0
  126. agentscope_runtime-0.1.0.dist-info/METADATA +327 -0
  127. agentscope_runtime-0.1.0.dist-info/RECORD +131 -0
  128. agentscope_runtime-0.1.0.dist-info/WHEEL +5 -0
  129. agentscope_runtime-0.1.0.dist-info/entry_points.txt +4 -0
  130. agentscope_runtime-0.1.0.dist-info/licenses/LICENSE +202 -0
  131. agentscope_runtime-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,213 @@
1
+ # -*- coding: utf-8 -*-
2
+ # pylint: disable=too-many-statements
3
+ import argparse
4
+ import logging
5
+ import os
6
+ import socket
7
+ import subprocess
8
+ import time
9
+
10
+ import requests
11
+
12
+ from .enums import SandboxType
13
+ from .registry import SandboxRegistry
14
+
15
+
16
+ def find_free_port(start_port, end_port):
17
+ for port in range(start_port, end_port + 1):
18
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
19
+ if sock.connect_ex(("localhost", port)) != 0:
20
+ return port
21
+ logging.error(
22
+ f"No free ports available in the range {start_port}-{end_port}",
23
+ )
24
+ raise RuntimeError(
25
+ f"No free ports available in the range {start_port}-{end_port}",
26
+ )
27
+
28
+
29
+ def check_health(url, secret_token, timeout=120, interval=5):
30
+ headers = {"Authorization": f"Bearer {secret_token}"}
31
+ spent_time = 0
32
+ while spent_time < timeout:
33
+ logging.info(
34
+ f"Attempting to connect to {url} (Elapsed time: {spent_time} "
35
+ f"seconds)...",
36
+ )
37
+ try:
38
+ response = requests.get(url, headers=headers)
39
+ if response.status_code == 200:
40
+ print(f"Health check successful for {url}")
41
+ return True
42
+ except requests.exceptions.RequestException:
43
+ pass
44
+ logging.info(
45
+ f"Health check failed for {url}. Retrying in {interval} "
46
+ f"seconds...",
47
+ )
48
+ time.sleep(interval)
49
+ spent_time += interval
50
+ logging.error(f"Health check failed for {url} after {timeout} seconds.")
51
+ return False
52
+
53
+
54
+ def build_image(build_type, dockerfile_path=None):
55
+ if dockerfile_path is None:
56
+ dockerfile_path = (
57
+ f"src/agentscope_runtime/sandbox/box/{build_type}/Dockerfile"
58
+ )
59
+
60
+ logging.info(f"Building {build_type} with `{dockerfile_path}`...")
61
+
62
+ # Initialize and update Git submodule
63
+ logging.info("Initializing and updating Git submodule...")
64
+ subprocess.run(
65
+ ["git", "submodule", "update", "--init", "--recursive"],
66
+ check=True,
67
+ )
68
+
69
+ secret_token = "secret_token123"
70
+ image_name = SandboxRegistry.get_image_by_type(build_type)
71
+
72
+ logging.info(f"Building Docker image {image_name}...")
73
+
74
+ # Check if image exists
75
+ result = subprocess.run(
76
+ ["docker", "images", "--format", "{{.Repository}}:{{.Tag}}"],
77
+ capture_output=True,
78
+ text=True,
79
+ check=True,
80
+ )
81
+ images = result.stdout.splitlines()
82
+
83
+ # Check if the image already exists
84
+ if image_name in images or f"{image_name}dev" in images:
85
+ choice = input(
86
+ f"Image {image_name}dev|{image_name} already exists. Do "
87
+ f"you want to overwrite it? (y/N): ",
88
+ )
89
+ if choice.lower() != "y":
90
+ logging.info("Exiting without overwriting the existing image.")
91
+ return
92
+
93
+ if not os.path.exists(dockerfile_path):
94
+ raise FileNotFoundError(
95
+ f"Dockerfile not found at {dockerfile_path}. Are you trying to "
96
+ f"build custom images?",
97
+ )
98
+
99
+ # Build Docker image
100
+ subprocess.run(
101
+ [
102
+ "docker",
103
+ "build",
104
+ "-f",
105
+ dockerfile_path,
106
+ "-t",
107
+ f"{image_name}dev",
108
+ ".",
109
+ ],
110
+ check=False,
111
+ )
112
+ logging.info(f"Docker image {image_name}dev built successfully.")
113
+
114
+ logging.info(f"Start to build image {image_name}.")
115
+
116
+ # Run the container with port mapping and environment variable
117
+ free_port = find_free_port(8080, 8090)
118
+ result = subprocess.run(
119
+ [
120
+ "docker",
121
+ "run",
122
+ "-d",
123
+ "-p",
124
+ f"{free_port}:80",
125
+ "-e",
126
+ f"SECRET_TOKEN={secret_token}",
127
+ f"{image_name}",
128
+ ],
129
+ capture_output=True,
130
+ text=True,
131
+ check=False,
132
+ )
133
+ container_id = result.stdout.strip()
134
+ logging.info(f"Running container {container_id} on port {free_port}")
135
+
136
+ # Check health endpoints
137
+ fastapi_health_url = f"http://localhost:{free_port}/fastapi/healthz"
138
+ steelapi_health_url = (
139
+ f"http://localhost:{free_port}/steel-api/{secret_token}/v1/health"
140
+ )
141
+
142
+ # Check health for FASTAPI
143
+ fastapi_healthy = check_health(fastapi_health_url, secret_token)
144
+
145
+ # Check health for Browser
146
+ if build_type in [SandboxType.BROWSER.value]:
147
+ browser_healthy = check_health(steelapi_health_url, secret_token)
148
+ else:
149
+ browser_healthy = True
150
+
151
+ if browser_healthy and fastapi_healthy:
152
+ logging.info("Health checks passed.")
153
+ subprocess.run(
154
+ ["docker", "commit", container_id, f"{image_name}"],
155
+ check=True,
156
+ )
157
+ logging.info(
158
+ f"Docker image {image_name} committed successfully.",
159
+ )
160
+ subprocess.run(["docker", "stop", container_id], check=True)
161
+ subprocess.run(["docker", "rm", container_id], check=True)
162
+ else:
163
+ logging.error("Health checks failed.")
164
+ subprocess.run(["docker", "stop", container_id], check=True)
165
+
166
+ choice = input(
167
+ f"Do you want to delete the dev image {image_name}dev? (" f"y/N): ",
168
+ )
169
+ if choice.lower() == "y":
170
+ subprocess.run(
171
+ ["docker", "rmi", "-f", f"{image_name}dev"],
172
+ check=True,
173
+ )
174
+ logging.info(f"Dev image {image_name}dev deleted.")
175
+ else:
176
+ logging.info(f"Dev image {image_name}dev retained.")
177
+
178
+
179
+ def main():
180
+ parser = argparse.ArgumentParser(
181
+ description="Build different types of Docker images.",
182
+ )
183
+ parser.add_argument(
184
+ "build_type",
185
+ default="base",
186
+ choices=[x.value for x in SandboxType] + ["all"],
187
+ help="Specify the build type to execute.",
188
+ )
189
+
190
+ parser.add_argument(
191
+ "--dockerfile_path",
192
+ default=None,
193
+ help="Specify the path for the Dockerfile.",
194
+ )
195
+
196
+ args = parser.parse_args()
197
+
198
+ if args.build_type == "all":
199
+ # Only build the built-in images
200
+ for build_type in [x.value for x in SandboxType.get_builtin_members()]:
201
+ build_image(build_type)
202
+ else:
203
+ if args.build_type not in [
204
+ x.value for x in SandboxType.get_builtin_members()
205
+ ]:
206
+ assert (
207
+ args.dockerfile_path is not None
208
+ ), "Dockerfile path is required for custom images"
209
+ build_image(args.build_type, args.dockerfile_path)
210
+
211
+
212
+ if __name__ == "__main__":
213
+ main()
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ from .http_client import SandboxHttpClient
3
+ from .training_client import TrainingSandboxClient
4
+
5
+ __all__ = ["SandboxHttpClient", "TrainingSandboxClient"]