agentscope-runtime 0.2.0b2__py3-none-any.whl → 1.0.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.
Files changed (183) hide show
  1. agentscope_runtime/adapters/__init__.py +0 -0
  2. agentscope_runtime/adapters/agentscope/__init__.py +0 -0
  3. agentscope_runtime/adapters/agentscope/long_term_memory/__init__.py +6 -0
  4. agentscope_runtime/adapters/agentscope/long_term_memory/_long_term_memory_adapter.py +258 -0
  5. agentscope_runtime/adapters/agentscope/memory/__init__.py +6 -0
  6. agentscope_runtime/adapters/agentscope/memory/_memory_adapter.py +152 -0
  7. agentscope_runtime/adapters/agentscope/message.py +535 -0
  8. agentscope_runtime/adapters/agentscope/stream.py +474 -0
  9. agentscope_runtime/adapters/agentscope/tool/__init__.py +9 -0
  10. agentscope_runtime/adapters/agentscope/tool/sandbox_tool.py +69 -0
  11. agentscope_runtime/adapters/agentscope/tool/tool.py +233 -0
  12. agentscope_runtime/adapters/autogen/__init__.py +0 -0
  13. agentscope_runtime/adapters/autogen/tool/__init__.py +7 -0
  14. agentscope_runtime/adapters/autogen/tool/tool.py +211 -0
  15. agentscope_runtime/adapters/text/__init__.py +0 -0
  16. agentscope_runtime/adapters/text/stream.py +29 -0
  17. agentscope_runtime/common/collections/redis_mapping.py +4 -1
  18. agentscope_runtime/common/container_clients/fc_client.py +855 -0
  19. agentscope_runtime/common/utils/__init__.py +0 -0
  20. agentscope_runtime/common/utils/lazy_loader.py +57 -0
  21. agentscope_runtime/engine/__init__.py +25 -18
  22. agentscope_runtime/engine/app/agent_app.py +161 -91
  23. agentscope_runtime/engine/app/base_app.py +4 -118
  24. agentscope_runtime/engine/constant.py +8 -0
  25. agentscope_runtime/engine/deployers/__init__.py +8 -0
  26. agentscope_runtime/engine/deployers/adapter/__init__.py +2 -0
  27. agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +0 -21
  28. agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +28 -9
  29. agentscope_runtime/engine/deployers/adapter/responses/__init__.py +2 -0
  30. agentscope_runtime/engine/deployers/adapter/responses/response_api_adapter_utils.py +5 -2
  31. agentscope_runtime/engine/deployers/adapter/responses/response_api_protocol_adapter.py +1 -1
  32. agentscope_runtime/engine/deployers/agentrun_deployer.py +2541 -0
  33. agentscope_runtime/engine/deployers/cli_fc_deploy.py +1 -1
  34. agentscope_runtime/engine/deployers/kubernetes_deployer.py +9 -21
  35. agentscope_runtime/engine/deployers/local_deployer.py +47 -74
  36. agentscope_runtime/engine/deployers/modelstudio_deployer.py +216 -50
  37. agentscope_runtime/engine/deployers/utils/app_runner_utils.py +29 -0
  38. agentscope_runtime/engine/deployers/utils/detached_app.py +510 -0
  39. agentscope_runtime/engine/deployers/utils/docker_image_utils/__init__.py +1 -1
  40. agentscope_runtime/engine/deployers/utils/docker_image_utils/dockerfile_generator.py +1 -1
  41. agentscope_runtime/engine/deployers/utils/docker_image_utils/{runner_image_factory.py → image_factory.py} +121 -61
  42. agentscope_runtime/engine/deployers/utils/package.py +693 -0
  43. agentscope_runtime/engine/deployers/utils/service_utils/__init__.py +0 -5
  44. agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py +256 -282
  45. agentscope_runtime/engine/deployers/utils/service_utils/fastapi_templates.py +2 -4
  46. agentscope_runtime/engine/deployers/utils/service_utils/process_manager.py +23 -1
  47. agentscope_runtime/engine/deployers/utils/templates/app_main.py.j2 +84 -0
  48. agentscope_runtime/engine/deployers/utils/templates/runner_main.py.j2 +95 -0
  49. agentscope_runtime/engine/deployers/utils/{service_utils → templates}/standalone_main.py.j2 +0 -45
  50. agentscope_runtime/engine/deployers/utils/wheel_packager.py +119 -18
  51. agentscope_runtime/engine/helpers/runner.py +40 -0
  52. agentscope_runtime/engine/runner.py +170 -130
  53. agentscope_runtime/engine/schemas/agent_schemas.py +114 -3
  54. agentscope_runtime/engine/schemas/modelstudio_llm.py +4 -2
  55. agentscope_runtime/engine/schemas/oai_llm.py +23 -23
  56. agentscope_runtime/engine/schemas/response_api.py +65 -0
  57. agentscope_runtime/engine/schemas/session.py +24 -0
  58. agentscope_runtime/engine/services/__init__.py +0 -9
  59. agentscope_runtime/engine/services/agent_state/__init__.py +16 -0
  60. agentscope_runtime/engine/services/agent_state/redis_state_service.py +113 -0
  61. agentscope_runtime/engine/services/agent_state/state_service.py +179 -0
  62. agentscope_runtime/engine/services/memory/__init__.py +24 -0
  63. agentscope_runtime/engine/services/{mem0_memory_service.py → memory/mem0_memory_service.py} +17 -13
  64. agentscope_runtime/engine/services/{memory_service.py → memory/memory_service.py} +28 -7
  65. agentscope_runtime/engine/services/{redis_memory_service.py → memory/redis_memory_service.py} +1 -1
  66. agentscope_runtime/engine/services/{reme_personal_memory_service.py → memory/reme_personal_memory_service.py} +9 -6
  67. agentscope_runtime/engine/services/{reme_task_memory_service.py → memory/reme_task_memory_service.py} +2 -2
  68. agentscope_runtime/engine/services/{tablestore_memory_service.py → memory/tablestore_memory_service.py} +12 -18
  69. agentscope_runtime/engine/services/sandbox/__init__.py +13 -0
  70. agentscope_runtime/engine/services/{sandbox_service.py → sandbox/sandbox_service.py} +86 -71
  71. agentscope_runtime/engine/services/session_history/__init__.py +23 -0
  72. agentscope_runtime/engine/services/{redis_session_history_service.py → session_history/redis_session_history_service.py} +3 -2
  73. agentscope_runtime/engine/services/{session_history_service.py → session_history/session_history_service.py} +44 -34
  74. agentscope_runtime/engine/services/{tablestore_session_history_service.py → session_history/tablestore_session_history_service.py} +14 -19
  75. agentscope_runtime/engine/services/utils/tablestore_service_utils.py +2 -2
  76. agentscope_runtime/engine/tracing/base.py +10 -9
  77. agentscope_runtime/engine/tracing/message_util.py +1 -1
  78. agentscope_runtime/engine/tracing/tracing_util.py +7 -2
  79. agentscope_runtime/sandbox/__init__.py +10 -2
  80. agentscope_runtime/sandbox/box/agentbay/__init__.py +4 -0
  81. agentscope_runtime/sandbox/box/agentbay/agentbay_sandbox.py +559 -0
  82. agentscope_runtime/sandbox/box/base/base_sandbox.py +12 -0
  83. agentscope_runtime/sandbox/box/browser/browser_sandbox.py +115 -11
  84. agentscope_runtime/sandbox/box/cloud/__init__.py +4 -0
  85. agentscope_runtime/sandbox/box/cloud/cloud_sandbox.py +254 -0
  86. agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +66 -0
  87. agentscope_runtime/sandbox/box/gui/gui_sandbox.py +42 -0
  88. agentscope_runtime/sandbox/box/mobile/__init__.py +4 -0
  89. agentscope_runtime/sandbox/box/mobile/box/__init__.py +0 -0
  90. agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +216 -0
  91. agentscope_runtime/sandbox/box/training_box/training_box.py +2 -2
  92. agentscope_runtime/sandbox/client/http_client.py +1 -0
  93. agentscope_runtime/sandbox/enums.py +2 -0
  94. agentscope_runtime/sandbox/manager/sandbox_manager.py +18 -2
  95. agentscope_runtime/sandbox/manager/server/app.py +12 -0
  96. agentscope_runtime/sandbox/manager/server/config.py +19 -0
  97. agentscope_runtime/sandbox/model/manager_config.py +79 -2
  98. agentscope_runtime/sandbox/utils.py +0 -18
  99. agentscope_runtime/tools/RAGs/__init__.py +0 -0
  100. agentscope_runtime/tools/RAGs/modelstudio_rag.py +377 -0
  101. agentscope_runtime/tools/RAGs/modelstudio_rag_lite.py +219 -0
  102. agentscope_runtime/tools/__init__.py +119 -0
  103. agentscope_runtime/tools/_constants.py +18 -0
  104. agentscope_runtime/tools/alipay/__init__.py +4 -0
  105. agentscope_runtime/tools/alipay/base.py +334 -0
  106. agentscope_runtime/tools/alipay/payment.py +835 -0
  107. agentscope_runtime/tools/alipay/subscribe.py +551 -0
  108. agentscope_runtime/tools/base.py +264 -0
  109. agentscope_runtime/tools/cli/__init__.py +0 -0
  110. agentscope_runtime/tools/cli/modelstudio_mcp_server.py +78 -0
  111. agentscope_runtime/tools/generations/__init__.py +75 -0
  112. agentscope_runtime/tools/generations/async_image_to_video.py +350 -0
  113. agentscope_runtime/tools/generations/async_image_to_video_wan25.py +366 -0
  114. agentscope_runtime/tools/generations/async_speech_to_video.py +422 -0
  115. agentscope_runtime/tools/generations/async_text_to_video.py +320 -0
  116. agentscope_runtime/tools/generations/async_text_to_video_wan25.py +334 -0
  117. agentscope_runtime/tools/generations/image_edit.py +208 -0
  118. agentscope_runtime/tools/generations/image_edit_wan25.py +193 -0
  119. agentscope_runtime/tools/generations/image_generation.py +202 -0
  120. agentscope_runtime/tools/generations/image_generation_wan25.py +201 -0
  121. agentscope_runtime/tools/generations/image_style_repaint.py +208 -0
  122. agentscope_runtime/tools/generations/image_to_video.py +233 -0
  123. agentscope_runtime/tools/generations/qwen_image_edit.py +205 -0
  124. agentscope_runtime/tools/generations/qwen_image_generation.py +214 -0
  125. agentscope_runtime/tools/generations/qwen_text_to_speech.py +154 -0
  126. agentscope_runtime/tools/generations/speech_to_text.py +260 -0
  127. agentscope_runtime/tools/generations/speech_to_video.py +314 -0
  128. agentscope_runtime/tools/generations/text_to_video.py +221 -0
  129. agentscope_runtime/tools/mcp_wrapper.py +215 -0
  130. agentscope_runtime/tools/realtime_clients/__init__.py +13 -0
  131. agentscope_runtime/tools/realtime_clients/asr_client.py +27 -0
  132. agentscope_runtime/tools/realtime_clients/azure_asr_client.py +195 -0
  133. agentscope_runtime/tools/realtime_clients/azure_tts_client.py +383 -0
  134. agentscope_runtime/tools/realtime_clients/modelstudio_asr_client.py +151 -0
  135. agentscope_runtime/tools/realtime_clients/modelstudio_tts_client.py +199 -0
  136. agentscope_runtime/tools/realtime_clients/realtime_tool.py +55 -0
  137. agentscope_runtime/tools/realtime_clients/tts_client.py +33 -0
  138. agentscope_runtime/tools/searches/__init__.py +3 -0
  139. agentscope_runtime/tools/searches/modelstudio_search.py +877 -0
  140. agentscope_runtime/tools/searches/modelstudio_search_lite.py +310 -0
  141. agentscope_runtime/tools/utils/__init__.py +0 -0
  142. agentscope_runtime/tools/utils/api_key_util.py +45 -0
  143. agentscope_runtime/tools/utils/crypto_utils.py +99 -0
  144. agentscope_runtime/tools/utils/mcp_util.py +35 -0
  145. agentscope_runtime/version.py +1 -1
  146. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/METADATA +234 -165
  147. agentscope_runtime-1.0.0b1.dist-info/RECORD +240 -0
  148. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/entry_points.txt +1 -0
  149. agentscope_runtime/engine/agents/__init__.py +0 -2
  150. agentscope_runtime/engine/agents/agentscope_agent.py +0 -488
  151. agentscope_runtime/engine/agents/agno_agent.py +0 -220
  152. agentscope_runtime/engine/agents/autogen_agent.py +0 -250
  153. agentscope_runtime/engine/agents/base_agent.py +0 -29
  154. agentscope_runtime/engine/agents/langgraph_agent.py +0 -59
  155. agentscope_runtime/engine/agents/utils.py +0 -53
  156. agentscope_runtime/engine/deployers/utils/package_project_utils.py +0 -1163
  157. agentscope_runtime/engine/deployers/utils/service_utils/service_config.py +0 -75
  158. agentscope_runtime/engine/deployers/utils/service_utils/service_factory.py +0 -220
  159. agentscope_runtime/engine/helpers/helper.py +0 -179
  160. agentscope_runtime/engine/schemas/context.py +0 -54
  161. agentscope_runtime/engine/services/context_manager.py +0 -164
  162. agentscope_runtime/engine/services/environment_manager.py +0 -50
  163. agentscope_runtime/engine/services/manager.py +0 -174
  164. agentscope_runtime/engine/services/rag_service.py +0 -195
  165. agentscope_runtime/engine/services/tablestore_rag_service.py +0 -143
  166. agentscope_runtime/sandbox/tools/__init__.py +0 -12
  167. agentscope_runtime/sandbox/tools/base/__init__.py +0 -8
  168. agentscope_runtime/sandbox/tools/base/tool.py +0 -52
  169. agentscope_runtime/sandbox/tools/browser/__init__.py +0 -57
  170. agentscope_runtime/sandbox/tools/browser/tool.py +0 -597
  171. agentscope_runtime/sandbox/tools/filesystem/__init__.py +0 -32
  172. agentscope_runtime/sandbox/tools/filesystem/tool.py +0 -319
  173. agentscope_runtime/sandbox/tools/function_tool.py +0 -321
  174. agentscope_runtime/sandbox/tools/gui/__init__.py +0 -7
  175. agentscope_runtime/sandbox/tools/gui/tool.py +0 -77
  176. agentscope_runtime/sandbox/tools/mcp_tool.py +0 -195
  177. agentscope_runtime/sandbox/tools/sandbox_tool.py +0 -104
  178. agentscope_runtime/sandbox/tools/tool.py +0 -238
  179. agentscope_runtime/sandbox/tools/utils.py +0 -68
  180. agentscope_runtime-0.2.0b2.dist-info/RECORD +0 -183
  181. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/WHEEL +0 -0
  182. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/licenses/LICENSE +0 -0
  183. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/top_level.txt +0 -0
