agentscope-runtime 0.2.0b2__py3-none-any.whl → 1.0.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.
- agentscope_runtime/adapters/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/_long_term_memory_adapter.py +258 -0
- agentscope_runtime/adapters/agentscope/memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/memory/_memory_adapter.py +152 -0
- agentscope_runtime/adapters/agentscope/message.py +535 -0
- agentscope_runtime/adapters/agentscope/stream.py +506 -0
- agentscope_runtime/adapters/agentscope/tool/__init__.py +9 -0
- agentscope_runtime/adapters/agentscope/tool/sandbox_tool.py +69 -0
- agentscope_runtime/adapters/agentscope/tool/tool.py +233 -0
- agentscope_runtime/adapters/autogen/__init__.py +0 -0
- agentscope_runtime/adapters/autogen/tool/__init__.py +7 -0
- agentscope_runtime/adapters/autogen/tool/tool.py +211 -0
- agentscope_runtime/adapters/text/__init__.py +0 -0
- agentscope_runtime/adapters/text/stream.py +29 -0
- agentscope_runtime/common/collections/redis_mapping.py +4 -1
- agentscope_runtime/common/container_clients/fc_client.py +855 -0
- agentscope_runtime/common/utils/__init__.py +0 -0
- agentscope_runtime/common/utils/lazy_loader.py +57 -0
- agentscope_runtime/engine/__init__.py +25 -18
- agentscope_runtime/engine/app/agent_app.py +161 -91
- agentscope_runtime/engine/app/base_app.py +4 -118
- agentscope_runtime/engine/constant.py +8 -0
- agentscope_runtime/engine/deployers/__init__.py +8 -0
- agentscope_runtime/engine/deployers/adapter/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +0 -21
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +28 -9
- agentscope_runtime/engine/deployers/adapter/responses/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/responses/response_api_adapter_utils.py +5 -2
- agentscope_runtime/engine/deployers/adapter/responses/response_api_protocol_adapter.py +1 -1
- agentscope_runtime/engine/deployers/agentrun_deployer.py +2541 -0
- agentscope_runtime/engine/deployers/cli_fc_deploy.py +1 -1
- agentscope_runtime/engine/deployers/kubernetes_deployer.py +9 -21
- agentscope_runtime/engine/deployers/local_deployer.py +47 -74
- agentscope_runtime/engine/deployers/modelstudio_deployer.py +216 -50
- agentscope_runtime/engine/deployers/utils/app_runner_utils.py +29 -0
- agentscope_runtime/engine/deployers/utils/detached_app.py +510 -0
- agentscope_runtime/engine/deployers/utils/docker_image_utils/__init__.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/dockerfile_generator.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/{runner_image_factory.py → image_factory.py} +121 -61
- agentscope_runtime/engine/deployers/utils/package.py +693 -0
- agentscope_runtime/engine/deployers/utils/service_utils/__init__.py +0 -5
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py +301 -282
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_templates.py +2 -4
- agentscope_runtime/engine/deployers/utils/service_utils/process_manager.py +23 -1
- agentscope_runtime/engine/deployers/utils/templates/app_main.py.j2 +84 -0
- agentscope_runtime/engine/deployers/utils/templates/runner_main.py.j2 +95 -0
- agentscope_runtime/engine/deployers/utils/{service_utils → templates}/standalone_main.py.j2 +0 -45
- agentscope_runtime/engine/deployers/utils/wheel_packager.py +119 -18
- agentscope_runtime/engine/helpers/runner.py +40 -0
- agentscope_runtime/engine/runner.py +171 -130
- agentscope_runtime/engine/schemas/agent_schemas.py +114 -3
- agentscope_runtime/engine/schemas/modelstudio_llm.py +4 -2
- agentscope_runtime/engine/schemas/oai_llm.py +23 -23
- agentscope_runtime/engine/schemas/response_api.py +65 -0
- agentscope_runtime/engine/schemas/session.py +24 -0
- agentscope_runtime/engine/services/__init__.py +0 -9
- agentscope_runtime/engine/services/agent_state/__init__.py +16 -0
- agentscope_runtime/engine/services/agent_state/redis_state_service.py +113 -0
- agentscope_runtime/engine/services/agent_state/state_service.py +179 -0
- agentscope_runtime/engine/services/memory/__init__.py +24 -0
- agentscope_runtime/engine/services/{mem0_memory_service.py → memory/mem0_memory_service.py} +17 -13
- agentscope_runtime/engine/services/{memory_service.py → memory/memory_service.py} +28 -7
- agentscope_runtime/engine/services/{redis_memory_service.py → memory/redis_memory_service.py} +1 -1
- agentscope_runtime/engine/services/{reme_personal_memory_service.py → memory/reme_personal_memory_service.py} +9 -6
- agentscope_runtime/engine/services/{reme_task_memory_service.py → memory/reme_task_memory_service.py} +2 -2
- agentscope_runtime/engine/services/{tablestore_memory_service.py → memory/tablestore_memory_service.py} +12 -18
- agentscope_runtime/engine/services/sandbox/__init__.py +13 -0
- agentscope_runtime/engine/services/{sandbox_service.py → sandbox/sandbox_service.py} +86 -71
- agentscope_runtime/engine/services/session_history/__init__.py +23 -0
- agentscope_runtime/engine/services/{redis_session_history_service.py → session_history/redis_session_history_service.py} +3 -2
- agentscope_runtime/engine/services/{session_history_service.py → session_history/session_history_service.py} +44 -34
- agentscope_runtime/engine/services/{tablestore_session_history_service.py → session_history/tablestore_session_history_service.py} +14 -19
- agentscope_runtime/engine/services/utils/tablestore_service_utils.py +2 -2
- agentscope_runtime/engine/tracing/base.py +10 -9
- agentscope_runtime/engine/tracing/message_util.py +1 -1
- agentscope_runtime/engine/tracing/tracing_util.py +7 -2
- agentscope_runtime/engine/tracing/wrapper.py +49 -31
- agentscope_runtime/sandbox/__init__.py +10 -2
- agentscope_runtime/sandbox/box/agentbay/__init__.py +4 -0
- agentscope_runtime/sandbox/box/agentbay/agentbay_sandbox.py +559 -0
- agentscope_runtime/sandbox/box/base/base_sandbox.py +12 -0
- agentscope_runtime/sandbox/box/browser/browser_sandbox.py +115 -11
- agentscope_runtime/sandbox/box/cloud/__init__.py +4 -0
- agentscope_runtime/sandbox/box/cloud/cloud_sandbox.py +254 -0
- agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +66 -0
- agentscope_runtime/sandbox/box/gui/gui_sandbox.py +42 -0
- agentscope_runtime/sandbox/box/mobile/__init__.py +4 -0
- agentscope_runtime/sandbox/box/mobile/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +216 -0
- agentscope_runtime/sandbox/box/training_box/training_box.py +2 -2
- agentscope_runtime/sandbox/client/http_client.py +1 -0
- agentscope_runtime/sandbox/enums.py +2 -0
- agentscope_runtime/sandbox/manager/sandbox_manager.py +15 -2
- agentscope_runtime/sandbox/manager/server/app.py +12 -0
- agentscope_runtime/sandbox/manager/server/config.py +19 -0
- agentscope_runtime/sandbox/model/manager_config.py +79 -2
- agentscope_runtime/sandbox/utils.py +0 -18
- agentscope_runtime/tools/RAGs/__init__.py +0 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag.py +377 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag_lite.py +219 -0
- agentscope_runtime/tools/__init__.py +119 -0
- agentscope_runtime/tools/_constants.py +18 -0
- agentscope_runtime/tools/alipay/__init__.py +4 -0
- agentscope_runtime/tools/alipay/base.py +334 -0
- agentscope_runtime/tools/alipay/payment.py +835 -0
- agentscope_runtime/tools/alipay/subscribe.py +551 -0
- agentscope_runtime/tools/base.py +264 -0
- agentscope_runtime/tools/cli/__init__.py +0 -0
- agentscope_runtime/tools/cli/modelstudio_mcp_server.py +78 -0
- agentscope_runtime/tools/generations/__init__.py +75 -0
- agentscope_runtime/tools/generations/async_image_to_video.py +350 -0
- agentscope_runtime/tools/generations/async_image_to_video_wan25.py +366 -0
- agentscope_runtime/tools/generations/async_speech_to_video.py +422 -0
- agentscope_runtime/tools/generations/async_text_to_video.py +320 -0
- agentscope_runtime/tools/generations/async_text_to_video_wan25.py +334 -0
- agentscope_runtime/tools/generations/image_edit.py +208 -0
- agentscope_runtime/tools/generations/image_edit_wan25.py +193 -0
- agentscope_runtime/tools/generations/image_generation.py +202 -0
- agentscope_runtime/tools/generations/image_generation_wan25.py +201 -0
- agentscope_runtime/tools/generations/image_style_repaint.py +208 -0
- agentscope_runtime/tools/generations/image_to_video.py +233 -0
- agentscope_runtime/tools/generations/qwen_image_edit.py +205 -0
- agentscope_runtime/tools/generations/qwen_image_generation.py +214 -0
- agentscope_runtime/tools/generations/qwen_text_to_speech.py +154 -0
- agentscope_runtime/tools/generations/speech_to_text.py +260 -0
- agentscope_runtime/tools/generations/speech_to_video.py +314 -0
- agentscope_runtime/tools/generations/text_to_video.py +221 -0
- agentscope_runtime/tools/mcp_wrapper.py +215 -0
- agentscope_runtime/tools/realtime_clients/__init__.py +13 -0
- agentscope_runtime/tools/realtime_clients/asr_client.py +27 -0
- agentscope_runtime/tools/realtime_clients/azure_asr_client.py +195 -0
- agentscope_runtime/tools/realtime_clients/azure_tts_client.py +383 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_asr_client.py +151 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_tts_client.py +199 -0
- agentscope_runtime/tools/realtime_clients/realtime_tool.py +55 -0
- agentscope_runtime/tools/realtime_clients/tts_client.py +33 -0
- agentscope_runtime/tools/searches/__init__.py +3 -0
- agentscope_runtime/tools/searches/modelstudio_search.py +877 -0
- agentscope_runtime/tools/searches/modelstudio_search_lite.py +310 -0
- agentscope_runtime/tools/utils/__init__.py +0 -0
- agentscope_runtime/tools/utils/api_key_util.py +45 -0
- agentscope_runtime/tools/utils/crypto_utils.py +99 -0
- agentscope_runtime/tools/utils/mcp_util.py +35 -0
- agentscope_runtime/version.py +1 -1
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/METADATA +240 -168
- agentscope_runtime-1.0.0.dist-info/RECORD +240 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/entry_points.txt +1 -0
- agentscope_runtime/engine/agents/__init__.py +0 -2
- agentscope_runtime/engine/agents/agentscope_agent.py +0 -488
- agentscope_runtime/engine/agents/agno_agent.py +0 -220
- agentscope_runtime/engine/agents/autogen_agent.py +0 -250
- agentscope_runtime/engine/agents/base_agent.py +0 -29
- agentscope_runtime/engine/agents/langgraph_agent.py +0 -59
- agentscope_runtime/engine/agents/utils.py +0 -53
- agentscope_runtime/engine/deployers/utils/package_project_utils.py +0 -1163
- agentscope_runtime/engine/deployers/utils/service_utils/service_config.py +0 -75
- agentscope_runtime/engine/deployers/utils/service_utils/service_factory.py +0 -220
- agentscope_runtime/engine/helpers/helper.py +0 -179
- agentscope_runtime/engine/schemas/context.py +0 -54
- agentscope_runtime/engine/services/context_manager.py +0 -164
- agentscope_runtime/engine/services/environment_manager.py +0 -50
- agentscope_runtime/engine/services/manager.py +0 -174
- agentscope_runtime/engine/services/rag_service.py +0 -195
- agentscope_runtime/engine/services/tablestore_rag_service.py +0 -143
- agentscope_runtime/sandbox/tools/__init__.py +0 -12
- agentscope_runtime/sandbox/tools/base/__init__.py +0 -8
- agentscope_runtime/sandbox/tools/base/tool.py +0 -52
- agentscope_runtime/sandbox/tools/browser/__init__.py +0 -57
- agentscope_runtime/sandbox/tools/browser/tool.py +0 -597
- agentscope_runtime/sandbox/tools/filesystem/__init__.py +0 -32
- agentscope_runtime/sandbox/tools/filesystem/tool.py +0 -319
- agentscope_runtime/sandbox/tools/function_tool.py +0 -321
- agentscope_runtime/sandbox/tools/gui/__init__.py +0 -7
- agentscope_runtime/sandbox/tools/gui/tool.py +0 -77
- agentscope_runtime/sandbox/tools/mcp_tool.py +0 -195
- agentscope_runtime/sandbox/tools/sandbox_tool.py +0 -104
- agentscope_runtime/sandbox/tools/tool.py +0 -238
- agentscope_runtime/sandbox/tools/utils.py +0 -68
- agentscope_runtime-0.2.0b2.dist-info/RECORD +0 -183
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/WHEEL +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
AgentbaySandbox implementation for AgentBay cloud environment.
|
|
4
|
+
|
|
5
|
+
This module provides a sandbox implementation that integrates with AgentBay,
|
|
6
|
+
a cloud-native sandbox environment service.
|
|
7
|
+
"""
|
|
8
|
+
import logging
|
|
9
|
+
import os
|
|
10
|
+
from typing import Any, Dict, Optional
|
|
11
|
+
|
|
12
|
+
from ...registry import SandboxRegistry
|
|
13
|
+
from ...enums import SandboxType
|
|
14
|
+
from ..cloud.cloud_sandbox import CloudSandbox
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@SandboxRegistry.register(
|
|
20
|
+
"agentbay-cloud", # Virtual image name indicating cloud service
|
|
21
|
+
sandbox_type=SandboxType.AGENTBAY,
|
|
22
|
+
security_level="high",
|
|
23
|
+
timeout=300,
|
|
24
|
+
description="AgentBay Cloud Sandbox Environment",
|
|
25
|
+
)
|
|
26
|
+
class AgentbaySandbox(CloudSandbox):
|
|
27
|
+
"""
|
|
28
|
+
AgentBay cloud sandbox implementation.
|
|
29
|
+
|
|
30
|
+
This sandbox provides access to AgentBay's cloud-native sandbox environment
|
|
31
|
+
with support for various image types including Linux, Windows, Browser,
|
|
32
|
+
CodeSpace, and Mobile environments.
|
|
33
|
+
|
|
34
|
+
Features:
|
|
35
|
+
- Cloud-native environment (no local containers)
|
|
36
|
+
- Support for multiple image types
|
|
37
|
+
- Direct API communication with AgentBay
|
|
38
|
+
- Session management and lifecycle control
|
|
39
|
+
- Tool execution in cloud environment
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
sandbox_id: Optional[str] = None,
|
|
45
|
+
timeout: int = 3000,
|
|
46
|
+
base_url: Optional[str] = None,
|
|
47
|
+
bearer_token: Optional[str] = None,
|
|
48
|
+
sandbox_type: SandboxType = SandboxType.AGENTBAY,
|
|
49
|
+
api_key: Optional[str] = None,
|
|
50
|
+
image_id: str = "linux_latest",
|
|
51
|
+
labels: Optional[Dict[str, str]] = None,
|
|
52
|
+
**kwargs,
|
|
53
|
+
):
|
|
54
|
+
"""
|
|
55
|
+
Initialize the AgentBay sandbox.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
sandbox_id: Optional sandbox ID for existing sessions
|
|
59
|
+
timeout: Timeout for operations in seconds
|
|
60
|
+
base_url: Base URL for AgentBay API (optional)
|
|
61
|
+
bearer_token: Authentication token (deprecated, use api_key)
|
|
62
|
+
sandbox_type: Type of sandbox (default: AGENTBAY)
|
|
63
|
+
api_key: AgentBay API key (from environment or parameter)
|
|
64
|
+
image_id: AgentBay image type (linux_latest, windows_latest, etc.)
|
|
65
|
+
labels: Optional labels for session organization
|
|
66
|
+
**kwargs: Additional configuration
|
|
67
|
+
"""
|
|
68
|
+
# Get API key from parameter, environment, or bearer_token
|
|
69
|
+
self.api_key = api_key or os.getenv("AGENTBAY_API_KEY") or bearer_token
|
|
70
|
+
if not self.api_key:
|
|
71
|
+
raise ValueError(
|
|
72
|
+
"AgentBay API key is required. Set AGENTBAY_API_KEY "
|
|
73
|
+
"environment variable or pass api_key parameter.",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Store AgentBay-specific configuration
|
|
77
|
+
self.image_id = image_id
|
|
78
|
+
self.labels = labels or {}
|
|
79
|
+
self.base_url = base_url
|
|
80
|
+
|
|
81
|
+
super().__init__(
|
|
82
|
+
sandbox_id=sandbox_id,
|
|
83
|
+
timeout=timeout,
|
|
84
|
+
base_url=base_url,
|
|
85
|
+
bearer_token=self.api_key,
|
|
86
|
+
sandbox_type=sandbox_type,
|
|
87
|
+
**kwargs,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def _initialize_cloud_client(self):
|
|
91
|
+
"""
|
|
92
|
+
Initialize the AgentBay client.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
AgentBay client instance
|
|
96
|
+
"""
|
|
97
|
+
try:
|
|
98
|
+
# Import AgentBay SDK
|
|
99
|
+
from agentbay import AgentBay
|
|
100
|
+
|
|
101
|
+
# Initialize client with API key
|
|
102
|
+
client = AgentBay(api_key=self.api_key)
|
|
103
|
+
|
|
104
|
+
logger.info("AgentBay client initialized successfully")
|
|
105
|
+
return client
|
|
106
|
+
|
|
107
|
+
except ImportError as e:
|
|
108
|
+
raise ImportError(
|
|
109
|
+
"AgentBay SDK is not installed. Please install it with: "
|
|
110
|
+
"pip install wuying-agentbay-sdk",
|
|
111
|
+
) from e
|
|
112
|
+
except Exception as e:
|
|
113
|
+
raise RuntimeError(
|
|
114
|
+
f"Failed to initialize AgentBay client: {e}",
|
|
115
|
+
) from e
|
|
116
|
+
|
|
117
|
+
def _create_cloud_sandbox(self) -> Optional[str]:
|
|
118
|
+
"""
|
|
119
|
+
Create a new AgentBay session.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
Session ID if successful, None otherwise
|
|
123
|
+
"""
|
|
124
|
+
try:
|
|
125
|
+
from agentbay.session_params import CreateSessionParams
|
|
126
|
+
|
|
127
|
+
# Create session parameters
|
|
128
|
+
params = CreateSessionParams(
|
|
129
|
+
image_id=self.image_id,
|
|
130
|
+
labels=self.labels,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# Create session
|
|
134
|
+
result = self.cloud_client.create(params)
|
|
135
|
+
|
|
136
|
+
if result.success:
|
|
137
|
+
session_id = result.session.session_id
|
|
138
|
+
logger.info(f"AgentBay session created: {session_id}")
|
|
139
|
+
return session_id
|
|
140
|
+
else:
|
|
141
|
+
logger.error(
|
|
142
|
+
f"Failed to create AgentBay session: "
|
|
143
|
+
f"{result.error_message}",
|
|
144
|
+
)
|
|
145
|
+
return None
|
|
146
|
+
|
|
147
|
+
except Exception as e:
|
|
148
|
+
logger.error(f"Error creating AgentBay session: {e}")
|
|
149
|
+
return None
|
|
150
|
+
|
|
151
|
+
def _delete_cloud_sandbox(self, sandbox_id: str) -> bool:
|
|
152
|
+
"""
|
|
153
|
+
Delete an AgentBay session.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
sandbox_id: ID of the session to delete
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
True if successful, False otherwise
|
|
160
|
+
"""
|
|
161
|
+
try:
|
|
162
|
+
# Get session object first
|
|
163
|
+
get_result = self.cloud_client.get(sandbox_id)
|
|
164
|
+
if not get_result.success:
|
|
165
|
+
logger.warning(
|
|
166
|
+
f"Session {sandbox_id} not found or already deleted",
|
|
167
|
+
)
|
|
168
|
+
return True # Consider it successful if already gone
|
|
169
|
+
|
|
170
|
+
# Delete the session
|
|
171
|
+
delete_result = self.cloud_client.delete(get_result.session)
|
|
172
|
+
|
|
173
|
+
if delete_result.success:
|
|
174
|
+
logger.info(
|
|
175
|
+
f"AgentBay session {sandbox_id} deleted successfully",
|
|
176
|
+
)
|
|
177
|
+
return True
|
|
178
|
+
else:
|
|
179
|
+
logger.error(
|
|
180
|
+
f"Failed to delete AgentBay session: "
|
|
181
|
+
f"{delete_result.error_message}",
|
|
182
|
+
)
|
|
183
|
+
return False
|
|
184
|
+
|
|
185
|
+
except Exception as e:
|
|
186
|
+
logger.error(
|
|
187
|
+
f"Error deleting AgentBay session {sandbox_id}: {e}",
|
|
188
|
+
)
|
|
189
|
+
return False
|
|
190
|
+
|
|
191
|
+
def _call_cloud_tool(
|
|
192
|
+
self,
|
|
193
|
+
tool_name: str,
|
|
194
|
+
arguments: Dict[str, Any],
|
|
195
|
+
) -> Any:
|
|
196
|
+
"""
|
|
197
|
+
Call a tool in the AgentBay environment.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
tool_name: Name of the tool to call
|
|
201
|
+
arguments: Arguments for the tool
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
Tool execution result
|
|
205
|
+
"""
|
|
206
|
+
try:
|
|
207
|
+
# Get the session object
|
|
208
|
+
get_result = self.cloud_client.get(self._sandbox_id)
|
|
209
|
+
if not get_result.success:
|
|
210
|
+
raise RuntimeError(f"Sandbox {self._sandbox_id} not found")
|
|
211
|
+
|
|
212
|
+
session = get_result.session
|
|
213
|
+
|
|
214
|
+
# Map tool names to AgentBay session methods
|
|
215
|
+
tool_mapping = {
|
|
216
|
+
"run_shell_command": self._execute_command,
|
|
217
|
+
"run_ipython_cell": self._execute_code,
|
|
218
|
+
"read_file": self._read_file,
|
|
219
|
+
"write_file": self._write_file,
|
|
220
|
+
"list_directory": self._list_directory,
|
|
221
|
+
"create_directory": self._create_directory,
|
|
222
|
+
"move_file": self._move_file,
|
|
223
|
+
"delete_file": self._delete_file,
|
|
224
|
+
"screenshot": self._take_screenshot,
|
|
225
|
+
"browser_navigate": self._browser_navigate,
|
|
226
|
+
"browser_click": self._browser_click,
|
|
227
|
+
"browser_input": self._browser_input,
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if tool_name in tool_mapping:
|
|
231
|
+
return tool_mapping[tool_name](session, arguments)
|
|
232
|
+
else:
|
|
233
|
+
# Try to call as a generic method
|
|
234
|
+
return self._generic_tool_call(session, tool_name, arguments)
|
|
235
|
+
|
|
236
|
+
except Exception as e:
|
|
237
|
+
logger.error(f"Error calling tool {tool_name}: {e}")
|
|
238
|
+
return {
|
|
239
|
+
"success": False,
|
|
240
|
+
"error": str(e),
|
|
241
|
+
"tool_name": tool_name,
|
|
242
|
+
"arguments": arguments,
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
def _execute_command(
|
|
246
|
+
self,
|
|
247
|
+
session,
|
|
248
|
+
arguments: Dict[str, Any],
|
|
249
|
+
) -> Dict[str, Any]:
|
|
250
|
+
"""Execute a shell command in AgentBay."""
|
|
251
|
+
command = arguments.get("command", "")
|
|
252
|
+
result = session.command.execute_command(command)
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
"success": result.success,
|
|
256
|
+
"output": result.output,
|
|
257
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
258
|
+
"exit_code": result.exit_code
|
|
259
|
+
if hasattr(result, "exit_code")
|
|
260
|
+
else 0,
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
def _execute_code(
|
|
264
|
+
self,
|
|
265
|
+
session,
|
|
266
|
+
arguments: Dict[str, Any],
|
|
267
|
+
) -> Dict[str, Any]:
|
|
268
|
+
"""Execute Python code in AgentBay."""
|
|
269
|
+
code = arguments.get("code", "")
|
|
270
|
+
result = session.code.run_code(code, "python")
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
"success": result.success,
|
|
274
|
+
"output": result.result,
|
|
275
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
def _read_file(self, session, arguments: Dict[str, Any]) -> Dict[str, Any]:
|
|
279
|
+
"""Read a file from AgentBay."""
|
|
280
|
+
path = arguments.get("path", "")
|
|
281
|
+
result = session.file_system.read_file(path)
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
"success": result.success,
|
|
285
|
+
"content": result.content if hasattr(result, "content") else None,
|
|
286
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
def _write_file(
|
|
290
|
+
self,
|
|
291
|
+
session,
|
|
292
|
+
arguments: Dict[str, Any],
|
|
293
|
+
) -> Dict[str, Any]:
|
|
294
|
+
"""Write a file to AgentBay."""
|
|
295
|
+
path = arguments.get("path", "")
|
|
296
|
+
content = arguments.get("content", "")
|
|
297
|
+
result = session.file_system.write_file(path, content)
|
|
298
|
+
|
|
299
|
+
return {
|
|
300
|
+
"success": result.success,
|
|
301
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
def _list_directory(
|
|
305
|
+
self,
|
|
306
|
+
session,
|
|
307
|
+
arguments: Dict[str, Any],
|
|
308
|
+
) -> Dict[str, Any]:
|
|
309
|
+
"""List directory contents in AgentBay."""
|
|
310
|
+
path = arguments.get("path", ".")
|
|
311
|
+
result = session.file_system.list_directory(path)
|
|
312
|
+
|
|
313
|
+
return {
|
|
314
|
+
"success": result.success,
|
|
315
|
+
"files": result.files if hasattr(result, "files") else [],
|
|
316
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
def _create_directory(
|
|
320
|
+
self,
|
|
321
|
+
session,
|
|
322
|
+
arguments: Dict[str, Any],
|
|
323
|
+
) -> Dict[str, Any]:
|
|
324
|
+
"""Create a directory in AgentBay."""
|
|
325
|
+
path = arguments.get("path", "")
|
|
326
|
+
result = session.file_system.create_directory(path)
|
|
327
|
+
|
|
328
|
+
return {
|
|
329
|
+
"success": result.success,
|
|
330
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
def _move_file(self, session, arguments: Dict[str, Any]) -> Dict[str, Any]:
|
|
334
|
+
"""Move a file in AgentBay."""
|
|
335
|
+
source = arguments.get("source", "")
|
|
336
|
+
destination = arguments.get("destination", "")
|
|
337
|
+
result = session.file_system.move_file(source, destination)
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
"success": result.success,
|
|
341
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
def _delete_file(
|
|
345
|
+
self,
|
|
346
|
+
session,
|
|
347
|
+
arguments: Dict[str, Any],
|
|
348
|
+
) -> Dict[str, Any]:
|
|
349
|
+
"""Delete a file in AgentBay."""
|
|
350
|
+
path = arguments.get("path", "")
|
|
351
|
+
result = session.file_system.delete_file(path)
|
|
352
|
+
|
|
353
|
+
return {
|
|
354
|
+
"success": result.success,
|
|
355
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
def _take_screenshot(
|
|
359
|
+
self,
|
|
360
|
+
session,
|
|
361
|
+
arguments: Dict[str, Any], # pylint: disable=unused-argument
|
|
362
|
+
) -> Dict[str, Any]:
|
|
363
|
+
"""Take a screenshot in AgentBay."""
|
|
364
|
+
result = session.computer.screenshot()
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
"success": result.success,
|
|
368
|
+
"screenshot_url": result.data if hasattr(result, "data") else None,
|
|
369
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
def _browser_navigate(
|
|
373
|
+
self,
|
|
374
|
+
session,
|
|
375
|
+
arguments: Dict[str, Any],
|
|
376
|
+
) -> Dict[str, Any]:
|
|
377
|
+
"""Navigate browser in AgentBay."""
|
|
378
|
+
url = arguments.get("url", "")
|
|
379
|
+
result = session.browser.agent.navigate(url)
|
|
380
|
+
|
|
381
|
+
return {
|
|
382
|
+
"success": result.success,
|
|
383
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
def _browser_click(
|
|
387
|
+
self,
|
|
388
|
+
session,
|
|
389
|
+
arguments: Dict[str, Any],
|
|
390
|
+
) -> Dict[str, Any]:
|
|
391
|
+
"""Click element in browser."""
|
|
392
|
+
selector = arguments.get("selector", "")
|
|
393
|
+
result = session.browser.agent.click(selector)
|
|
394
|
+
|
|
395
|
+
return {
|
|
396
|
+
"success": result.success,
|
|
397
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
def _browser_input(
|
|
401
|
+
self,
|
|
402
|
+
session,
|
|
403
|
+
arguments: Dict[str, Any],
|
|
404
|
+
) -> Dict[str, Any]:
|
|
405
|
+
"""Input text in browser."""
|
|
406
|
+
selector = arguments.get("selector", "")
|
|
407
|
+
text = arguments.get("text", "")
|
|
408
|
+
result = session.browser.agent.input_text(selector, text)
|
|
409
|
+
|
|
410
|
+
return {
|
|
411
|
+
"success": result.success,
|
|
412
|
+
"error": result.error if hasattr(result, "error") else None,
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
def _generic_tool_call(
|
|
416
|
+
self,
|
|
417
|
+
session,
|
|
418
|
+
tool_name: str,
|
|
419
|
+
arguments: Dict[str, Any],
|
|
420
|
+
) -> Dict[str, Any]:
|
|
421
|
+
"""Generic tool call fallback."""
|
|
422
|
+
try:
|
|
423
|
+
# Try to find and call the method on the session
|
|
424
|
+
if hasattr(session, tool_name):
|
|
425
|
+
method = getattr(session, tool_name)
|
|
426
|
+
result = method(**arguments)
|
|
427
|
+
|
|
428
|
+
return {
|
|
429
|
+
"success": True,
|
|
430
|
+
"result": result,
|
|
431
|
+
}
|
|
432
|
+
else:
|
|
433
|
+
return {
|
|
434
|
+
"success": False,
|
|
435
|
+
"error": (
|
|
436
|
+
f"Tool '{tool_name}' not found in AgentBay session"
|
|
437
|
+
),
|
|
438
|
+
}
|
|
439
|
+
except Exception as e:
|
|
440
|
+
return {
|
|
441
|
+
"success": False,
|
|
442
|
+
"error": f"Error calling tool '{tool_name}': {str(e)}",
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
def _get_cloud_provider_name(self) -> str:
|
|
446
|
+
"""Get the name of the cloud provider."""
|
|
447
|
+
return "AgentBay"
|
|
448
|
+
|
|
449
|
+
def list_tools(self, tool_type: Optional[str] = None) -> Dict[str, Any]:
|
|
450
|
+
"""
|
|
451
|
+
List available tools in the AgentBay sandbox.
|
|
452
|
+
|
|
453
|
+
Args:
|
|
454
|
+
tool_type: Optional filter for tool type (e.g., "file", "browser")
|
|
455
|
+
|
|
456
|
+
Returns:
|
|
457
|
+
Dictionary containing available tools organized by type
|
|
458
|
+
"""
|
|
459
|
+
# Define tool categories
|
|
460
|
+
file_tools = [
|
|
461
|
+
"read_file",
|
|
462
|
+
"write_file",
|
|
463
|
+
"list_directory",
|
|
464
|
+
"create_directory",
|
|
465
|
+
"move_file",
|
|
466
|
+
"delete_file",
|
|
467
|
+
]
|
|
468
|
+
command_tools = ["run_shell_command", "run_ipython_cell"]
|
|
469
|
+
browser_tools = ["browser_navigate", "browser_click", "browser_input"]
|
|
470
|
+
system_tools = ["screenshot"]
|
|
471
|
+
|
|
472
|
+
# Organize tools by type
|
|
473
|
+
tools_by_type = {
|
|
474
|
+
"file": file_tools,
|
|
475
|
+
"command": command_tools,
|
|
476
|
+
"browser": browser_tools,
|
|
477
|
+
"system": system_tools,
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
# If tool_type is specified, return only that type
|
|
481
|
+
if tool_type:
|
|
482
|
+
tools = tools_by_type.get(tool_type, [])
|
|
483
|
+
return {
|
|
484
|
+
"tools": tools,
|
|
485
|
+
"tool_type": tool_type,
|
|
486
|
+
"sandbox_id": self._sandbox_id,
|
|
487
|
+
"total_count": len(tools),
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
# Return all tools organized by type
|
|
491
|
+
all_tools = []
|
|
492
|
+
for tool_list in tools_by_type.values():
|
|
493
|
+
all_tools.extend(tool_list)
|
|
494
|
+
|
|
495
|
+
return {
|
|
496
|
+
"tools": all_tools,
|
|
497
|
+
"tools_by_type": tools_by_type,
|
|
498
|
+
"tool_type": tool_type,
|
|
499
|
+
"sandbox_id": self._sandbox_id,
|
|
500
|
+
"total_count": len(all_tools),
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
def get_session_info(self) -> Dict[str, Any]:
|
|
504
|
+
"""
|
|
505
|
+
Get detailed information about the AgentBay session.
|
|
506
|
+
|
|
507
|
+
Returns:
|
|
508
|
+
Dictionary containing session information
|
|
509
|
+
"""
|
|
510
|
+
try:
|
|
511
|
+
get_result = self.cloud_client.get(self._sandbox_id)
|
|
512
|
+
if not get_result.success:
|
|
513
|
+
return {"error": "Session not found"}
|
|
514
|
+
|
|
515
|
+
session = get_result.session
|
|
516
|
+
info_result = session.info()
|
|
517
|
+
|
|
518
|
+
if info_result.success:
|
|
519
|
+
return {
|
|
520
|
+
"session_id": info_result.data.session_id,
|
|
521
|
+
"resource_id": info_result.data.resource_id,
|
|
522
|
+
"resource_url": info_result.data.resource_url,
|
|
523
|
+
"app_id": info_result.data.app_id,
|
|
524
|
+
"resource_type": info_result.data.resource_type,
|
|
525
|
+
"request_id": info_result.request_id,
|
|
526
|
+
}
|
|
527
|
+
else:
|
|
528
|
+
return {"error": info_result.error_message}
|
|
529
|
+
|
|
530
|
+
except Exception as e:
|
|
531
|
+
return {"error": str(e)}
|
|
532
|
+
|
|
533
|
+
def list_sessions(
|
|
534
|
+
self,
|
|
535
|
+
labels: Optional[Dict[str, str]] = None,
|
|
536
|
+
) -> Dict[str, Any]:
|
|
537
|
+
"""
|
|
538
|
+
List AgentBay sessions.
|
|
539
|
+
|
|
540
|
+
Args:
|
|
541
|
+
labels: Optional labels to filter sessions
|
|
542
|
+
|
|
543
|
+
Returns:
|
|
544
|
+
Dictionary containing session list
|
|
545
|
+
"""
|
|
546
|
+
try:
|
|
547
|
+
result = self.cloud_client.list(labels=labels)
|
|
548
|
+
|
|
549
|
+
return {
|
|
550
|
+
"success": result.success,
|
|
551
|
+
"session_ids": result.session_ids,
|
|
552
|
+
"total_count": result.total_count,
|
|
553
|
+
"request_id": result.request_id,
|
|
554
|
+
}
|
|
555
|
+
except Exception as e:
|
|
556
|
+
return {
|
|
557
|
+
"success": False,
|
|
558
|
+
"error": str(e),
|
|
559
|
+
}
|
|
@@ -33,7 +33,19 @@ class BaseSandbox(Sandbox):
|
|
|
33
33
|
)
|
|
34
34
|
|
|
35
35
|
def run_ipython_cell(self, code: str):
|
|
36
|
+
"""
|
|
37
|
+
Run an IPython cell.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
code (str): IPython code to execute.
|
|
41
|
+
"""
|
|
36
42
|
return self.call_tool("run_ipython_cell", {"code": code})
|
|
37
43
|
|
|
38
44
|
def run_shell_command(self, command: str):
|
|
45
|
+
"""
|
|
46
|
+
Run a shell command.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
command (str): Shell command to execute.
|
|
50
|
+
"""
|
|
39
51
|
return self.call_tool("run_shell_command", {"command": command})
|