feat: Adjust get_composio_key (#866)

This commit is contained in:
Matthew Zhou
2025-01-30 13:37:00 -10:00
committed by GitHub
parent 8410698e09
commit b7e8b45f64

View File

@@ -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