@@ -1,31 +1,34 @@
1
1
  # -*- coding: utf-8 -*-
2
- # pylint: disable=too-many-branches
3
- from typing import List
2
+ # mypy: disable-error-code="list-item"
3
+ from typing import List, Optional
4
4
 
5
- from ...sandbox.enums import SandboxType
6
- from ...sandbox.manager import SandboxManager
7
- from ...sandbox.registry import SandboxRegistry
8
- from ...sandbox.tools.mcp_tool import MCPTool
9
- from ...sandbox.tools.sandbox_tool import SandboxTool
10
- from ...sandbox.tools.function_tool import FunctionTool
11
- from ...engine.services.base import ServiceWithLifecycleManager
5
+ from ....sandbox.enums import SandboxType
6
+ from ....sandbox.manager import SandboxManager
7
+ from ....sandbox.registry import SandboxRegistry
8
+ from ....engine.services.base import ServiceWithLifecycleManager
12
9
 
13
10
 
14
11
  class SandboxService(ServiceWithLifecycleManager):
15
12
  def __init__(self, base_url=None, bearer_token=None):
16
- self.manager_api = SandboxManager(
17
- base_url=base_url,
18
- bearer_token=bearer_token,
19
- )
20
-
13
+ self.manager_api = None
21
14
  self.base_url = base_url
