Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: Suppress warnings during local sandbox tool execution w/ venv (#2164)

Matthew Zhouf3470f4bde5d
diff --git a/letta/services/tool_execution_sandbox.py b/letta/services/tool_execution_sandbox.py
index 4dedfb3bb..98c8603a4 100644
--- a/letta/services/tool_execution_sandbox.py
+++ b/letta/services/tool_execution_sandbox.py
@@ -159,6 +159,8 @@ class ToolExecutionSandbox:
# Set up env for venv
env["VIRTUAL_ENV"] = venv_path
env["PATH"] = os.path.join(venv_path, "bin") + ":" + env["PATH"]
+ # Suppress all warnings
+ env["PYTHONWARNINGS"] = "ignore"
# Execute the code in a restricted subprocess
try:
diff --git a/tests/integration_test_tool_execution_sandbox.py b/tests/integration_test_tool_execution_sandbox.py
index bb414fae8..09129e49c 100644
--- a/tests/integration_test_tool_execution_sandbox.py
+++ b/tests/integration_test_tool_execution_sandbox.py
@@ -163,6 +163,26 @@ def get_env_tool(test_user):
yield tool
+def get_warning_tool(test_user):
+ def warn_hello_world() -> str:
+ """
+ Simple function that warns hello world.
+
+ Returns:
+ str: hello world
+ """
+ import warnings
+
+ msg = "Hello World"
+ warnings.warn(msg)
+ return msg
+
+ tool = create_tool_from_func(warn_hello_world)
+ tool = ToolManager().create_or_update_tool(tool, test_user)
+ yield tool
+
+
@pytest.fixture
def list_tool(test_user):
def create_list():
@@ -349,6 +369,22 @@ def test_local_sandbox_external_codebase(mock_e2b_api_key_none, external_codebas
assert "Hello World" in result.stdout[0]
+def test_local_sandbox_with_venv_and_warnings_does_not_error(mock_e2b_api_key_none, get_warning_tool, test_user):
+ # Make the external codebase the sandbox config
+ manager = SandboxConfigManager(tool_settings)
+
+ # Set the sandbox to be within the external codebase path and use a venv
+ external_codebase_path = str(Path(__file__).parent / "test_tool_sandbox" / "restaurant_management_system")
+ local_sandbox_config = LocalSandboxConfig(sandbox_dir=external_codebase_path, use_venv=True)
+ config_create = SandboxConfigCreate(config=local_sandbox_config.model_dump())
+ manager.create_or_update_sandbox_config(sandbox_config_create=config_create, actor=test_user)
+
+ sandbox = ToolExecutionSandbox(get_warning_tool.name, {}, user_id=test_user.id)
+ result = sandbox.run()
+ assert result.func_return == "Hello World"
+
+
# E2B sandbox tests