agentscope-runtime 0.2.0b1__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/container_clients/kubernetes_client.py +6 -13
- 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} +16 -19
- 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 -44
- agentscope_runtime/sandbox/client/http_client.py +1 -0
- agentscope_runtime/sandbox/enums.py +2 -1
- 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.0b1.dist-info → agentscope_runtime-1.0.0.dist-info}/METADATA +244 -168
- agentscope_runtime-1.0.0.dist-info/RECORD +240 -0
- {agentscope_runtime-0.2.0b1.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 -222
- 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.0b1.dist-info/RECORD +0 -183
- {agentscope_runtime-0.2.0b1.dist-info → agentscope_runtime-1.0.0.dist-info}/WHEEL +0 -0
- {agentscope_runtime-0.2.0b1.dist-info → agentscope_runtime-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-0.2.0b1.dist-info → agentscope_runtime-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# flake8: noqa: E501
|
|
3
|
-
# pylint: disable=line-too-long
|
|
4
|
-
from typing import Dict
|
|
5
|
-
|
|
6
|
-
from ..base.tool import RunIPythonCellTool, RunShellCommandTool
|
|
7
|
-
from ..sandbox_tool import SandboxTool
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class _RunIPythonCellTool(RunIPythonCellTool):
|
|
11
|
-
"""Tool for running IPython cells."""
|
|
12
|
-
|
|
13
|
-
_sandbox_type: str = "filesystem"
|
|
14
|
-
_tool_type: str = "generic"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class _RunShellCommandTool(RunShellCommandTool):
|
|
18
|
-
"""Tool for running shell commands."""
|
|
19
|
-
|
|
20
|
-
_sandbox_type: str = "filesystem"
|
|
21
|
-
_tool_type: str = "generic"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class ReadFileTool(SandboxTool):
|
|
25
|
-
"""Tool for reading the complete contents of a file."""
|
|
26
|
-
|
|
27
|
-
_name: str = "read_file"
|
|
28
|
-
_sandbox_type: str = "filesystem"
|
|
29
|
-
_tool_type: str = "filesystem"
|
|
30
|
-
_schema: Dict = {
|
|
31
|
-
"name": "read_file",
|
|
32
|
-
"description": "Read the complete contents of a file.",
|
|
33
|
-
"parameters": {
|
|
34
|
-
"type": "object",
|
|
35
|
-
"properties": {
|
|
36
|
-
"path": {
|
|
37
|
-
"type": "string",
|
|
38
|
-
"description": "Path to the file to read",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
"required": ["path"],
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
class ReadMultipleFilesTool(SandboxTool):
|
|
47
|
-
"""Tool for reading the contents of multiple files."""
|
|
48
|
-
|
|
49
|
-
_name: str = "read_multiple_files"
|
|
50
|
-
_sandbox_type: str = "filesystem"
|
|
51
|
-
_tool_type: str = "filesystem"
|
|
52
|
-
_schema: Dict = {
|
|
53
|
-
"name": "read_multiple_files",
|
|
54
|
-
"description": "Read the contents of multiple files simultaneously.",
|
|
55
|
-
"parameters": {
|
|
56
|
-
"type": "object",
|
|
57
|
-
"properties": {
|
|
58
|
-
"paths": {
|
|
59
|
-
"type": "array",
|
|
60
|
-
"items": {
|
|
61
|
-
"type": "string",
|
|
62
|
-
},
|
|
63
|
-
"description": "Paths to the files to read",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
"required": ["paths"],
|
|
67
|
-
},
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
class WriteFileTool(SandboxTool):
|
|
72
|
-
"""Tool for creating or overwriting a file with new content."""
|
|
73
|
-
|
|
74
|
-
_name: str = "write_file"
|
|
75
|
-
_sandbox_type: str = "filesystem"
|
|
76
|
-
_tool_type: str = "filesystem"
|
|
77
|
-
_schema: Dict = {
|
|
78
|
-
"name": "write_file",
|
|
79
|
-
"description": "Create a new file or overwrite an existing file with new content.",
|
|
80
|
-
"parameters": {
|
|
81
|
-
"type": "object",
|
|
82
|
-
"properties": {
|
|
83
|
-
"path": {
|
|
84
|
-
"type": "string",
|
|
85
|
-
"description": "Path to the file to write to",
|
|
86
|
-
},
|
|
87
|
-
"content": {
|
|
88
|
-
"type": "string",
|
|
89
|
-
"description": "Content to write into the file",
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
"required": ["path", "content"],
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
class EditFileTool(SandboxTool):
|
|
98
|
-
"""Tool for making line-based edits to a text file."""
|
|
99
|
-
|
|
100
|
-
_name: str = "edit_file"
|
|
101
|
-
_sandbox_type: str = "filesystem"
|
|
102
|
-
_tool_type: str = "filesystem"
|
|
103
|
-
_schema: Dict = {
|
|
104
|
-
"name": "edit_file",
|
|
105
|
-
"description": "Make line-based edits to a text file.",
|
|
106
|
-
"parameters": {
|
|
107
|
-
"type": "object",
|
|
108
|
-
"properties": {
|
|
109
|
-
"path": {
|
|
110
|
-
"type": "string",
|
|
111
|
-
"description": "Path to the file to edit",
|
|
112
|
-
},
|
|
113
|
-
"edits": {
|
|
114
|
-
"type": "array",
|
|
115
|
-
"items": {
|
|
116
|
-
"type": "object",
|
|
117
|
-
"properties": {
|
|
118
|
-
"oldText": {
|
|
119
|
-
"type": "string",
|
|
120
|
-
"description": "Text to search for - must match exactly",
|
|
121
|
-
},
|
|
122
|
-
"newText": {
|
|
123
|
-
"type": "string",
|
|
124
|
-
"description": "Text to replace with",
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
"required": ["oldText", "newText"],
|
|
128
|
-
"additionalProperties": False,
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
"dryRun": {
|
|
132
|
-
"type": "boolean",
|
|
133
|
-
"default": False,
|
|
134
|
-
"description": "Preview changes using git-style diff format",
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
"required": ["path", "edits"],
|
|
138
|
-
},
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
class CreateDirectoryTool(SandboxTool):
|
|
143
|
-
"""Tool for creating a new directory or ensuring it exists."""
|
|
144
|
-
|
|
145
|
-
_name: str = "create_directory"
|
|
146
|
-
_sandbox_type: str = "filesystem"
|
|
147
|
-
_tool_type: str = "filesystem"
|
|
148
|
-
_schema: Dict = {
|
|
149
|
-
"name": "create_directory",
|
|
150
|
-
"description": "Create a new directory or ensure a directory exists.",
|
|
151
|
-
"parameters": {
|
|
152
|
-
"type": "object",
|
|
153
|
-
"properties": {
|
|
154
|
-
"path": {
|
|
155
|
-
"type": "string",
|
|
156
|
-
"description": "Path to the directory to create",
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
"required": ["path"],
|
|
160
|
-
},
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
class ListDirectoryTool(SandboxTool):
|
|
165
|
-
"""Tool for listing all files and directories in a specified path."""
|
|
166
|
-
|
|
167
|
-
_name: str = "list_directory"
|
|
168
|
-
_sandbox_type: str = "filesystem"
|
|
169
|
-
_tool_type: str = "filesystem"
|
|
170
|
-
_schema: Dict = {
|
|
171
|
-
"name": "list_directory",
|
|
172
|
-
"description": "Get a detailed listing of all files and directories in a specified path.",
|
|
173
|
-
"parameters": {
|
|
174
|
-
"type": "object",
|
|
175
|
-
"properties": {
|
|
176
|
-
"path": {
|
|
177
|
-
"type": "string",
|
|
178
|
-
"description": "Path to list contents",
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
"required": ["path"],
|
|
182
|
-
},
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
class DirectoryTreeTool(SandboxTool):
|
|
187
|
-
"""Tool for getting a recursive tree view of files and directories."""
|
|
188
|
-
|
|
189
|
-
_name: str = "directory_tree"
|
|
190
|
-
_sandbox_type: str = "filesystem"
|
|
191
|
-
_tool_type: str = "filesystem"
|
|
192
|
-
_schema: Dict = {
|
|
193
|
-
"name": "directory_tree",
|
|
194
|
-
"description": "Get a recursive tree view of files and directories as a JSON structure.",
|
|
195
|
-
"parameters": {
|
|
196
|
-
"type": "object",
|
|
197
|
-
"properties": {
|
|
198
|
-
"path": {
|
|
199
|
-
"type": "string",
|
|
200
|
-
"description": "Path to get tree structure",
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
"required": ["path"],
|
|
204
|
-
},
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
class MoveFileTool(SandboxTool):
|
|
209
|
-
"""Tool for moving or renaming files and directories."""
|
|
210
|
-
|
|
211
|
-
_name: str = "move_file"
|
|
212
|
-
_sandbox_type: str = "filesystem"
|
|
213
|
-
_tool_type: str = "filesystem"
|
|
214
|
-
_schema: Dict = {
|
|
215
|
-
"name": "move_file",
|
|
216
|
-
"description": "Move or rename files and directories.",
|
|
217
|
-
"parameters": {
|
|
218
|
-
"type": "object",
|
|
219
|
-
"properties": {
|
|
220
|
-
"source": {
|
|
221
|
-
"type": "string",
|
|
222
|
-
"description": "Source path to move from",
|
|
223
|
-
},
|
|
224
|
-
"destination": {
|
|
225
|
-
"type": "string",
|
|
226
|
-
"description": "Destination path to move to",
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
"required": ["source", "destination"],
|
|
230
|
-
},
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
class SearchFilesTool(SandboxTool):
|
|
235
|
-
"""Tool for searching files and directories matching a pattern."""
|
|
236
|
-
|
|
237
|
-
_name: str = "search_files"
|
|
238
|
-
_sandbox_type: str = "filesystem"
|
|
239
|
-
_tool_type: str = "filesystem"
|
|
240
|
-
_schema: Dict = {
|
|
241
|
-
"name": "search_files",
|
|
242
|
-
"description": "Recursively search for files and directories matching a pattern.",
|
|
243
|
-
"parameters": {
|
|
244
|
-
"type": "object",
|
|
245
|
-
"properties": {
|
|
246
|
-
"path": {
|
|
247
|
-
"type": "string",
|
|
248
|
-
"description": "Starting path for the search",
|
|
249
|
-
},
|
|
250
|
-
"pattern": {
|
|
251
|
-
"type": "string",
|
|
252
|
-
"description": "Pattern to match files/directories",
|
|
253
|
-
},
|
|
254
|
-
"excludePatterns": {
|
|
255
|
-
"type": "array",
|
|
256
|
-
"items": {
|
|
257
|
-
"type": "string",
|
|
258
|
-
},
|
|
259
|
-
"default": [],
|
|
260
|
-
"description": "Patterns to exclude from search",
|
|
261
|
-
},
|
|
262
|
-
},
|
|
263
|
-
"required": ["path", "pattern"],
|
|
264
|
-
},
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
class GetFileInfoTool(SandboxTool):
|
|
269
|
-
"""Tool for retrieving metadata about a file or directory."""
|
|
270
|
-
|
|
271
|
-
_name: str = "get_file_info"
|
|
272
|
-
_sandbox_type: str = "filesystem"
|
|
273
|
-
_tool_type: str = "filesystem"
|
|
274
|
-
_schema: Dict = {
|
|
275
|
-
"name": "get_file_info",
|
|
276
|
-
"description": "Retrieve detailed metadata about a file or directory.",
|
|
277
|
-
"parameters": {
|
|
278
|
-
"type": "object",
|
|
279
|
-
"properties": {
|
|
280
|
-
"path": {
|
|
281
|
-
"type": "string",
|
|
282
|
-
"description": "Path to the file or directory",
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
"required": ["path"],
|
|
286
|
-
},
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
class ListAllowedDirectoriesTool(SandboxTool):
|
|
291
|
-
"""Tool for listing allowed directories the server can access."""
|
|
292
|
-
|
|
293
|
-
_name: str = "list_allowed_directories"
|
|
294
|
-
_sandbox_type: str = "filesystem"
|
|
295
|
-
_tool_type: str = "filesystem"
|
|
296
|
-
_schema: Dict = {
|
|
297
|
-
"name": "list_allowed_directories",
|
|
298
|
-
"description": "Returns the list of directories that this server is allowed to access.",
|
|
299
|
-
"parameters": {
|
|
300
|
-
"type": "object",
|
|
301
|
-
"properties": {},
|
|
302
|
-
"required": [],
|
|
303
|
-
},
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
run_shell_command = _RunShellCommandTool()
|
|
308
|
-
run_ipython_cell = _RunIPythonCellTool()
|
|
309
|
-
read_file = ReadFileTool()
|
|
310
|
-
read_multiple_files = ReadMultipleFilesTool()
|
|
311
|
-
write_file = WriteFileTool()
|
|
312
|
-
edit_file = EditFileTool()
|
|
313
|
-
create_directory = CreateDirectoryTool()
|
|
314
|
-
list_directory = ListDirectoryTool()
|
|
315
|
-
directory_tree = DirectoryTreeTool()
|
|
316
|
-
move_file = MoveFileTool()
|
|
317
|
-
search_files = SearchFilesTool()
|
|
318
|
-
get_file_info = GetFileInfoTool()
|
|
319
|
-
list_allowed_directories = ListAllowedDirectoriesTool()
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# pylint: disable=unused-argument
|
|
3
|
-
import traceback
|
|
4
|
-
from typing import Optional, Any, Dict, Callable, Union
|
|
5
|
-
|
|
6
|
-
import inspect
|
|
7
|
-
from functools import partial
|
|
8
|
-
|
|
9
|
-
from .tool import Tool
|
|
10
|
-
from ..registry import SandboxType
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class FunctionTool(Tool):
|
|
14
|
-
"""Function tool class for direct function calls.
|
|
15
|
-
|
|
16
|
-
This tool class is designed for calling regular Python functions directly,
|
|
17
|
-
WITHOUT running in a sandbox environment. Unlike SandboxTool which executes
|
|
18
|
-
tools within isolated sandbox environments, FunctionTool executes functions
|
|
19
|
-
in the current Python process context.
|
|
20
|
-
|
|
21
|
-
Key differences from SandboxTool:
|
|
22
|
-
- No sandbox isolation: functions run in the same process.
|
|
23
|
-
- Direct function execution with immediate access to local variables and
|
|
24
|
-
imports.
|
|
25
|
-
- No security boundaries: functions have full access to the runtime
|
|
26
|
-
environment.
|
|
27
|
-
- Suitable for trusted, lightweight operations.
|
|
28
|
-
|
|
29
|
-
Use cases:
|
|
30
|
-
- Simple computational functions.
|
|
31
|
-
- Data processing utilities.
|
|
32
|
-
- Internal helper functions.
|
|
33
|
-
- Functions that don't require sandbox isolation.
|
|
34
|
-
|
|
35
|
-
Security note:
|
|
36
|
-
Since functions run without sandbox protection, ensure that:
|
|
37
|
-
- Functions are from trusted sources.
|
|
38
|
-
- Input validation is handled appropriately.
|
|
39
|
-
- Functions don't perform dangerous operations in production.
|
|
40
|
-
|
|
41
|
-
Example:
|
|
42
|
-
def add_numbers(a: int, b: int) -> int:
|
|
43
|
-
return a + b
|
|
44
|
-
|
|
45
|
-
tool = FunctionTool(add_numbers)
|
|
46
|
-
result = tool(a=1, b=2) # Executes directly, returns 3
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
def __init__(
|
|
50
|
-
self,
|
|
51
|
-
func: Callable,
|
|
52
|
-
name: Optional[str] = None,
|
|
53
|
-
schema: Optional[Dict] = None,
|
|
54
|
-
tool_type: str = "function",
|
|
55
|
-
description: Optional[str] = None,
|
|
56
|
-
):
|
|
57
|
-
"""
|
|
58
|
-
Initialize the function tool.
|
|
59
|
-
Args:
|
|
60
|
-
func: The function to call (can be a partial function)
|
|
61
|
-
name: Tool name, defaults to function name
|
|
62
|
-
schema: Tool schema, auto-generated if not provided
|
|
63
|
-
tool_type: Tool type
|
|
64
|
-
description: Tool description
|
|
65
|
-
"""
|
|
66
|
-
self._func = func
|
|
67
|
-
self._name: str = name or self._extract_function_name(func)
|
|
68
|
-
self._tool_type: str = tool_type
|
|
69
|
-
self._description = description or func.__doc__ or f"Call {self._name}"
|
|
70
|
-
# Auto-generate schema if not provided
|
|
71
|
-
if schema is None:
|
|
72
|
-
self._schema = self._generate_schema_from_func(func)
|
|
73
|
-
else:
|
|
74
|
-
self._schema = {
|
|
75
|
-
"name": self._name,
|
|
76
|
-
"description": self._description,
|
|
77
|
-
**schema,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
@property
|
|
81
|
-
def name(self) -> str:
|
|
82
|
-
return self._name
|
|
83
|
-
|
|
84
|
-
@property
|
|
85
|
-
def tool_type(self) -> str:
|
|
86
|
-
return self._tool_type
|
|
87
|
-
|
|
88
|
-
@property
|
|
89
|
-
def schema(self) -> Dict:
|
|
90
|
-
return {
|
|
91
|
-
"type": "function",
|
|
92
|
-
"function": self._schema,
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@property
|
|
96
|
-
def sandbox_type(self) -> SandboxType:
|
|
97
|
-
"""Function tools don't need a sandbox type"""
|
|
98
|
-
return SandboxType.DUMMY
|
|
99
|
-
|
|
100
|
-
@property
|
|
101
|
-
def sandbox(self) -> None:
|
|
102
|
-
"""Function tools don't have sandbox"""
|
|
103
|
-
return None
|
|
104
|
-
|
|
105
|
-
def __call__(self, **kwargs):
|
|
106
|
-
"""Call the function directly"""
|
|
107
|
-
return self.call(**kwargs)
|
|
108
|
-
|
|
109
|
-
def call(self, *, sandbox: Optional[Any] = None, **kwargs):
|
|
110
|
-
"""
|
|
111
|
-
Execute the function call.
|
|
112
|
-
Args:
|
|
113
|
-
sandbox: Ignored for function tools (for interface compatibility)
|
|
114
|
-
**kwargs: Function parameters
|
|
115
|
-
"""
|
|
116
|
-
# Filter kwargs to only include parameters that the function accepts
|
|
117
|
-
filtered_kwargs = self._filter_kwargs(kwargs)
|
|
118
|
-
try:
|
|
119
|
-
return {
|
|
120
|
-
"meta": None,
|
|
121
|
-
"content": [
|
|
122
|
-
{
|
|
123
|
-
"type": "text",
|
|
124
|
-
"text": str(self._func(**filtered_kwargs)),
|
|
125
|
-
"annotations": None,
|
|
126
|
-
"description": "None",
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
"isError": False,
|
|
130
|
-
}
|
|
131
|
-
except Exception as e:
|
|
132
|
-
return {
|
|
133
|
-
"meta": None,
|
|
134
|
-
"content": [
|
|
135
|
-
{
|
|
136
|
-
"type": "text",
|
|
137
|
-
"text": f"{e}:\n{traceback.format_exc()}",
|
|
138
|
-
"annotations": None,
|
|
139
|
-
"description": "None",
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
"isError": True,
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
def bind(self, *args, **kwargs):
|
|
146
|
-
"""
|
|
147
|
-
Return a new instance with pre-bound parameters (similar to
|
|
148
|
-
functools.partial).
|
|
149
|
-
"""
|
|
150
|
-
return self.__class__(
|
|
151
|
-
func=self._func,
|
|
152
|
-
name=self._name,
|
|
153
|
-
tool_type=self._tool_type,
|
|
154
|
-
description=self._description,
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
def _extract_function_name(self, func: Callable) -> str:
|
|
158
|
-
"""Extract function name from function or partial"""
|
|
159
|
-
if isinstance(func, partial):
|
|
160
|
-
return getattr(func.func, "__name__", "partial_function")
|
|
161
|
-
return getattr(func, "__name__", "unknown_function")
|
|
162
|
-
|
|
163
|
-
def _filter_kwargs(self, kwargs: Dict) -> Dict:
|
|
164
|
-
"""Filter kwargs to match function signature"""
|
|
165
|
-
if isinstance(self._func, partial):
|
|
166
|
-
sig = inspect.signature(self._func.func)
|
|
167
|
-
# Remove already bound parameters
|
|
168
|
-
bound_params = set(self._func.keywords.keys())
|
|
169
|
-
else:
|
|
170
|
-
sig = inspect.signature(self._func)
|
|
171
|
-
bound_params = set()
|
|
172
|
-
|
|
173
|
-
filtered = {}
|
|
174
|
-
for param_name, param in sig.parameters.items():
|
|
175
|
-
if param_name in bound_params:
|
|
176
|
-
continue
|
|
177
|
-
if param_name in kwargs:
|
|
178
|
-
filtered[param_name] = kwargs[param_name]
|
|
179
|
-
elif (
|
|
180
|
-
param.default == inspect.Parameter.empty
|
|
181
|
-
and param.kind != param.VAR_KEYWORD
|
|
182
|
-
):
|
|
183
|
-
# Required parameter is missing
|
|
184
|
-
raise TypeError(f"Missing required parameter: {param_name}")
|
|
185
|
-
|
|
186
|
-
# If function accepts **kwargs, include remaining parameters
|
|
187
|
-
if any(p.kind == p.VAR_KEYWORD for p in sig.parameters.values()):
|
|
188
|
-
used_params = set(sig.parameters.keys()) | bound_params
|
|
189
|
-
for key, value in kwargs.items():
|
|
190
|
-
if key not in used_params:
|
|
191
|
-
filtered[key] = value
|
|
192
|
-
|
|
193
|
-
return filtered
|
|
194
|
-
|
|
195
|
-
def _generate_schema_from_func(self, func: Callable) -> Dict:
|
|
196
|
-
"""Generate schema from function signature"""
|
|
197
|
-
if isinstance(func, partial):
|
|
198
|
-
actual_func = func.func
|
|
199
|
-
bound_kwargs = func.keywords
|
|
200
|
-
else:
|
|
201
|
-
actual_func = func
|
|
202
|
-
bound_kwargs = {}
|
|
203
|
-
|
|
204
|
-
sig = inspect.signature(actual_func)
|
|
205
|
-
parameters = {}
|
|
206
|
-
required = []
|
|
207
|
-
|
|
208
|
-
for param_name, param in sig.parameters.items():
|
|
209
|
-
# Skip already bound parameters
|
|
210
|
-
if param_name in bound_kwargs:
|
|
211
|
-
continue
|
|
212
|
-
|
|
213
|
-
param_info = self._get_param_info(param)
|
|
214
|
-
parameters[param_name] = param_info
|
|
215
|
-
|
|
216
|
-
# Check if parameter is required
|
|
217
|
-
if (
|
|
218
|
-
param.default == inspect.Parameter.empty
|
|
219
|
-
and param.kind
|
|
220
|
-
not in (
|
|
221
|
-
param.VAR_POSITIONAL,
|
|
222
|
-
param.VAR_KEYWORD,
|
|
223
|
-
)
|
|
224
|
-
):
|
|
225
|
-
required.append(param_name)
|
|
226
|
-
|
|
227
|
-
schema = {
|
|
228
|
-
"name": self._name,
|
|
229
|
-
"description": self._description,
|
|
230
|
-
"parameters": {
|
|
231
|
-
"type": "object",
|
|
232
|
-
"properties": parameters,
|
|
233
|
-
"required": required,
|
|
234
|
-
},
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return schema
|
|
238
|
-
|
|
239
|
-
def _get_param_info(self, param: inspect.Parameter) -> Dict:
|
|
240
|
-
"""Get parameter info for schema"""
|
|
241
|
-
param_info = {"type": "string"} # default type
|
|
242
|
-
|
|
243
|
-
# Try to infer type from annotation
|
|
244
|
-
if param.annotation != inspect.Parameter.empty:
|
|
245
|
-
param_info.update(
|
|
246
|
-
self._annotation_to_schema_type(param.annotation),
|
|
247
|
-
)
|
|
248
|
-
|
|
249
|
-
# Add default value if exists
|
|
250
|
-
if param.default != inspect.Parameter.empty:
|
|
251
|
-
param_info["default"] = param.default
|
|
252
|
-
|
|
253
|
-
return param_info
|
|
254
|
-
|
|
255
|
-
def _annotation_to_schema_type(self, annotation) -> Dict:
|
|
256
|
-
"""Convert Python type annotation to JSON schema type"""
|
|
257
|
-
type_mapping = {
|
|
258
|
-
int: {"type": "integer"},
|
|
259
|
-
float: {"type": "number"},
|
|
260
|
-
bool: {"type": "boolean"},
|
|
261
|
-
str: {"type": "string"},
|
|
262
|
-
list: {"type": "array"},
|
|
263
|
-
dict: {"type": "object"},
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
# Handle Union types (Optional)
|
|
267
|
-
if hasattr(annotation, "__origin__"):
|
|
268
|
-
if annotation.__origin__ is Union:
|
|
269
|
-
args = annotation.__args__
|
|
270
|
-
if (
|
|
271
|
-
len(args) == 2 and type(None) in args
|
|
272
|
-
): # This is Optional[T]
|
|
273
|
-
non_none_type = next(
|
|
274
|
-
arg for arg in args if arg is not type(None)
|
|
275
|
-
)
|
|
276
|
-
result = self._annotation_to_schema_type(non_none_type)
|
|
277
|
-
# Mark as optional (though this is handled in required
|
|
278
|
-
# array)
|
|
279
|
-
return result
|
|
280
|
-
|
|
281
|
-
return type_mapping.get(annotation, {"type": "string"})
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
def create_function_tool(
|
|
285
|
-
func: Callable,
|
|
286
|
-
name: Optional[str] = None,
|
|
287
|
-
**kwargs,
|
|
288
|
-
) -> FunctionTool:
|
|
289
|
-
"""
|
|
290
|
-
Factory function to create a FunctionTool.
|
|
291
|
-
|
|
292
|
-
Args:func: Function or partial function
|
|
293
|
-
name: Tool name
|
|
294
|
-
**kwargs: Additional arguments for FunctionToolReturns:
|
|
295
|
-
FunctionTool instance
|
|
296
|
-
"""
|
|
297
|
-
return FunctionTool(func=func, name=name, **kwargs)
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
def function_tool(
|
|
301
|
-
name: Optional[str] = None,
|
|
302
|
-
description: Optional[str] = None,
|
|
303
|
-
**tool_kwargs,
|
|
304
|
-
):
|
|
305
|
-
"""
|
|
306
|
-
Decorator to convert a function into a FunctionTool.
|
|
307
|
-
Usage:
|
|
308
|
-
@function_tool(name="my_calculator", description="A simple calculator")
|
|
309
|
-
def add(a: int, b: int) -> int:
|
|
310
|
-
return a + b
|
|
311
|
-
"""
|
|
312
|
-
|
|
313
|
-
def decorator(func):
|
|
314
|
-
return FunctionTool(
|
|
315
|
-
func=func,
|
|
316
|
-
name=name,
|
|
317
|
-
description=description,
|
|
318
|
-
**tool_kwargs,
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
return decorator
|