22
15
  self.bearer_token = bearer_token
16
+ self._health = False
23
17
 
24
18
  async def start(self) -> None:
25
- pass
19
+ if self.manager_api is None:
20
+ self.manager_api = SandboxManager(
21
+ base_url=self.base_url,
22
+ bearer_token=self.bearer_token,
23
+ )
24
+ self._health = True
26
25
 
27
26
  async def stop(self) -> None:
28
27
  # Release all environments
28
+ if self.manager_api is None:
29
+ self._health = False
30
+ return
31
+
29
32
  session_keys = self.manager_api.list_session_keys()
30
33
 
31
34
  if session_keys:
@@ -39,15 +42,16 @@ class SandboxService(ServiceWithLifecycleManager):
39
42
  # Embedded mode
40
43
  self.manager_api.cleanup()
41
44
 
45
+ self.manager_api = None
46
+
42
47
  async def health(self) -> bool:
43
- return True
48
+ return self._health
44
49
 
45
50
  def connect(
46
51
  self,
47
- session_id,
48
- user_id,
49
- env_types=None,
50
- tools=None,
52
+ session_id: str,
53
+ user_id: Optional[str] = None,
54
+ sandbox_types=None,
51
55
  ) -> List:
52
56
  # Create a composite key
53
57
  session_ctx_id = self._create_session_ctx_id(session_id, user_id)
