Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: cleanup error trace for no llm/embedding_config on POST (#2218)

Charles Packer223b6bc0a98a
diff --git a/letta/server/rest_api/app.py b/letta/server/rest_api/app.py
index 9b567bf4a..ebbd58601 100644
--- a/letta/server/rest_api/app.py
+++ b/letta/server/rest_api/app.py
@@ -6,7 +6,7 @@ from pathlib import Path
from typing import Optional
import uvicorn
-from fastapi import FastAPI
+from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware.cors import CORSMiddleware
@@ -136,17 +136,18 @@ def create_application() -> "FastAPI":
},
)
+ debug_mode = "--debug" in sys.argv
app = FastAPI(
swagger_ui_parameters={"docExpansion": "none"},
# openapi_tags=TAGS_METADATA,
title="Letta",
summary="Create LLM agents with long-term memory and custom tools 📚🦙",
version="1.0.0", # TODO wire this up to the version in the package
- debug=True,
+ debug=debug_mode, # if True, the stack trace will be printed in the response
)
@app.exception_handler(Exception)
- async def generic_error_handler(request, exc):
+ async def generic_error_handler(request: Request, exc: Exception):
# Log the actual error for debugging
log.error(f"Unhandled error: {exc}", exc_info=True)
@@ -166,12 +167,16 @@ def create_application() -> "FastAPI":
},
)
+ @app.exception_handler(ValueError)
+ async def value_error_handler(request: Request, exc: ValueError):
+ return JSONResponse(status_code=400, content={"detail": str(exc)})
+
@app.exception_handler(LettaAgentNotFoundError)
- async def agent_not_found_handler(request, exc):
+ async def agent_not_found_handler(request: Request, exc: LettaAgentNotFoundError):
return JSONResponse(status_code=404, content={"detail": "Agent not found"})
@app.exception_handler(LettaUserNotFoundError)
- async def user_not_found_handler(request, exc):
+ async def user_not_found_handler(request: Request, exc: LettaUserNotFoundError):
return JSONResponse(status_code=404, content={"detail": "User not found"})
settings.cors_origins.append("https://app.letta.com")
diff --git a/letta/server/server.py b/letta/server/server.py
index 609e8eab4..c60abe484 100644
--- a/letta/server/server.py
+++ b/letta/server/server.py
@@ -826,6 +826,12 @@ class SyncServer(Server):
if not user:
raise ValueError(f"cannot find user with associated client id: {user_id}")
+ if request.llm_config is None:
+ raise ValueError("llm_config is required")
+
+ if request.embedding_config is None:
+ raise ValueError("embedding_config is required")
+
# created and persist the agent state in the DB
agent_state = PersistedAgentState(
name=request.name,