Skip to content

Commit

Permalink
feat: Adjust get_composio_key (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattzh72 authored Jan 30, 2025
1 parent f0f1c41 commit 27deb57
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions letta/server/rest_api/routers/v1/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
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(
Expand Down Expand Up @@ -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

0 comments on commit 27deb57

Please sign in to comment.