@@ -62,49 +66,32 @@ class SandboxService(ServiceWithLifecycleManager):
62
66
  # Create a new environment
63
67
  return self._create_new_environment(
64
68
  session_ctx_id,
65
- env_types,
66
- tools,
69
+ sandbox_types,
67
70
  )
68
71
 
69
72
  def _create_new_environment(
70
73
  self,
71
74
  session_ctx_id: str,
72
- env_types=None,
73
- tools=None,
75
+ sandbox_types: Optional[List[str]] = None,
74
76
  ):
75
- if tools:
76
- for tool in tools:
77
- if not isinstance(tool, (SandboxTool, FunctionTool, MCPTool)):
78
- raise ValueError(
79
- "tools must be instances of SandboxTool, "
80
- "FunctionTool, or MCPTool",
81
- )
82
-
83
- if env_types is None:
84
- assert (
85
- tools is not None
86
- ), "tools must be specified when env_types is not set"
87
-
88
- if tools:
89
- tool_env_types = set()
90
- for tool in tools:
91
- tool_env_types.add(tool.sandbox_type)
92
- if env_types is None:
93
- env_types = []
94
-
95
- env_types = set(env_types) | tool_env_types
77
+ if sandbox_types is None:
78
+ sandbox_types = [SandboxType.BASE]
96
79
 
