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.pyindex 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 InvalidClassDefinitionfrom fastapi import APIRouter, Body, Depends, Header, HTTPExceptionfrom letta.errors import LettaToolCreateError+from letta.log import get_loggerfrom letta.orm.errors import UniqueConstraintViolationErrorfrom letta.schemas.letta_message import ToolReturnMessagefrom letta.schemas.tool import Tool, ToolCreate, ToolRunFromSource, ToolUpdatefrom letta.schemas.user import Userfrom letta.server.rest_api.utils import get_letta_serverfrom letta.server.server import SyncServer+from letta.settings import tool_settingsrouter = 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