From b7e8b45f6463309b6d2fc39dc408057d2c4f4f5f Mon Sep 17 00:00:00 2001 From: Matthew Zhou Date: Thu, 30 Jan 2025 13:37:00 -1000 Subject: [PATCH] feat: Adjust get_composio_key (#866) --- letta/server/rest_api/routers/v1/tools.py | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.py index d0f918f2..65a403c8 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.", - ) + logger.warning(f"No API keys found for Composio. Defaulting to the environment variable...") - # 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 + 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