97
80
  sandboxes = []
98
- for env_type in env_types:
81
+ for env_type in sandbox_types:
99
82
  if env_type is None:
100
83
  continue
101
84
 
102
85
  box_type = SandboxType(env_type)
103
86
 
104
- box_id = self.manager_api.create_from_pool(
105
- sandbox_type=box_type.value,
106
- meta={"session_ctx_id": session_ctx_id},
107
- )
87
+ if box_type != SandboxType.AGENTBAY:
88
+ box_id = self.manager_api.create_from_pool(
89
+ sandbox_type=box_type.value,
90
+ meta={"session_ctx_id": session_ctx_id},
91
+ )
92
+ else:
93
+ box_id = None
94
+
108
95
  box_cls = SandboxRegistry.get_classes_by_type(box_type)
109
96
 
110
97
  box = box_cls(
@@ -119,32 +106,38 @@ class SandboxService(ServiceWithLifecycleManager):
119
106
  # Embedded mode
120
107
  box.manager_api = self.manager_api
121
108
 
122
- # Add MCP to the sandbox
123
- server_config_list = []
124
- if tools:
125
- for tool in tools:
126
- if isinstance(tool, MCPTool) and SandboxType(
127
- tool.sandbox_type,
128
- ) == SandboxType(box_type):
129
- server_config_list.append(tool.server_configs)
130
- if server_config_list:
131
- server_configs = {"mcpServers": {}}
132
- for server_config in server_config_list:
133
- if (
134
- server_config is not None
135
- and "mcpServers" in server_config
136
- ):
137
- server_configs["mcpServers"].update(
138
- server_config["mcpServers"],
139
- )
140
- box.add_mcp_servers(server_configs, overwrite=False)
141
-
142
109
  sandboxes.append(box)
143
110
  return sandboxes
144
111
 
145
112
  def _connect_existing_environment(self, env_ids: List[str]):
146
113
  boxes = []
147
114
  for env_id in env_ids:
115
+ # Check if this is an AgentBay session ID
116
+ if self._is_agentbay_session_id(env_id):
117
+ try:
118
+ from ....sandbox.box.agentbay.agentbay_sandbox import (
119
+ AgentbaySandbox,
120
+ )
121
+
122
+ # Connect to existing AgentBay session
123
+ sandbox = AgentbaySandbox(
124
+ sandbox_id=env_id,
125
+ base_url=self.base_url,
126
+ bearer_token=self.bearer_token,
127
+ sandbox_type=SandboxType.AGENTBAY,
128
+ )
129
+ boxes.append(sandbox)
130
+ continue
131
+ except Exception as e:
132
+ import logging
133
+
134
+ logger = logging.getLogger(__name__)
135
+ logger.error(
136
+ f"Failed to connect to AgentBay session {env_id}: {e}",
137
+ )
138
+ continue
139
+
140
+ # Standard sandbox connection
148
141
  info = self.manager_api.get_info(env_id)
149
142
  version = info.get("version", "")
150
143
 
@@ -174,17 +167,39 @@ class SandboxService(ServiceWithLifecycleManager):
174
167
 
175
168
  return boxes
176
169
 
177
- def release(self, session_id, user_id):
170
+ def _is_agentbay_session_id(self, session_id: str) -> bool:
171
+ """
172
+ Check if a session ID belongs to AgentBay.
173
+
174
+ AgentBay session IDs typically start with 'session-' prefix.
175
+
176
+ Args:
177
+ session_id: Session ID to check
178
+
179
+ Returns:
180
+ True if this appears to be an AgentBay session ID
181
+ """
182
+ return session_id.startswith("session-")
183
+
184
+ def release(self, session_id, user_id=None):
178
185
  session_ctx_id = self._create_session_ctx_id(session_id, user_id)
179
186
 
180
187
  env_ids = self.manager_api.get_session_mapping(session_ctx_id)
181
188
 
182
189
  if env_ids:
183
190
  for env_id in env_ids:
191
+ # Check if this is an AgentBay session
192
+ if self._is_agentbay_session_id(env_id):
193
+ # AgentBay sessions are cleaned up automatically
194
+ # when the sandbox object is destroyed
195
+ continue
196
+ # Standard sandbox release
184
197
  self.manager_api.release(env_id)
185
198
 
186
199
  return True
187
200
 
188
201
  def _create_session_ctx_id(self, session_id, user_id):
189
202
  # Create a composite key from session_id and user_id
203
+ if user_id is None:
204
+ return session_id
190
205
  return f"{session_id}_{user_id}"
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ from typing import TYPE_CHECKING
3
+ from ....common.utils.lazy_loader import install_lazy_loader
4
+
5
+ if TYPE_CHECKING:
6
+ from .session_history_service import (
7
+ SessionHistoryService,
8
+ InMemorySessionHistoryService,
9
+ )
10
+ from .redis_session_history_service import RedisSessionHistoryService
11
+ from .tablestore_session_history_service import (
12
+ TablestoreSessionHistoryService,
13
+ )
14
+
15
+ install_lazy_loader(
16
+ globals(),
17
+ {
18
+ "SessionHistoryService": ".session_history_service",
19
+ "InMemorySessionHistoryService": ".session_history_service",
20
+ "RedisSessionHistoryService": ".redis_session_history_service",
21
+ "TablestoreSessionHistoryService": ".tablestore_session_history_service", # noqa
22
+ },
23
+ )
@@ -5,8 +5,9 @@ from typing import Optional, Dict, Any, List, Union
5
5
 
6
6
  import redis.asyncio as aioredis
7
7
 
8
- from .session_history_service import SessionHistoryService, Session
9
- from ..schemas.agent_schemas import Message
8
+ from .session_history_service import SessionHistoryService
9
+ from ...schemas.session import Session
10
+ from ...schemas.agent_schemas import Message
10
11
 
11
12
 
12
13
  class RedisSessionHistoryService(SessionHistoryService):
@@ -4,28 +4,9 @@ import uuid
4
4
  from abc import abstractmethod
5
5
  from typing import List, Dict, Optional, Union, Any
6
6
 
7
- from pydantic import BaseModel
8
-
9
- from .base import ServiceWithLifecycleManager
10
- from ..schemas.agent_schemas import Message
11
-
12
-
13
- class Session(BaseModel):
14
- """Represents a single conversation session.
15
-
16
- A session contains the history of a conversation, including all
17
- messages, and is uniquely identified by its ID.
18
-
19
- Attributes:
20
- id: The unique identifier for the session.
21
- user_id: The identifier of the user who owns the session.
22
- messages: A list of messages formatted for Agent response
23
-
24
- """
25
-
26
- id: str
27
- user_id: str
28
- messages: List[Union[Message, Dict[str, Any]]] = []
7
+ from ..base import ServiceWithLifecycleManager
8
+ from ...schemas.session import Session
9
+ from ...schemas.agent_schemas import Message
29
10
 
30
11
 
31
12
  class SessionHistoryService(ServiceWithLifecycleManager):
@@ -42,9 +23,6 @@ class SessionHistoryService(ServiceWithLifecycleManager):
42
23
  async def stop(self) -> None:
43
24
  pass
44
25
 
45
- async def health(self) -> bool:
46
- return True
47
-
48
26
  @abstractmethod
49
27
  async def create_session(
50
28
  self,
@@ -124,13 +102,31 @@ class InMemorySessionHistoryService(SessionHistoryService):
124
102
  for development, testing, and scenarios where persistence is not required.
125
103
 
126
104
  Attributes:
127
- _sessions: A dictionary holding all session objects, keyed by user ID
105
+ _store: A dictionary holding all session objects, keyed by user ID
128
106
  and then by session ID.
129
107
  """
130
108
 
131
109
  def __init__(self) -> None:
132
110
  """Initializes the InMemorySessionHistoryService."""
133
- self._sessions: Dict[str, Dict[str, Session]] = {}
111
+ self._store: Optional[Dict[str, Dict[str, Session]]] = None
112
+ self._health = False
113
+
114
+ async def start(self) -> None:
115
+ """Initialize the in-memory store."""
116
+ if self._store is None:
117
+ self._store = {}
118
+ self._health = True
119
+
120
+ async def stop(self) -> None:
121
+ """Clear all in-memory data."""
122
+ if self._store is not None:
123
+ self._store.clear()
124
+ self._store = None
125
+ self._health = False
126
+
127
+ async def health(self) -> bool:
128
+ """Service health check: always True."""
129
+ return self._health
134
130
 
135
131
  async def create_session(
136
132
  self,
@@ -146,13 +142,16 @@ class InMemorySessionHistoryService(SessionHistoryService):
146
142
  Returns:
147
143
  A deep copy of the newly created Session object.
148
144
  """
145
+ if self._store is None:
146
+ raise RuntimeError("Service not started")
147
+
149
148
  session_id = (
150
149
  session_id.strip()
151
150
  if session_id and session_id.strip()
152
151
  else str(uuid.uuid4())
153
152
  )
154
153
  session = Session(id=session_id, user_id=user_id)
155
- self._sessions.setdefault(user_id, {})[session_id] = session
154
+ self._store.setdefault(user_id, {})[session_id] = session
156
155
  return copy.deepcopy(session)
157
156
 
158
157
  async def get_session(
@@ -169,11 +168,13 @@ class InMemorySessionHistoryService(SessionHistoryService):
169
168
  Returns:
170
169
  A deep copy of the Session object if found, otherwise None.
171
170
  """
171
+ if self._store is None:
172
+ raise RuntimeError("Service not started")
172
173
 
173
- session = self._sessions.get(user_id, {}).get(session_id)
174
+ session = self._store.get(user_id, {}).get(session_id)
174
175
  if not session:
175
176
  session = Session(id=session_id, user_id=user_id)
176
- self._sessions.setdefault(user_id, {})[session_id] = session
177
+ self._store.setdefault(user_id, {})[session_id] = session
177
178
  return copy.deepcopy(session) if session else None
178
179
 
179
180
  async def delete_session(self, user_id: str, session_id: str) -> None:
@@ -185,8 +186,11 @@ class InMemorySessionHistoryService(SessionHistoryService):
185
186
  user_id: The identifier for the user.
186
187
  session_id: The identifier for the session to delete.
187
188
  """
188
- if user_id in self._sessions and session_id in self._sessions[user_id]:
189
- del self._sessions[user_id][session_id]
189
+ if self._store is None:
190
+ raise RuntimeError("Service not started")
191
+
192
+ if user_id in self._store and session_id in self._store[user_id]:
193
+ del self._store[user_id][session_id]
190
194
 
191
195
  async def list_sessions(self, user_id: str) -> list[Session]:
192
196
  """Lists all sessions for a given user.
@@ -200,7 +204,10 @@ class InMemorySessionHistoryService(SessionHistoryService):
200
204
  Returns:
201
205
  A list of Session objects belonging to the user, without history.
202
206
  """
203
- user_sessions = self._sessions.get(user_id, {})
207
+ if self._store is None:
208
+ raise RuntimeError("Service not started")
209
+
210
+ user_sessions = self._store.get(user_id, {})
204
211
  # Return sessions without their potentially large history for
205
212
  # efficiency.
206
213
  sessions_without_history = []
@@ -232,6 +239,9 @@ class InMemorySessionHistoryService(SessionHistoryService):
232
239
  message: The message or list of messages to append to the
233
240
  session's history.
234
241
  """
242
+ if self._store is None:
243
+ raise RuntimeError("Service not started")
244
+
235
245
  # Normalize to list
236
246
  if not isinstance(message, list):
237
247
  message = [message]
@@ -245,7 +255,7 @@ class InMemorySessionHistoryService(SessionHistoryService):
245
255
  session.messages.extend(norm_message)
246
256
 
247
257
  # update the in memory copy
248
- storage_session = self._sessions.get(session.user_id, {}).get(
258
+ storage_session = self._store.get(session.user_id, {}).get(
249
259
  session.id,
250
260
  )
251
261
  if storage_session:
@@ -4,25 +4,20 @@ import asyncio
4
4
  import uuid
5
5
  from typing import Any, Dict, List, Optional, Union
6
6
 
7
- try:
8
- import tablestore
9
- from tablestore import AsyncOTSClient as AsyncTablestoreClient
10
- from tablestore_for_agent_memory.base.base_memory_store import (
11
- Session as TablestoreSession,
12
- )
13
- from tablestore_for_agent_memory.base.common import MetaType, Order
14
- from tablestore_for_agent_memory.memory.async_memory_store import (
15
- AsyncMemoryStore,
16
- )
17
- except ImportError as e:
18
- raise ImportError(
19
- "aliyun_tablestore is not available. "
20
- "Please run pip install agentscope-runtime[aliyun_tablestore_ext]",
21
- ) from e
22
-
23
- from ..schemas.agent_schemas import Message
24
- from .session_history_service import Session, SessionHistoryService
25
- from .utils.tablestore_service_utils import (
7
+ import tablestore
8
+ from tablestore import AsyncOTSClient as AsyncTablestoreClient
9
+ from tablestore_for_agent_memory.base.base_memory_store import (
10
+ Session as TablestoreSession,
11
+ )
12
+ from tablestore_for_agent_memory.base.common import MetaType, Order
13
+ from tablestore_for_agent_memory.memory.async_memory_store import (
14
+ AsyncMemoryStore,
15
+ )
16
+
17
+ from .session_history_service import SessionHistoryService
18
+ from ...schemas.agent_schemas import Message
19
+ from ...schemas.session import Session
20
+ from ..utils.tablestore_service_utils import (
26
21
  convert_message_to_tablestore_message,
27
22
  convert_tablestore_session_to_session,
28
23
  tablestore_log,
@@ -17,8 +17,8 @@ from tablestore_for_agent_memory.base.base_memory_store import (
17
17
  Session as TablestoreSession,
18
18
  )
19
19
 
20
- from ...schemas.agent_schemas import ContentType, MessageType
21
- from ..session_history_service import Message, Session
20
+ from ...schemas.agent_schemas import ContentType, MessageType, Message
21
+ from ...schemas.session import Session
22
22
 
23
23
 
24
24
  def create_tablestore_client(
@@ -82,7 +82,6 @@ class TracerHandler(ABC):
82
82
  raise NotImplementedError("Subclasses must implement on_error method")
83
83
 
84
84
 
85
- # 新增基础的LogHandler类
86
85
  class BaseLogHandler(TracerHandler):
87
86
  """Basic log handler implementation using Python's logging module."""
88
87
 
@@ -166,14 +165,16 @@ class BaseLogHandler(TracerHandler):
166
165
 
167
166
  class Tracer:
168
167
  """
169
- Tracer class for logging events
170
- usage:
171
- with tracer.event(TraceType.LLM, payload) as event:
172
- event.log("message")
173
- ""...logic here...""
174
- end_payload = {xxx}
175
- # optional on_end call for additional payload and kwargs
176
- event.on_end(end_payload, if_success=True)
168
+ Tracer class for logging events.
169
+
170
+ Usage example::
171
+
172
+ with tracer.event(TraceType.LLM, payload) as event:
173
+ event.log("message")
174
+ # ...logic here...
175
+ end_payload = {"xxx": "value"}
176
+ # optional on_end call for additional payload and kwargs
177
+ event.on_end(end_payload, if_success=True)
177
178
  """
178
179
 
179
180
  def __init__(self, handlers: List[TracerHandler]):
@@ -13,7 +13,7 @@ from agentscope_runtime.engine.schemas.agent_schemas import (
13
13
  TextContent,
14
14
  )
15
15
 
16
- # Use OpenAI's ToolCall type instead of agentscope_bricks
16
+ # Use OpenAI's ToolCall type instead of agentscope_runtime
17
17
  ToolCall = ChoiceDeltaToolCall
18
18
 
19
19
 
@@ -26,7 +26,10 @@ class TracingUtil:
26
26
  """Set request id"""
27
27
  _user_request_id.set(value)
28
28
  if value:
29
- ctx = baggage.set_baggage("agentscope-bricks_request_id", value)
29
+ ctx = baggage.set_baggage(
30
+ "agentscope-runtime_request_id",
31
+ value,
32
+ )
30
33
  attach(ctx)
31
34
 
32
35
  TracingUtil.clear_common_attributes()
@@ -48,7 +51,9 @@ class TracingUtil:
48
51
  return request_id
49
52
 
50
53
  # Fallback to baggage for cross-thread scenarios
51
- request_id = baggage.get_baggage("agentscope-bricks_request_id")
54
+ request_id = baggage.get_baggage(
55
+ "agentscope-runtime_request_id",
56
+ )
52
57
  if request_id:
53
58
  return request_id
54
59
 
@@ -1,11 +1,16 @@
1
1
  # -*- coding: utf-8 -*-
2
- from .custom import *
2
+ # Explicitly import all Sandbox classes so their modules execute immediately.
3
+ # This ensures SandboxRegistry.register() runs at import time.
4
+ # Without this, lazy loading delays module import and types may not be
5
+ # registered.
3
6
  from .box.base.base_sandbox import BaseSandbox
4
7
  from .box.browser.browser_sandbox import BrowserSandbox
5
8
  from .box.filesystem.filesystem_sandbox import FilesystemSandbox
6
9
  from .box.gui.gui_sandbox import GuiSandbox
7
10
  from .box.training_box.training_box import TrainingSandbox
8
-
11
+ from .box.cloud.cloud_sandbox import CloudSandbox
12
+ from .box.mobile.mobile_sandbox import MobileSandbox
13
+ from .box.agentbay.agentbay_sandbox import AgentbaySandbox
9
14
 
10
15
  __all__ = [
11
16
  "BaseSandbox",
@@ -13,4 +18,7 @@ __all__ = [
13
18
  "FilesystemSandbox",
14
19
  "GuiSandbox",
15
20
  "TrainingSandbox",
21
+ "CloudSandbox",
22
+ "MobileSandbox",
23
+ "AgentbaySandbox",
16
24
  ]
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+ from .agentbay_sandbox import AgentbaySandbox
3
+
4
+ __all__ = ["AgentbaySandbox"]