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.

Finish

Matt Zhou827a31d07d32
diff --git a/letta/server/server.py b/letta/server/server.py
index 03604a89d..c4699eb37 100644
--- a/letta/server/server.py
+++ b/letta/server/server.py
@@ -53,6 +53,7 @@ from letta.schemas.memory import ArchivalMemorySummary, ContextWindowOverview, M
from letta.schemas.message import Message, MessageCreate, MessageRole, MessageUpdate
from letta.schemas.organization import Organization
from letta.schemas.passage import Passage
+from letta.schemas.sandbox_config import SandboxType, SandboxEnvironmentVariableCreate
from letta.schemas.source import Source
from letta.schemas.tool import Tool
from letta.schemas.usage import LettaUsageStatistics
@@ -298,6 +299,17 @@ class SyncServer(Server):
self.block_manager.add_default_blocks(actor=self.default_user)
self.tool_manager.upsert_base_tools(actor=self.default_user)
+ # Add composio keys to the tool sandbox env vars of the org
+ if tool_settings.composio_api_key:
+ manager = SandboxConfigManager(tool_settings)
+ sandbox_config = manager.get_or_create_default_sandbox_config(sandbox_type=SandboxType.LOCAL, actor=self.default_user)
+
+ manager.create_sandbox_env_var(
+ SandboxEnvironmentVariableCreate(key="COMPOSIO_API_KEY", value=tool_settings.composio_api_key),
+ sandbox_config_id=sandbox_config.id,
+ actor=self.default_user,
+ )
+
# collect providers (always has Letta as a default)
self._enabled_providers: List[Provider] = [LettaProvider()]
if model_settings.openai_api_key:
diff --git a/letta/services/tool_execution_sandbox.py b/letta/services/tool_execution_sandbox.py
index fc6e1bdd3..b05b6ce23 100644
--- a/letta/services/tool_execution_sandbox.py
+++ b/letta/services/tool_execution_sandbox.py
@@ -127,7 +127,7 @@ class ToolExecutionSandbox:
if local_configs.use_venv:
return self.run_local_dir_sandbox_venv(sbx_config, env, temp_file_path)
else:
- return self.run_local_dir_sandbox_runpy(sbx_config, env_vars, temp_file_path)
+ return self.run_local_dir_sandbox_runpy(sbx_config, env, temp_file_path)
except Exception as e:
logger.error(f"Executing tool {self.tool_name} has an unexpected error: {e}")
logger.error(f"Logging out tool {self.tool_name} auto-generated code for debugging: \n\n{code}")
@@ -200,7 +200,7 @@ class ToolExecutionSandbox:
logger.error(f"Executing tool {self.tool_name} has an unexpected error: {e}")
raise e
- def run_local_dir_sandbox_runpy(self, sbx_config: SandboxConfig, env_vars: Dict[str, str], temp_file_path: str) -> SandboxRunResult:
+ def run_local_dir_sandbox_runpy(self, sbx_config: SandboxConfig, env: Dict[str, str], temp_file_path: str) -> SandboxRunResult:
status = "success"
agent_state, stderr = None, None
@@ -213,8 +213,8 @@ class ToolExecutionSandbox:
try:
# Execute the temp file
- with self.temporary_env_vars(env_vars):
- result = runpy.run_path(temp_file_path, init_globals=env_vars)
+ with self.temporary_env_vars(env):
+ result = runpy.run_path(temp_file_path, init_globals=env)
# Fetch the result
func_result = result.get(self.LOCAL_SANDBOX_RESULT_VAR_NAME)
diff --git a/tests/integration_test_composio.py b/tests/integration_test_composio.py
new file mode 100644
index 000000000..7caf33250
--- /dev/null
+++ b/tests/integration_test_composio.py
@@ -0,0 +1,32 @@
+import pytest
+from fastapi.testclient import TestClient
+
+from letta.server.rest_api.app import app
+
+
+def client():
+ return TestClient(app)
+
+def test_list_composio_apps(client):
+ response = client.get(
+ "/v1/tools/composio/apps"
+ )
+ assert response.status_code == 200
+ assert isinstance(response.json(), list)
+
+def test_list_composio_actions_by_app(client):
+ response = client.get(
+ "/v1/tools/composio/apps/github/actions"
+ )
+ assert response.status_code == 200
+ assert isinstance(response.json(), list)
+
+def test_add_composio_tool(client):
+ response = client.post(
+ "/v1/tools/composio/GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER"
+ )
+ assert response.status_code == 200
+ assert "id" in response.json()
+ assert "name" in response.json()
+
diff --git a/tests/integration_test_tool_execution_sandbox.py b/tests/integration_test_tool_execution_sandbox.py
index 97346021b..b84bcd51a 100644
--- a/tests/integration_test_tool_execution_sandbox.py
+++ b/tests/integration_test_tool_execution_sandbox.py
@@ -351,6 +351,12 @@ def test_local_sandbox_e2e_composio_star_github(mock_e2b_api_key_none, check_com
assert result.func_return["details"] == "Action executed successfully"
+def test_local_sandbox_e2e_composio_star_github_without_setting_db_env_vars(mock_e2b_api_key_none, check_composio_key_set, composio_github_star_tool, test_user):
+ result = ToolExecutionSandbox(composio_github_star_tool.name, {"owner": "letta-ai", "repo": "letta"}, user=test_user).run()
+ assert result.func_return["details"] == "Action executed successfully"
+
+
@pytest.mark.local_sandbox
def test_local_sandbox_external_codebase(mock_e2b_api_key_none, custom_test_sandbox_config, external_codebase_tool, test_user):
# Set the args