alita-sdk 0.3.337__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.

@@ -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 = True
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 install Deno manually or ensure it's available in PATH."
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, use the bootstrap.sh script or install manually.
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.337
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
@@ -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=_v8ACXV4POFRIuM7iU1NTm3-OL5pBmONl5z7bjDmBtw,9053
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.337.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
354
- alita_sdk-0.3.337.dist-info/METADATA,sha256=BWEeyZsFO8oG3JOc7z8vy-nS-xJZxruNuEE1zm29HQc,18901
355
- alita_sdk-0.3.337.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
356
- alita_sdk-0.3.337.dist-info/top_level.txt,sha256=0vJYy5p_jK6AwVb1aqXr7Kgqgk3WDtQ6t5C-XI9zkmg,10
357
- alita_sdk-0.3.337.dist-info/RECORD,,
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,,