alita-sdk 0.3.336__py3-none-any.whl → 0.3.338__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.
Potentially problematic release.
This version of alita-sdk might be problematic. Click here for more details.
- alita_sdk/runtime/tools/sandbox.py +57 -7
- {alita_sdk-0.3.336.dist-info → alita_sdk-0.3.338.dist-info}/METADATA +8 -9
- {alita_sdk-0.3.336.dist-info → alita_sdk-0.3.338.dist-info}/RECORD +6 -6
- {alita_sdk-0.3.336.dist-info → alita_sdk-0.3.338.dist-info}/WHEEL +0 -0
- {alita_sdk-0.3.336.dist-info → alita_sdk-0.3.338.dist-info}/licenses/LICENSE +0 -0
- {alita_sdk-0.3.336.dist-info → alita_sdk-0.3.338.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import asyncio
|
|
3
3
|
import subprocess
|
|
4
|
+
import os
|
|
4
5
|
from typing import Any, Type, Optional, Union, Dict
|
|
5
6
|
from langchain_core.tools import BaseTool
|
|
6
7
|
from pydantic import BaseModel, Field, create_model
|
|
@@ -22,6 +23,42 @@ def _is_deno_available() -> bool:
|
|
|
22
23
|
except (subprocess.TimeoutExpired, subprocess.CalledProcessError, FileNotFoundError):
|
|
23
24
|
return False
|
|
24
25
|
|
|
26
|
+
|
|
27
|
+
def _setup_pyodide_cache_env() -> None:
|
|
28
|
+
"""Setup Pyodide caching environment variables for performance optimization"""
|
|
29
|
+
try:
|
|
30
|
+
# Check if cache environment file exists and source it
|
|
31
|
+
cache_env_file = os.path.expanduser("~/.pyodide_cache_env")
|
|
32
|
+
if os.path.exists(cache_env_file):
|
|
33
|
+
with open(cache_env_file, 'r') as f:
|
|
34
|
+
for line in f:
|
|
35
|
+
line = line.strip()
|
|
36
|
+
if line.startswith('export ') and '=' in line:
|
|
37
|
+
# Parse export VAR=value format
|
|
38
|
+
var_assignment = line[7:] # Remove 'export '
|
|
39
|
+
if '=' in var_assignment:
|
|
40
|
+
key, value = var_assignment.split('=', 1)
|
|
41
|
+
# Remove quotes if present
|
|
42
|
+
value = value.strip('"').strip("'")
|
|
43
|
+
os.environ[key] = value
|
|
44
|
+
logger.debug(f"Set Pyodide cache env: {key}={value}")
|
|
45
|
+
|
|
46
|
+
# Set default caching environment variables if not already set
|
|
47
|
+
cache_defaults = {
|
|
48
|
+
'PYODIDE_PACKAGES_PATH': os.path.expanduser('~/.cache/pyodide'),
|
|
49
|
+
'DENO_DIR': os.path.expanduser('~/.cache/deno'),
|
|
50
|
+
'PYODIDE_CACHE_DIR': os.path.expanduser('~/.cache/pyodide'),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for key, default_value in cache_defaults.items():
|
|
54
|
+
if key not in os.environ:
|
|
55
|
+
os.environ[key] = default_value
|
|
56
|
+
logger.debug(f"Set default Pyodide env: {key}={default_value}")
|
|
57
|
+
|
|
58
|
+
except Exception as e:
|
|
59
|
+
logger.warning(f"Could not setup Pyodide cache environment: {e}")
|
|
60
|
+
|
|
61
|
+
|
|
25
62
|
# Create input schema for the sandbox tool
|
|
26
63
|
sandbox_tool_input = create_model(
|
|
27
64
|
"SandboxToolInput",
|
|
@@ -33,6 +70,7 @@ class PyodideSandboxTool(BaseTool):
|
|
|
33
70
|
"""
|
|
34
71
|
A tool that provides secure Python code execution using Pyodide (Python compiled to WebAssembly).
|
|
35
72
|
This tool leverages langchain-sandbox to provide a safe environment for running untrusted Python code.
|
|
73
|
+
Optimized for performance with caching and stateless execution by default.
|
|
36
74
|
"""
|
|
37
75
|
|
|
38
76
|
name: str = "pyodide_sandbox"
|
|
@@ -46,9 +84,10 @@ class PyodideSandboxTool(BaseTool):
|
|
|
46
84
|
|
|
47
85
|
The sandbox supports most Python standard library modules and can install additional packages.
|
|
48
86
|
Note: File access and some system operations are restricted for security.
|
|
87
|
+
Optimized for performance with local caching (stateless by default for faster execution).
|
|
49
88
|
"""
|
|
50
89
|
args_schema: Type[BaseModel] = sandbox_tool_input
|
|
51
|
-
stateful: bool =
|
|
90
|
+
stateful: bool = False # Default to stateless for better performance
|
|
52
91
|
allow_net: bool = True
|
|
53
92
|
session_bytes: Optional[bytes] = None
|
|
54
93
|
session_metadata: Optional[Dict] = None
|
|
@@ -56,26 +95,32 @@ class PyodideSandboxTool(BaseTool):
|
|
|
56
95
|
def __init__(self, **kwargs: Any) -> None:
|
|
57
96
|
super().__init__(**kwargs)
|
|
58
97
|
self._sandbox = None
|
|
98
|
+
# Setup caching environment for optimal performance
|
|
99
|
+
_setup_pyodide_cache_env()
|
|
59
100
|
self._initialize_sandbox()
|
|
60
101
|
|
|
61
102
|
def _initialize_sandbox(self) -> None:
|
|
62
|
-
"""Initialize the PyodideSandbox instance"""
|
|
103
|
+
"""Initialize the PyodideSandbox instance with optimized settings"""
|
|
63
104
|
try:
|
|
64
105
|
# Check if Deno is available
|
|
65
106
|
if not _is_deno_available():
|
|
66
107
|
error_msg = (
|
|
67
108
|
"Deno is required for PyodideSandbox but is not installed. "
|
|
68
|
-
"Please
|
|
109
|
+
"Please run the bootstrap.sh script or install Deno manually."
|
|
69
110
|
)
|
|
70
111
|
logger.error(error_msg)
|
|
71
112
|
raise RuntimeError(error_msg)
|
|
72
113
|
|
|
73
114
|
from langchain_sandbox import PyodideSandbox
|
|
115
|
+
|
|
116
|
+
# Configure sandbox with performance optimizations
|
|
74
117
|
self._sandbox = PyodideSandbox(
|
|
75
118
|
stateful=self.stateful,
|
|
76
|
-
allow_net=self.allow_net
|
|
119
|
+
allow_net=self.allow_net,
|
|
120
|
+
# Use auto node_modules_dir for better caching
|
|
121
|
+
node_modules_dir="auto"
|
|
77
122
|
)
|
|
78
|
-
logger.info("PyodideSandbox initialized successfully")
|
|
123
|
+
logger.info(f"PyodideSandbox initialized successfully (stateful={self.stateful})")
|
|
79
124
|
except ImportError as e:
|
|
80
125
|
if "langchain_sandbox" in str(e):
|
|
81
126
|
error_msg = (
|
|
@@ -205,10 +250,10 @@ def create_sandbox_tool(stateful: bool = False, allow_net: bool = True) -> BaseT
|
|
|
205
250
|
Factory function to create sandbox tools with specified configuration.
|
|
206
251
|
|
|
207
252
|
Note: This tool requires Deno to be installed and available in PATH.
|
|
208
|
-
For installation,
|
|
253
|
+
For installation and optimization, run the bootstrap.sh script.
|
|
209
254
|
|
|
210
255
|
Args:
|
|
211
|
-
stateful: Whether to maintain state between executions
|
|
256
|
+
stateful: Whether to maintain state between executions (default: False for better performance)
|
|
212
257
|
allow_net: Whether to allow network access (for package installation)
|
|
213
258
|
|
|
214
259
|
Returns:
|
|
@@ -217,6 +262,11 @@ def create_sandbox_tool(stateful: bool = False, allow_net: bool = True) -> BaseT
|
|
|
217
262
|
Raises:
|
|
218
263
|
ImportError: If langchain-sandbox is not installed
|
|
219
264
|
RuntimeError: If Deno is not found in PATH
|
|
265
|
+
|
|
266
|
+
Performance Notes:
|
|
267
|
+
- Stateless mode (default) is faster and avoids session state overhead
|
|
268
|
+
- Run bootstrap.sh script to enable local caching and reduce initialization time
|
|
269
|
+
- Cached wheels reduce package download time from ~4.76s to near-instant
|
|
220
270
|
"""
|
|
221
271
|
if stateful:
|
|
222
272
|
return StatefulPyodideSandboxTool(allow_net=allow_net)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: alita_sdk
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.338
|
|
4
4
|
Summary: SDK for building langchain agents using resources from Alita
|
|
5
5
|
Author-email: Artem Rozumenko <artyom.rozumenko@gmail.com>, Mikalai Biazruchka <mikalai_biazruchka@epam.com>, Roman Mitusov <roman_mitusov@epam.com>, Ivan Krakhmaliuk <lifedj27@gmail.com>, Artem Dubrovskiy <ad13box@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -25,15 +25,17 @@ Requires-Dist: httpcore==1.0.7
|
|
|
25
25
|
Requires-Dist: urllib3>=2
|
|
26
26
|
Requires-Dist: certifi==2024.8.30
|
|
27
27
|
Provides-Extra: runtime
|
|
28
|
-
Requires-Dist: langchain_core
|
|
29
|
-
Requires-Dist: langchain
|
|
30
|
-
Requires-Dist: langchain_community
|
|
31
|
-
Requires-Dist: langchain-openai
|
|
28
|
+
Requires-Dist: langchain_core<0.4.0,>=0.3.76; extra == "runtime"
|
|
29
|
+
Requires-Dist: langchain<0.4.0,>=0.3.22; extra == "runtime"
|
|
30
|
+
Requires-Dist: langchain_community<0.4.0,>=0.3.7; extra == "runtime"
|
|
31
|
+
Requires-Dist: langchain-openai<0.4.0,>=0.3.0; extra == "runtime"
|
|
32
|
+
Requires-Dist: langchain-anthropic<0.4.0,>=0.3.10; extra == "runtime"
|
|
33
|
+
Requires-Dist: anthropic>=0.57.0; extra == "runtime"
|
|
32
34
|
Requires-Dist: langgraph-checkpoint-sqlite~=2.0.0; extra == "runtime"
|
|
33
35
|
Requires-Dist: langgraph-checkpoint-postgres==2.0.21; extra == "runtime"
|
|
34
36
|
Requires-Dist: langsmith>=0.3.45; extra == "runtime"
|
|
35
37
|
Requires-Dist: langgraph<0.5,>=0.4.8; extra == "runtime"
|
|
36
|
-
Requires-Dist: langchain_chroma
|
|
38
|
+
Requires-Dist: langchain_chroma<0.3.0,>=0.2.2; extra == "runtime"
|
|
37
39
|
Requires-Dist: langchain-unstructured~=0.1.6; extra == "runtime"
|
|
38
40
|
Requires-Dist: langchain-postgres~=0.0.13; extra == "runtime"
|
|
39
41
|
Requires-Dist: keybert==0.8.3; extra == "runtime"
|
|
@@ -97,8 +99,6 @@ Requires-Dist: azure-search-documents==11.5.2; extra == "tools"
|
|
|
97
99
|
Requires-Dist: PyMySQL==1.1.1; extra == "tools"
|
|
98
100
|
Requires-Dist: psycopg2-binary==2.9.10; extra == "tools"
|
|
99
101
|
Requires-Dist: Office365-REST-Python-Client==2.5.14; extra == "tools"
|
|
100
|
-
Requires-Dist: python-docx==1.1.2; extra == "tools"
|
|
101
|
-
Requires-Dist: python-pptx==1.0.2; extra == "tools"
|
|
102
102
|
Requires-Dist: pypdf2~=3.0.1; extra == "tools"
|
|
103
103
|
Requires-Dist: FigmaPy==2018.1.0; extra == "tools"
|
|
104
104
|
Requires-Dist: pandas==2.2.3; extra == "tools"
|
|
@@ -115,7 +115,6 @@ Requires-Dist: playwright>=1.52.0; extra == "tools"
|
|
|
115
115
|
Requires-Dist: google-api-python-client==2.154.0; extra == "tools"
|
|
116
116
|
Requires-Dist: wikipedia==1.4.0; extra == "tools"
|
|
117
117
|
Requires-Dist: lxml==5.2.2; extra == "tools"
|
|
118
|
-
Requires-Dist: beautifulsoup4; extra == "tools"
|
|
119
118
|
Requires-Dist: pymupdf==1.24.9; extra == "tools"
|
|
120
119
|
Requires-Dist: googlemaps==4.10.0; extra == "tools"
|
|
121
120
|
Requires-Dist: yagmail==0.15.293; extra == "tools"
|
|
@@ -119,7 +119,7 @@ alita_sdk/runtime/tools/mcp_server_tool.py,sha256=MhLxZJ44LYrB_0GrojmkyqKoDRaqIH
|
|
|
119
119
|
alita_sdk/runtime/tools/pgvector_search.py,sha256=NN2BGAnq4SsDHIhUcFZ8d_dbEOM8QwB0UwpsWCYruXU,11692
|
|
120
120
|
alita_sdk/runtime/tools/prompt.py,sha256=nJafb_e5aOM1Rr3qGFCR-SKziU9uCsiP2okIMs9PppM,741
|
|
121
121
|
alita_sdk/runtime/tools/router.py,sha256=wCvZjVkdXK9dMMeEerrgKf5M790RudH68pDortnHSz0,1517
|
|
122
|
-
alita_sdk/runtime/tools/sandbox.py,sha256=
|
|
122
|
+
alita_sdk/runtime/tools/sandbox.py,sha256=WNz-aUMtkGCPg84dDy_0BPkyp-6YjoYB-xjIEFFrtKw,11601
|
|
123
123
|
alita_sdk/runtime/tools/tool.py,sha256=lE1hGi6qOAXG7qxtqxarD_XMQqTghdywf261DZawwno,5631
|
|
124
124
|
alita_sdk/runtime/tools/vectorstore.py,sha256=UFBAJ_N2F6uB0xxIy1VMx581tHco-xDl7v2Hl6u0Xzw,34468
|
|
125
125
|
alita_sdk/runtime/tools/vectorstore_base.py,sha256=qmidtzD2SFZdUDrmKNkUWnuBHqJDjPbQQJ_z1TqIl0g,27283
|
|
@@ -350,8 +350,8 @@ alita_sdk/tools/zephyr_scale/api_wrapper.py,sha256=kT0TbmMvuKhDUZc0i7KO18O38JM9S
|
|
|
350
350
|
alita_sdk/tools/zephyr_squad/__init__.py,sha256=0ne8XLJEQSLOWfzd2HdnqOYmQlUliKHbBED5kW_Vias,2895
|
|
351
351
|
alita_sdk/tools/zephyr_squad/api_wrapper.py,sha256=kmw_xol8YIYFplBLWTqP_VKPRhL_1ItDD0_vXTe_UuI,14906
|
|
352
352
|
alita_sdk/tools/zephyr_squad/zephyr_squad_cloud_client.py,sha256=R371waHsms4sllHCbijKYs90C-9Yu0sSR3N4SUfQOgU,5066
|
|
353
|
-
alita_sdk-0.3.
|
|
354
|
-
alita_sdk-0.3.
|
|
355
|
-
alita_sdk-0.3.
|
|
356
|
-
alita_sdk-0.3.
|
|
357
|
-
alita_sdk-0.3.
|
|
353
|
+
alita_sdk-0.3.338.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
354
|
+
alita_sdk-0.3.338.dist-info/METADATA,sha256=JCh2biWyamVC1ZnDrAOGqrxctL38ArPoq4Uu_QTLw9w,18901
|
|
355
|
+
alita_sdk-0.3.338.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
356
|
+
alita_sdk-0.3.338.dist-info/top_level.txt,sha256=0vJYy5p_jK6AwVb1aqXr7Kgqgk3WDtQ6t5C-XI9zkmg,10
|
|
357
|
+
alita_sdk-0.3.338.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|