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.

feat: Adjust get_composio_key (#866)

Matthew Zhoue42d400803b2
diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.py
index d0f918f20..65a403c83 100644
--- a/letta/server/rest_api/routers/v1/tools.py
+++ b/letta/server/rest_api/routers/v1/tools.py
@@ -8,15 +8,19 @@ from composio.tools.base.abs import InvalidClassDefinition
from fastapi import APIRouter, Body, Depends, Header, HTTPException
from letta.errors import LettaToolCreateError
+from letta.log import get_logger
from letta.orm.errors import UniqueConstraintViolationError
from letta.schemas.letta_message import ToolReturnMessage
from letta.schemas.tool import Tool, ToolCreate, ToolRunFromSource, ToolUpdate
from letta.schemas.user import User
from letta.server.rest_api.utils import get_letta_server
from letta.server.server import SyncServer
+from letta.settings import tool_settings
router = APIRouter(prefix="/tools", tags=["tools"])
+logger = get_logger(__name__)
+
@router.delete("/{tool_id}", operation_id="delete_tool")
def delete_tool(
@@ -297,12 +301,18 @@ def add_composio_tool(
def get_composio_key(server: SyncServer, actor: User):
api_keys = server.sandbox_config_manager.list_sandbox_env_vars_by_key(key="COMPOSIO_API_KEY", actor=actor)
if not api_keys:
- raise HTTPException(
- status_code=400, # Bad Request
- detail=f"No API keys found for Composio. Please add your Composio API Key as an environment variable for your sandbox configuration.",
- )
-
- # TODO: Add more protections around this
- # Ideally, not tied to a specific sandbox, but for now we just get the first one
- # Theoretically possible for someone to have different composio api keys per sandbox
- return api_keys[0].value
+ logger.warning(f"No API keys found for Composio. Defaulting to the environment variable...")
+
+ if tool_settings.composio_api_key:
+ return tool_settings.composio_api_key
+ else:
+ # Nothing, raise fatal warning
+ raise HTTPException(
+ status_code=400, # Bad Request
+ detail=f"No API keys found for Composio. Please add your Composio API Key as an environment variable for your sandbox configuration, or set it as environment variable COMPOSIO_API_KEY.",
+ )
+ else:
+ # TODO: Add more protections around this
+ # Ideally, not tied to a specific sandbox, but for now we just get the first one
+ # Theoretically possible for someone to have different composio api keys per sandbox
+ return api_keys[0].value