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,69 @@
1
+ # -*- coding: utf-8 -*-
2
+ class TraceType(str):
3
+ """Callback manager event types.
4
+
5
+ Attributes:
6
+ LLM: Logs for the template and response of LLM calls.
7
+ TOOL:Logs for the tool name and its arguments and
8
+ the output of tool calls
9
+ AGENT_STEP: Logs for the agent loop start and end?
10
+ """
11
+
12
+ # Officially supported event types
13
+ LLM = "llm"
14
+ TOOL = "tool"
15
+ AGENT_STEP = "agent_step"
16
+ SEARCH = "search"
17
+ IMAGE_GENERATION = "image_generation"
18
+ RAG = "rag"
19
+ INTENTION = "intention"
20
+ PLUGIN_CENTER = "plugin_center"
21
+
22
+ def __init__(self, value: str):
23
+ """Initialize a TraceType with a string value.
24
+
25
+ Args:
26
+ value (str): The string value for the trace type.
27
+
28
+ Raises:
29
+ ValueError: If value is not a string.
30
+ """
31
+ if not isinstance(value, str):
32
+ raise ValueError(
33
+ f"TraceType value must be a string, got {type(value)}",
34
+ )
35
+ self._value_ = value
36
+
37
+ def __str__(self) -> str:
38
+ """Return the string representation of the trace type.
39
+
40
+ Returns:
41
+ str: The trace type value.
42
+ """
43
+ return self._value_
44
+
45
+ def __repr__(self) -> str:
46
+ """Return the detailed string representation of the trace type.
47
+
48
+ Returns:
49
+ str: The trace type representation in the format TraceType(value).
50
+ """
51
+ return f"TraceType({self._value_})"
52
+
53
+ @classmethod
54
+ def add_type(cls, name: str, value: str) -> None:
55
+ """Add a new trace type to the class.
56
+
57
+ Args:
58
+ name (str): The name of the new trace type attribute.
59
+ value (str): The string value for the new trace type.
60
+
61
+ Raises:
62
+ ValueError: If name or value are not strings, or if the name
63
+ already exists.
64
+ """
65
+ if not isinstance(name, str) or not isinstance(value, str):
66
+ raise ValueError("Name and value must be strings")
67
+ if hasattr(cls, name):
68
+ raise ValueError(f"TraceType {name} already exists")
69
+ setattr(cls, name, cls(value))
@@ -0,0 +1,321 @@
1
+ # -*- coding: utf-8 -*-
2
+ # pylint:disable=too-many-statements,typevar-name-incorrect-variance
3
+ import inspect
4
+ from functools import wraps
5
+ from typing import (
6
+ Any,
7
+ AsyncGenerator,
8
+ Dict,
9
+ Iterable,
10
+ Optional,
11
+ Union,
12
+ )
13
+ from typing import AsyncIterable, AsyncIterator, Tuple, TypeVar
14
+
15
+ from pydantic import BaseModel
16
+ from openai.types.chat import ChatCompletionChunk
17
+
18
+ from .base import Tracer, TraceType
19
+ from .local_logging_handler import LocalLogHandler
20
+
21
+ T = TypeVar("T", covariant=True)
22
+
23
+
24
+ async def aenumerate(
25
+ asequence: AsyncIterable[T],
26
+ start: int = 0,
27
+ ) -> AsyncIterator[Tuple[int, T]]:
28
+ """Asynchronously enumerate an async iterator from a given start value.
29
+
30
+ Args:
31
+ asequence (AsyncIterable[T]): The async iterable to enumerate.
32
+ start (int): The starting value for enumeration. Defaults to 0.
33
+
34
+ Yields:
35
+ Tuple[int, T]: A tuple containing the index and the item from the
36
+ async iterable.
37
+ """
38
+ n = start
39
+ async for elem in asequence:
40
+ yield n, elem
41
+ n += 1
42
+
43
+
44
+ def trace(
45
+ trace_type: Union[TraceType, str],
46
+ tracer: Optional[Tracer] = Tracer(
47
+ handlers=[LocalLogHandler(enable_console=True)],
48
+ ),
49
+ ) -> Any:
50
+ """Decorator for tracing function execution.
51
+
52
+ Args:
53
+ trace_type (Union[TraceType, str]): The type of trace event.
54
+ tracer (Optional[Tracer]): The tracer instance to use. Defaults to
55
+ a new Tracer with LocalLogHandler.
56
+
57
+ Returns:
58
+ Any: The decorated function with tracing capabilities.
59
+ """
60
+ if isinstance(trace_type, str):
61
+ trace_type = TraceType(trace_type)
62
+
63
+ def task_wrapper(func: Any) -> Any:
64
+ """Wrapper function that applies tracing to the target function.
65
+
66
+ Args:
67
+ func (Any): The function to be traced.
68
+
69
+ Returns:
70
+ Any: The wrapped function with appropriate tracing logic.
71
+ """
72
+
73
+ async def async_exec(*args: Any, **kwargs: Any) -> Any:
74
+ """Execute async function with tracing.
75
+
76
+ Args:
77
+ *args (Any): Positional arguments for the function.
78
+ **kwargs (Any): Keyword arguments for the function.
79
+
80
+ Returns:
81
+ Any: The result of the traced function.
82
+ """
83
+ start_payload = _get_start_payload(args, kwargs)
84
+ with tracer.event(
85
+ trace_type,
86
+ payload=start_payload,
87
+ **kwargs,
88
+ ) as event:
89
+ kwargs = kwargs if kwargs is not None else {}
90
+ kwargs["trace_event"] = event
91
+ result = await func(*args, **kwargs)
92
+ event.on_end(payload=_obj_to_dict(result))
93
+ return result
94
+
95
+ def sync_exec(*args: Any, **kwargs: Any) -> Any:
96
+ """Execute sync function with tracing.
97
+
98
+ Args:
99
+ *args (Any): Positional arguments for the function.
100
+ **kwargs (Any): Keyword arguments for the function.
101
+
102
+ Returns:
103
+ Any: The result of the traced function.
104
+ """
105
+ start_payload = _get_start_payload(args, kwargs)
106
+ with tracer.event(
107
+ trace_type,
108
+ payload=start_payload,
109
+ **kwargs,
110
+ ) as event:
111
+ kwargs = kwargs if kwargs is not None else {}
112
+ kwargs["trace_event"] = event
113
+ result = func(*args, **kwargs)
114
+ event.on_end(payload=_obj_to_dict(result))
115
+ return result
116
+
117
+ @wraps(func)
118
+ async def async_iter_task(
119
+ *args: Any,
120
+ **kwargs: Any,
121
+ ) -> AsyncGenerator[T, None]:
122
+ """Execute async generator function with tracing.
123
+
124
+ Args:
125
+ *args (Any): Positional arguments for the function.
126
+ **kwargs (Any): Keyword arguments for the function.
127
+
128
+ Yields:
129
+ T: Items from the traced async generator.
130
+ """
131
+ start_payload = _get_start_payload(args, kwargs)
132
+ with tracer.event(
133
+ trace_type,
134
+ payload=start_payload,
135
+ **kwargs,
136
+ ) as event:
137
+ kwargs = kwargs if kwargs is not None else {}
138
+ kwargs["trace_event"] = event
139
+ cumulated = []
140
+
141
+ async def iter_entry() -> AsyncGenerator[T, None]:
142
+ """Internal async generator for processing items.
143
+
144
+ Yields:
145
+ T: Items from the original generator with tracing.
146
+ """
147
+ try:
148
+ async for i, resp in aenumerate(
149
+ func(*args, **kwargs),
150
+ ): # type: ignore
151
+ if i == 0:
152
+ event.on_log(
153
+ "",
154
+ **{
155
+ "step_suffix": "first_resp",
156
+ "payload": resp.model_dump(),
157
+ },
158
+ )
159
+ # todo: support more components
160
+ if isinstance(resp, ChatCompletionChunk):
161
+ if len(resp.choices) > 0:
162
+ cumulated.append(resp)
163
+ if (
164
+ resp.choices[0].finish_reason
165
+ is not None
166
+ ):
167
+ if (
168
+ resp.choices[0].finish_reason
169
+ == "stop"
170
+ ):
171
+ step_suffix = "last_resp"
172
+ else:
173
+ step_suffix = resp.choices[
174
+ 0
175
+ ].finish_reason
176
+ event.on_log(
177
+ "",
178
+ **{
179
+ "step_suffix": step_suffix,
180
+ "payload": resp.model_dump(),
181
+ },
182
+ )
183
+ elif resp.usage:
184
+ cumulated.append(resp)
185
+
186
+ yield resp
187
+ except Exception as e:
188
+ raise e
189
+
190
+ try:
191
+ async for resp in iter_entry():
192
+ yield resp
193
+
194
+ except Exception as e:
195
+ raise e
196
+
197
+ @wraps(func)
198
+ def iter_task(*args: Any, **kwargs: Any) -> Iterable[T]:
199
+ """Execute generator function with tracing.
200
+
201
+ Args:
202
+ *args (Any): Positional arguments for the function.
203
+ **kwargs (Any): Keyword arguments for the function.
204
+
205
+ Yields:
206
+ T: Items from the traced generator.
207
+ """
208
+ start_payload = _get_start_payload(args, kwargs)
209
+ with tracer.event(
210
+ trace_type,
211
+ payload=start_payload,
212
+ **kwargs,
213
+ ) as event:
214
+ cumulated = []
215
+ try:
216
+ kwargs = kwargs if kwargs is not None else {}
217
+ kwargs["trace_event"] = event
218
+ for i, resp in enumerate(func(*args, **kwargs)):
219
+ if i == 0:
220
+ event.on_log(
221
+ "",
222
+ **{
223
+ "step_suffix": "first_resp",
224
+ "payload": resp.model_dump(),
225
+ },
226
+ )
227
+ # todo: support more components
228
+ if len(resp.choices) > 0:
229
+ cumulated.append(resp)
230
+ if resp.choices[0].finish_reason is not None:
231
+ if resp.choices[0].finish_reason == "stop":
232
+ step_suffix = "last_resp"
233
+ else:
234
+ step_suffix = resp.choices[0].finish_reason
235
+ event.on_log(
236
+ "",
237
+ **{
238
+ "step_suffix": step_suffix,
239
+ "payload": resp.model_dump(),
240
+ },
241
+ )
242
+ elif resp.usage:
243
+ cumulated.append(resp)
244
+
245
+ yield resp
246
+ except Exception as e:
247
+ raise e
248
+
249
+ if inspect.isasyncgenfunction(func):
250
+ return async_iter_task
251
+ elif inspect.isgeneratorfunction(func):
252
+ return iter_task
253
+ elif inspect.iscoroutinefunction(func):
254
+ return async_exec
255
+ else:
256
+ return sync_exec
257
+
258
+ return task_wrapper
259
+
260
+
261
+ def _get_start_payload(args: Any, kwargs: Any) -> Dict:
262
+ """Extract and format the start payload from function arguments.
263
+
264
+ Args:
265
+ args (Any): Positional arguments from the function call.
266
+ kwargs (Any): Keyword arguments from the function call.
267
+
268
+ Returns:
269
+ Dict: The formatted start payload for tracing.
270
+ """
271
+ dict_args = {}
272
+ if isinstance(args, tuple) and len(args) > 1:
273
+ dict_args = _obj_to_dict(args[1:])
274
+
275
+ dict_kwargs = _obj_to_dict(kwargs)
276
+ dict_kwargs = {
277
+ key: value
278
+ for key, value in dict_kwargs.items()
279
+ if not key.startswith("trace_")
280
+ }
281
+
282
+ merged = {}
283
+ if dict_args:
284
+ if isinstance(dict_args, list):
285
+ for item in dict_args:
286
+ if isinstance(item, dict):
287
+ merged.update(item)
288
+ elif isinstance(dict_args, dict):
289
+ merged.update(dict_args)
290
+
291
+ if dict_kwargs:
292
+ merged.update(dict_kwargs)
293
+
294
+ return merged
295
+
296
+
297
+ def _obj_to_dict(obj: Any) -> Any:
298
+ """Convert an object to a dictionary representation for tracing.
299
+
300
+ Args:
301
+ obj (Any): The object to convert.
302
+
303
+ Returns:
304
+ Any: The dictionary representation of the object, or the object
305
+ itself if it's a primitive type.
306
+ """
307
+ if isinstance(obj, (str, int, float, bool, type(None))):
308
+ return obj
309
+ elif isinstance(obj, dict):
310
+ return {k: _obj_to_dict(v) for k, v in obj.items()} # obj
311
+ elif isinstance(obj, (list, set, tuple)):
312
+ return [_obj_to_dict(item) for item in obj]
313
+ elif isinstance(obj, BaseModel):
314
+ return obj.model_dump()
315
+ else:
316
+ result = None
317
+ try:
318
+ result = str(obj)
319
+ except Exception as e:
320
+ print(f"{obj} str method failed with error: {e}")
321
+ return result
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+ from .custom import *
3
+ from .box.base.base_sandbox import BaseSandbox
4
+ from .box.browser.browser_sandbox import BrowserSandbox
5
+ from .box.filesystem.filesystem_sandbox import FilesystemSandbox
6
+ from .box.training_box.training_box import TrainingSandbox
7
+
8
+
9
+ __all__ = [
10
+ "BaseSandbox",
11
+ "BrowserSandbox",
12
+ "FilesystemSandbox",
13
+ "TrainingSandbox",
14
+ ]
File without changes
File without changes
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ from typing import Optional
3
+
4
+ from ...constant import IMAGE_TAG
5
+ from ...registry import SandboxRegistry
6
+ from ...enums import SandboxType
7
+ from ...box.sandbox import Sandbox
8
+
9
+
10
+ @SandboxRegistry.register(
11
+ f"agentscope/runtime-sandbox-base:{IMAGE_TAG}",
12
+ sandbox_type=SandboxType.BASE,
13
+ security_level="medium",
14
+ timeout=30,
15
+ description="Base Sandbox",
16
+ )
17
+ class BaseSandbox(Sandbox):
18
+ def __init__(
19
+ self,
20
+ sandbox_id: Optional[str] = None,
21
+ timeout: int = 3000,
22
+ base_url: Optional[str] = None,
23
+ bearer_token: Optional[str] = None,
24
+ ):
25
+ super().__init__(
26
+ sandbox_id,
27
+ timeout,
28
+ base_url,
29
+ bearer_token,
30
+ SandboxType.BASE,
31
+ )
32
+
33
+ def run_ipython_cell(self, code: str):
34
+ return self.call_tool("run_ipython_cell", {"code": code})
35
+
36
+ def run_shell_command(self, command: str):
37
+ return self.call_tool("run_shell_command", {"command": command})
File without changes
File without changes
File without changes
@@ -0,0 +1,176 @@
1
+ # -*- coding: utf-8 -*-
2
+ # pylint: disable=too-many-public-methods
3
+ from typing import Optional
4
+
5
+ from ...constant import IMAGE_TAG
6
+ from ...registry import SandboxRegistry
7
+ from ...enums import SandboxType
8
+ from ...box.sandbox import Sandbox
9
+
10
+
11
+ @SandboxRegistry.register(
12
+ f"agentscope/runtime-sandbox-browser:{IMAGE_TAG}",
13
+ sandbox_type=SandboxType.BROWSER,
14
+ security_level="medium",
15
+ timeout=60,
16
+ description="Browser sandbox",
17
+ )
18
+ class BrowserSandbox(Sandbox):
19
+ def __init__(
20
+ self,
21
+ sandbox_id: Optional[str] = None,
22
+ timeout: int = 3000,
23
+ base_url: Optional[str] = None,
24
+ bearer_token: Optional[str] = None,
25
+ ):
26
+ super().__init__(
27
+ sandbox_id,
28
+ timeout,
29
+ base_url,
30
+ bearer_token,
31
+ SandboxType.BROWSER,
32
+ )
33
+
34
+ def browser_close(self):
35
+ return self.call_tool("browser_close", {})
36
+
37
+ def browser_resize(self, width: int, height: int):
38
+ return self.call_tool(
39
+ "browser_resize",
40
+ {"width": width, "height": height},
41
+ )
42
+
43
+ def browser_console_messages(self):
44
+ return self.call_tool("browser_console_messages", {})
45
+
46
+ def browser_handle_dialog(self, accept: bool, prompt_text: str = ""):
47
+ return self.call_tool(
48
+ "browser_handle_dialog",
49
+ {"accept": accept, "promptText": prompt_text},
50
+ )
51
+
52
+ def browser_file_upload(self, paths: list):
53
+ return self.call_tool("browser_file_upload", {"paths": paths})
54
+
55
+ def browser_press_key(self, key: str):
56
+ return self.call_tool("browser_press_key", {"key": key})
57
+
58
+ def browser_navigate(self, url: str):
59
+ return self.call_tool("browser_navigate", {"url": url})
60
+
61
+ def browser_navigate_back(self):
62
+ return self.call_tool("browser_navigate_back", {})
63
+
64
+ def browser_navigate_forward(self):
65
+ return self.call_tool("browser_navigate_forward", {})
66
+
67
+ def browser_network_requests(self):
68
+ return self.call_tool("browser_network_requests", {})
69
+
70
+ def browser_pdf_save(self, filename: str = ""):
71
+ return self.call_tool("browser_pdf_save", {"filename": filename})
72
+
73
+ def browser_take_screenshot(
74
+ self,
75
+ raw: bool = False,
76
+ filename: str = "",
77
+ element: str = "",
78
+ ref: str = "",
79
+ ):
80
+ return self.call_tool(
81
+ "browser_take_screenshot",
82
+ {
83
+ "raw": raw,
84
+ "filename": filename,
85
+ "element": element,
86
+ "ref": ref,
87
+ },
88
+ )
89
+
90
+ def browser_snapshot(self):
91
+ return self.call_tool("browser_snapshot", {})
92
+
93
+ def browser_click(self, element: str, ref: str):
94
+ return self.call_tool(
95
+ "browser_click",
96
+ {"element": element, "ref": ref},
97
+ )
98
+
99
+ def browser_drag(
100
+ self,
101
+ start_element: str,
102
+ start_ref: str,
103
+ end_element: str,
104
+ end_ref: str,
105
+ ):
106
+ return self.call_tool(
107
+ "browser_drag",
108
+ {
109
+ "startElement": start_element,
110
+ "startRef": start_ref,
111
+ "endElement": end_element,
112
+ "endRef": end_ref,
113
+ },
114
+ )
115
+
116
+ def browser_hover(self, element: str, ref: str):
117
+ return self.call_tool(
118
+ "browser_hover",
119
+ {"element": element, "ref": ref},
120
+ )
121
+
122
+ def browser_type(
123
+ self,
124
+ element: str,
125
+ ref: str,
126
+ text: str,
127
+ submit: bool = False,
128
+ slowly: bool = False,
129
+ ):
130
+ return self.call_tool(
131
+ "browser_type",
132
+ {
133
+ "element": element,
134
+ "ref": ref,
135
+ "text": text,
136
+ "submit": submit,
137
+ "slowly": slowly,
138
+ },
139
+ )
140
+
141
+ def browser_select_option(self, element: str, ref: str, values: list):
142
+ return self.call_tool(
143
+ "browser_select_option",
144
+ {
145
+ "element": element,
146
+ "ref": ref,
147
+ "values": values,
148
+ },
149
+ )
150
+
151
+ def browser_tab_list(self):
152
+ return self.call_tool("browser_tab_list", {})
153
+
154
+ def browser_tab_new(self, url: str = ""):
155
+ return self.call_tool("browser_tab_new", {"url": url})
156
+
157
+ def browser_tab_select(self, index: int):
158
+ return self.call_tool("browser_tab_select", {"index": index})
159
+
160
+ def browser_tab_close(self, index: int = None):
161
+ return self.call_tool("browser_tab_close", {"index": index})
162
+
163
+ def browser_wait_for(
164
+ self,
165
+ time: float = None,
166
+ text: str = None,
167
+ text_gone: str = None,
168
+ ):
169
+ return self.call_tool(
170
+ "browser_wait_for",
171
+ {
172
+ "time": time,
173
+ "text": text,
174
+ "textGone": text_gone,
175
+ },
176
+ )
File without changes
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ from typing import Optional
3
+
4
+ from ...registry import SandboxRegistry
5
+ from ...enums import SandboxType
6
+ from ...box.sandbox import Sandbox
7
+
8
+
9
+ @SandboxRegistry.register(
10
+ "",
11
+ sandbox_type=SandboxType.DUMMY,
12
+ security_level="low",
13
+ timeout=30,
14
+ description="Dummy Sandbox",
15
+ )
16
+ class DummySandbox(Sandbox):
17
+ def __init__(
18
+ self,
19
+ sandbox_id: Optional[str] = None,
20
+ timeout: int = 3000,
21
+ base_url: Optional[str] = None,
22
+ bearer_token: Optional[str] = None,
23
+ sandbox_type: SandboxType = SandboxType.DUMMY,
24
+ ):
25
+ self._sandbox_id = sandbox_id
26
+ self.sandbox_type = sandbox_type
File without changes