From 6170d9f49757f2b20ea4f2783d9faaa2ef4f3132 Mon Sep 17 00:00:00 2001 From: Matthew Zhou Date: Fri, 2 May 2025 13:53:08 -0700 Subject: [PATCH] feat: Make tool execution directory if does not exist (#1992) --- letta/server/rest_api/app.py | 4 ---- letta/server/server.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/letta/server/rest_api/app.py b/letta/server/rest_api/app.py index 273036a7..caaaf3d0 100644 --- a/letta/server/rest_api/app.py +++ b/letta/server/rest_api/app.py @@ -170,10 +170,6 @@ def create_application() -> "FastAPI": t.start() t.join() - @app.on_event("shutdown") - def shutdown_scheduler(): - shutdown_cron_scheduler() - @app.exception_handler(IncompatibleAgentType) async def handle_incompatible_agent_type(request: Request, exc: IncompatibleAgentType): return JSONResponse( diff --git a/letta/server/server.py b/letta/server/server.py index f49653ab..4117adf3 100644 --- a/letta/server/server.py +++ b/letta/server/server.py @@ -244,9 +244,15 @@ class SyncServer(Server): tool_dir = tool_settings.tool_exec_dir or LETTA_TOOL_EXECUTION_DIR venv_dir = Path(tool_dir) / venv_name - if not Path(tool_dir).is_dir(): - logger.error(f"Provided LETTA_TOOL_SANDBOX_DIR is not a valid directory: {tool_dir}") + tool_path = Path(tool_dir) + + if tool_path.exists() and not tool_path.is_dir(): + logger.error(f"LETTA_TOOL_SANDBOX_DIR exists but is not a directory: {tool_dir}") else: + if not tool_path.exists(): + logger.warning(f"LETTA_TOOL_SANDBOX_DIR does not exist, creating now: {tool_dir}") + tool_path.mkdir(parents=True, exist_ok=True) + if tool_settings.tool_exec_venv_name and not venv_dir.is_dir(): logger.warning( f"Provided LETTA_TOOL_SANDBOX_VENV_NAME is not a valid venv ({venv_dir}), one will be created for you during tool execution."