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,77 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # flake8: noqa: E501
3
- # pylint: disable=line-too-long
4
- from typing import Dict
5
-
6
- from ..sandbox_tool import SandboxTool
7
-
8
-
9
- class ComputerUseTool(SandboxTool):
10
- """
11
- Use a mouse and keyboard to interact with a computer, and take screenshots.
12
- """
13
-
14
- _name: str = "computer"
15
- _sandbox_type: str = "gui"
16
- _tool_type: str = "computer_use"
17
- _schema: Dict = {
18
- "name": "computer",
19
- "description": (
20
- "Use a mouse and keyboard to interact with a computer, and take screenshots.\n"
21
- "* This is an interface to a desktop GUI. You do not have access to a terminal or applications menu. You must click on desktop icons to start applications.\n"
22
- "* Always prefer using keyboard shortcuts rather than clicking, where possible.\n"
23
- "* If you see boxes with two letters in them, typing these letters will click that element. Use this instead of other shortcuts or clicking, where possible.\n"
24
- "* Some applications may take time to start or process actions, so you may need to wait and take successive screenshots to see the results of your actions. E.g. if you click on Firefox and a window doesn't open, try taking another screenshot.\n"
25
- "* Whenever you intend to move the cursor to click on an element like an icon, you should consult a screenshot to determine the coordinates of the element before moving the cursor.\n"
26
- "* If you tried clicking on a program or link but it failed to load, even after waiting, try adjusting your cursor position so that the tip of the cursor visually falls on the element that you want to click.\n"
27
- "* Make sure to click any buttons, links, icons, etc with the cursor tip in the center of the element. Don't click boxes on their edges unless asked."
28
- ),
29
- "parameters": {
30
- "type": "object",
31
- "properties": {
32
- "action": {
33
- "type": "string",
34
- "enum": [
35
- "key",
36
- "type",
37
- "mouse_move",
38
- "left_click",
39
- "left_click_drag",
40
- "right_click",
41
- "middle_click",
42
- "double_click",
43
- "get_screenshot",
44
- "get_cursor_position",
45
- ],
46
- "description": (
47
- "The action to perform. The available actions are:\n"
48
- "* key: Press a key or key-combination on the keyboard.\n"
49
- "* type: Type a string of text on the keyboard.\n"
50
- "* get_cursor_position: Get the current (x, y) pixel coordinate of the cursor on the screen.\n"
51
- "* mouse_move: Move the cursor to a specified (x, y) pixel coordinate on the screen.\n"
52
- "* left_click: Click the left mouse button.\n"
53
- "* left_click_drag: Click and drag the cursor to a specified (x, y) pixel coordinate on the screen.\n"
54
- "* right_click: Click the right mouse button.\n"
55
- "* middle_click: Click the middle mouse button.\n"
56
- "* double_click: Double-click the left mouse button.\n"
57
- "* get_screenshot: Take a screenshot of the screen."
58
- ),
59
- },
60
- "coordinate": {
61
- "type": "array",
62
- "items": {"type": "number"},
63
- "minItems": 2,
64
- "maxItems": 2,
65
- "description": "(x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates",
66
- },
67
- "text": {
68
- "type": "string",
69
- "description": "Text to type or key command to execute",
70
- },
71
- },
72
- "required": ["action"],
73
- },
74
- }
75
-
76
-
77
- computer_use = ComputerUseTool()
@@ -1,195 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from typing import Optional, Any, Dict, Set, List
3
-
4
- from ..enums import SandboxType
5
- from ..box.sandbox import Sandbox
6
- from .sandbox_tool import SandboxTool
7
-
8
-
9
- class MCPTool(SandboxTool):
10
- """MCP tool class."""
11
-
12
- def __init__(
13
- self,
14
- *,
15
- sandbox: Optional[Any] = None,
16
- name: Optional[str] = None,
17
- sandbox_type: Optional[SandboxType | str] = None,
18
- tool_type: Optional[str] = None,
19
- schema: Optional[Dict] = None,
20
- server_configs: Optional[Dict] = None,
21
- ):
22
- """
23
- Initialize the MCP tool with an additional MCP server configuration.
24
- """
25
- super().__init__(
26
- sandbox=sandbox,
27
- name=name,
28
- sandbox_type=sandbox_type,
29
- tool_type=tool_type,
30
- schema=schema,
31
- )
32
- self._server_configs = server_configs
33
-
34
- @property
35
- def server_configs(self) -> Optional[Dict]:
36
- return self._server_configs
37
-
38
- @server_configs.setter
39
- def server_configs(self, config: Dict):
40
- if not isinstance(config, dict) and "mcpServers" not in config:
41
- raise ValueError(
42
- "MCP server configuration must be a valid dictionary.",
43
- )
44
- self._server_configs = config
45
-
46
- def bind(self, sandbox: Sandbox):
47
- """
48
- Return a new instance bound with a specific sandbox (immutable mode).
49
- """
50
- if not isinstance(sandbox, Sandbox):
51
- raise TypeError(
52
- "The provided sandbox must be an instance of `Sandbox`.",
53
- )
54
-
55
- assert self.sandbox_type == sandbox.sandbox_type, (
56
- f"Sandbox type mismatch! The tool requires a sandbox of type "
57
- f"`{self.sandbox_type}`, but a sandbox of type"
58
- f" `{sandbox.sandbox_type}` was provided."
59
- )
60
-
61
- return self.__class__(
62
- sandbox=sandbox,
63
- name=self._name,
64
- sandbox_type=self._sandbox_type,
65
- tool_type=self._tool_type,
66
- schema=self._schema,
67
- server_configs=self._server_configs,
68
- )
69
-
70
-
71
- class MCPConfigConverter:
72
- """MCP configuration management class."""
73
-
74
- def __init__(
75
- self,
76
- server_configs: Dict,
77
- *,
78
- sandbox: Optional[Sandbox] = None,
79
- whitelist: Optional[Set[str]] = None,
80
- blacklist: Optional[Set[str]] = None,
81
- ) -> None:
82
- """
83
- Initializes MCP configuration.
84
-
85
- Args:
86
- server_configs: Dictionary of MCP server configurations.
87
- whitelist: Whitelist; if set, only functions in the whitelist
88
- are allowed.
89
- blacklist: Blacklist; functions in the blacklist will be excluded.
90
- """
91
- self.server_configs = server_configs
92
- self.whitelist = whitelist or set()
93
- self.blacklist = blacklist or set()
94
- self._sandbox = sandbox
95
-
96
- assert (
97
- "mcpServers" in server_configs
98
- ), "MCP server config must contain 'mcpServers'"
99
-
100
- def bind(self, sandbox: Sandbox) -> "MCPConfigConverter":
101
- """
102
- Binds a sandbox and returns a new instance.
103
-
104
- Args:
105
- sandbox: The sandbox object to bind.
106
-
107
- Returns:
108
- A new configuration instance bound to the sandbox.
109
- """
110
- new_config = self.__class__(
111
- server_configs=self.server_configs.copy(),
112
- sandbox=sandbox,
113
- whitelist=self.whitelist.copy(),
114
- blacklist=self.blacklist.copy(),
115
- )
116
- return new_config
117
-
118
- def to_builtin_tools(
119
- self,
120
- *,
121
- sandbox: Optional[Sandbox] = None,
122
- sandbox_type: Optional[SandboxType | str] = None,
123
- ) -> List[MCPTool]:
124
- """
125
- Converts to a list of MCPTool instances.
126
-
127
- Returns:
128
- A list of bound MCPTool objects.
129
- """
130
- box = sandbox or self._sandbox
131
- if box is None:
132
- from ..registry import SandboxRegistry
133
-
134
- if sandbox_type is None:
135
- sandbox_type = SandboxType.BASE
136
-
137
- cls_ = SandboxRegistry.get_classes_by_type(sandbox_type)
138
- # Use proper context manager
139
- with cls_() as tmp_box:
140
- return self._process_tools(tmp_box)
141
- else:
142
- return self._process_tools(box)
143
-
144
- def _process_tools(self, box: Sandbox) -> List[MCPTool]:
145
- """Helper method to process tools with the given sandbox."""
146
- tools_to_add = []
147
- box.add_mcp_servers(
148
- server_configs=self.server_configs,
149
- overwrite=False,
150
- )
151
- for server_name in self.server_configs["mcpServers"]:
152
- tools = box.list_tools(tool_type=server_name).get(server_name, {})
153
- for tool_name, tool_info in tools.items():
154
- if self.whitelist and tool_name not in self.whitelist:
155
- continue
156
- if self.blacklist and tool_name in self.blacklist:
157
- continue
158
-
159
- tools_to_add.append(
160
- MCPTool(
161
- sandbox=box,
162
- name=tool_name,
163
- sandbox_type=box.sandbox_type,
164
- tool_type=server_name,
165
- schema=tool_info["json_schema"]["function"],
166
- server_configs={
167
- "mcpServers": {
168
- server_name: self.server_configs["mcpServers"][
169
- server_name
170
- ],
171
- },
172
- },
173
- ),
174
- )
175
-
176
- return tools_to_add
177
-
178
- @classmethod
179
- def from_dict(
180
- cls,
181
- config_dict: Dict,
182
- whitelist: Optional[Set[str]] = None,
183
- blacklist: Optional[Set[str]] = None,
184
- ) -> "MCPConfigConverter":
185
- """Creates a configuration instance from a dictionary.
186
-
187
- Args:
188
- config_dict: Configuration dictionary.
189
- whitelist: Whitelist.
190
- blacklist: Blacklist.
191
-
192
- Returns:
193
- An instance of McpConfig.
194
- """
195
- return cls(config_dict, whitelist=whitelist, blacklist=blacklist)
@@ -1,104 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from typing import Optional, Any, Dict
3
-
4
- from .tool import Tool
5
- from ..enums import SandboxType
6
- from ..box.sandbox import Sandbox
7
-
8
-
9
- class SandboxTool(Tool):
10
- """Built-in tool class"""
11
-
12
- _name: str = None
13
- _sandbox_type: SandboxType | str = None
14
- _tool_type: str = None
15
- _schema: Dict = None
16
-
17
- def __init__(
18
- self,
19
- *,
20
- sandbox: Optional[Any] = None,
21
- name: Optional[str] = None,
22
- sandbox_type: Optional[SandboxType | str] = None,
23
- tool_type: Optional[str] = None,
24
- schema: Optional[Dict] = None,
25
- ):
26
- """
27
- Initialize the tool.
28
-
29
- Note: Once the sandbox is set, it does not change.
30
- """
31
- self._sandbox = sandbox
32
- self._name = name or self.__class__._name
33
- self._sandbox_type = sandbox_type or self.__class__._sandbox_type
34
- self._tool_type = tool_type or self.__class__._tool_type
35
- self._schema = schema or self.__class__._schema
36
-
37
- @property
38
- def name(self) -> str:
39
- return self._name
40
-
41
- @property
42
- def sandbox_type(self) -> SandboxType:
43
- return SandboxType(self._sandbox_type)
44
-
45
- @property
46
- def tool_type(self) -> str:
47
- return self._tool_type
48
-
49
- @property
50
- def schema(self) -> Dict:
51
- return {
52
- "type": "function",
53
- "function": self._schema,
54
- }
55
-
56
- @property
57
- def sandbox(self):
58
- return self._sandbox
59
-
60
- def __call__(self, *, sandbox: Optional[Any] = None, **kwargs):
61
- """Call the tool, allowing a temporary sandbox to be specified"""
62
- return self.call(sandbox=sandbox, **kwargs)
63
-
64
- def call(self, *, sandbox: Optional[Any] = None, **kwargs):
65
- """
66
- Execute the tool call.
67
- Args:
68
- sandbox: Temporarily used sandbox, highest priority
69
- **kwargs: Tool parameters
70
- """
71
- # Priority: temporary sandbox > instance sandbox > None (dryrun)
72
- box = sandbox or self._sandbox
73
- if box is None:
74
- return self._dryrun_call(**kwargs)
75
- else:
76
- return box.call_tool(self.name, arguments=kwargs)
77
-
78
- def bind(self, sandbox: Sandbox):
79
- """
80
- Return a new instance bound with a specific sandbox (immutable mode).
81
- """
82
- if not isinstance(sandbox, Sandbox):
83
- raise TypeError(
84
- "The provided sandbox must be an instance of `Sandbox`.",
85
- )
86
-
87
- assert self.sandbox_type == sandbox.sandbox_type, (
88
- f"Sandbox type mismatch! The tool requires a sandbox of type "
89
- f"`{self.sandbox_type}`, but a sandbox of type"
90
- f" `{sandbox.sandbox_type}` was provided."
91
- )
92
-
93
- return self.__class__(sandbox=sandbox)
94
-
95
- def _dryrun_call(self, **kwargs):
96
- """
97
- Dryrun mode: temporarily create a sandbox
98
- """
99
- from ..registry import SandboxRegistry
100
-
101
- cls_ = SandboxRegistry.get_classes_by_type(self.sandbox_type)
102
-
103
- with cls_() as box:
104
- return box.call_tool(self.name, arguments=kwargs)
@@ -1,238 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # pylint: disable=unused-argument
3
- import inspect
4
-
5
- from abc import ABC, abstractmethod
6
- from typing import Optional, Any, Dict
7
- from ..enums import SandboxType
8
-
9
-
10
- class Tool(ABC):
11
- """Abstract base class for all tools.
12
-
13
- This abstract class defines the common interface that all tool
14
- implementations must follow, including both SandboxTool and FunctionTool.
15
-
16
- Key responsibilities:
17
- - Define the standard tool interface
18
- - Ensure consistent behavior across different tool types
19
- - Provide common functionality where applicable
20
- """
21
-
22
- def __init__(
23
- self,
24
- *,
25
- name: Optional[str] = None,
26
- tool_type: Optional[str] = None,
27
- **kwargs,
28
- ):
29
- """
30
- Initialize the tool with basic parameters.
31
-
32
- Args:
33
- name: Tool name
34
- tool_type: Tool type identifier
35
- **kwargs: Additional tool-specific parameters
36
- """
37
- self._name = name
38
- self._tool_type = tool_type
39
-
40
- @property
41
- def __name__(self) -> str:
42
- return self.name
43
-
44
- @property
45
- @abstractmethod
46
- def name(self) -> str:
47
- """Get the tool name."""
48
-
49
- @property
50
- @abstractmethod
51
- def tool_type(self) -> str:
52
- """Get the tool type."""
53
-
54
- @property
55
- @abstractmethod
56
- def schema(self) -> Dict:
57
- """Get the tool schema in OpenAI function calling format."""
58
-
59
- @property
60
- @abstractmethod
61
- def sandbox_type(self) -> SandboxType:
62
- """Get the required sandbox type for this tool."""
63
-
64
- @property
65
- @abstractmethod
66
- def sandbox(self) -> Optional[Any]:
67
- """Get the current sandbox instance (if any)."""
68
-
69
- def __call__(self, *, sandbox: Optional[Any] = None, **kwargs):
70
- """Call the tool with optional sandbox override.
71
-
72
- This is a convenience method that delegates to the call() method.
73
-
74
- Args:
75
- sandbox: Optional sandbox to use for this call
76
- **kwargs: Tool parameters
77
-
78
- Returns:
79
- Tool execution result
80
- """
81
- return self.call(sandbox=sandbox, **kwargs)
82
-
83
- @abstractmethod
84
- def call(self, *, sandbox: Optional[Any] = None, **kwargs) -> Dict:
85
- """Execute the tool call.
86
-
87
- This is the core method that each tool implementation must provide.
88
-
89
- Args:
90
- sandbox: Optional sandbox to use for this call
91
- **kwargs: Tool parameters
92
-
93
- Returns:
94
- Tool execution result in standardized format:
95
- {
96
- "meta": Optional[Dict],
97
- "content": List[Dict],
98
- "isError": bool
99
- }
100
- """
101
-
102
- @abstractmethod
103
- def bind(self, *args, **kwargs) -> "Tool":
104
- """Bind parameters or context to create a new tool instance.
105
-
106
- The specific binding behavior depends on the tool type:
107
- - SandboxTool: binds to a sandbox
108
- - FunctionTool: binds function parameters
109
-
110
- Returns:
111
- New tool instance with bound parameters/context
112
- """
113
-
114
- def __str__(self) -> str:
115
- """String representation of the tool."""
116
- return (
117
- f"{self.__class__.__name__}(name='{self.name}', type="
118
- f"'{self.tool_type}')"
119
- )
120
-
121
- def __repr__(self) -> str:
122
- """Detailed string representation of the tool."""
123
- return (
124
- f"{self.__class__.__name__}("
125
- f"name='{self.name}', "
126
- f"tool_type='{self.tool_type}', "
127
- f"sandbox_type='{self.sandbox_type}'"
128
- f")"
129
- )
130
-
131
- def make_function(self):
132
- """Create a function with proper type signatures from schema."""
133
- tool_call = self.__call__
134
- parameters = self.schema["function"]["parameters"]
135
-
136
- # Extract properties and required parameters from the schema
137
- properties = parameters.get("properties", {})
138
- required = parameters.get("required", [])
139
-
140
- # Type mapping from JSON schema types to Python types
141
- type_mapping = {
142
- "string": str,
143
- "integer": int,
144
- "number": float,
145
- "boolean": bool,
146
- "array": list,
147
- "object": dict,
148
- }
149
-
150
- # Build parameter signature
151
- sig_params = []
152
- for param_name, param_info in properties.items():
153
- param_type = type_mapping.get(
154
- param_info.get("type", "string"),
155
- str,
156
- )
157
-
158
- if param_name in required:
159
- # Required parameter
160
- param = inspect.Parameter(
161
- param_name,
162
- inspect.Parameter.POSITIONAL_OR_KEYWORD,
163
- annotation=param_type,
164
- )
165
- else:
166
- # Optional parameter with default None
167
- param = inspect.Parameter(
168
- param_name,
169
- inspect.Parameter.POSITIONAL_OR_KEYWORD,
170
- default=None,
171
- annotation=Optional[param_type],
172
- )
173
-
174
- sig_params.append(param)
175
-
176
- # Create the function signature
177
- new_signature = inspect.Signature(sig_params, return_annotation=Any)
178
-
179
- def generated_function(*args, **kwargs):
180
- """
181
- Dynamically generated function wrapper for the tool schema.
182
-
183
- This function is created at runtime to match the tool's parameter
184
- signature as defined in the schema. It validates arguments and
185
- forwards them to the tool's call interface.
186
- """
187
- # Bind arguments to signature
188
- bound = new_signature.bind(*args, **kwargs)
189
- bound.apply_defaults()
190
-
191
- # Validate required parameters
192
- missing_required = [
193
- param_name
194
- for param_name in required
195
- if param_name not in bound.arguments
196
- or bound.arguments[param_name] is None
197
- ]
198
-
199
- if missing_required:
200
- raise TypeError(
201
- f"Missing required arguments: {set(missing_required)}",
202
- )
203
-
204
- # Filter kwargs based on defined properties and remove None
205
- # values for optional params
206
- filtered_kwargs = {
207
- k: v
208
- for k, v in bound.arguments.items()
209
- if k in properties and (k in required or v is not None)
210
- }
211
-
212
- return tool_call(**filtered_kwargs)
213
-
214
- # Set the correct signature and metadata
215
- generated_function.__signature__ = new_signature
216
- generated_function.__name__ = self.name
217
-
218
- # Build docstring with parameter information
219
- doc_parts = []
220
- for name, info in properties.items():
221
- required_str = " (required)" if name in required else " (optional)"
222
- doc_parts.append(
223
- f" {name}: {info.get('type', 'string')}{required_str} -"
224
- f" {info.get('description', '')}",
225
- )
226
-
227
- generated_function.__doc__ = (
228
- self.schema["function"]["description"]
229
- + "\n\nParameters:\n"
230
- + "\n".join(doc_parts)
231
- )
232
-
233
- # Set type annotations for compatibility with typing inspection
234
- annotations = {param.name: param.annotation for param in sig_params}
235
- annotations["return"] = Any
236
- generated_function.__annotations__ = annotations
237
-
238
- return generated_function
@@ -1,68 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- def setup_tools(
3
- tools,
4
- environment_manager,
5
- session_id,
6
- user_id,
7
- include_schemas=False,
8
- ):
9
- """
10
- Generic function to activate tools.
11
-
12
- Args:
13
- tools: List of tools to activate.
14
- environment_manager: Environment manager
15
- session_id: ID of the session.
16
- user_id: ID of the user.
17
- include_schemas: Boolean flag to indicate if schemas should be
18
- included.
19
-
20
- Returns:
21
- tuple: (activated_tools, schemas) if include_schemas=True,
22
- else only activated_tools.
23
- """
24
- # Lazy import
25
- from .tool import Tool
26
- from .sandbox_tool import SandboxTool
27
- from ...sandbox.box.dummy.dummy_sandbox import DummySandbox
28
-
29
- enable_sandbox = False
30
-
31
- # Check tool types and determine if sandbox needs to be enabled
32
- for tool in tools:
33
- assert isinstance(tool, Tool), f"{tool} must be an instance of Tool"
34
- if isinstance(tool, SandboxTool):
35
- enable_sandbox = True
36
- break
37
-
38
- # Check environment service
39
- if enable_sandbox and environment_manager is None:
40
- raise ValueError("environment_manager is not set")
41
-
42
- # Connect to sandbox if required
43
- if enable_sandbox:
44
- sandboxes = environment_manager.connect_sandbox(
45
- session_id=session_id,
46
- user_id=user_id,
47
- tools=tools,
48
- )
49
- else:
50
- sandboxes = [DummySandbox()]
51
-
52
- # Bind tools to sandbox and prepare schemas if required
53
- schemas = [] # Initialize schemas list
54
- activated_tools = [] # Initialize activated tools list
55
-
56
- for tool in tools:
57
- if include_schemas:
58
- schemas.append(tool.schema) # Collect tool schemas
59
- for sandbox in sandboxes:
60
- if sandbox.sandbox_type == tool.sandbox_type:
61
- bound_tool = tool.bind(sandbox) # Bind tool to the sandbox
62
- activated_tools.append(
63
- bound_tool,
64
- ) # Add to the activated tools list
65
-
66
- if include_schemas:
67
- return activated_tools, schemas
68
- return activated_tools