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: check both unique constraints in provider model sync (#9193)

Kian Jonesb0f8e16ac044
diff --git a/letta/services/provider_manager.py b/letta/services/provider_manager.py
index 1556ecef8..52b464954 100644
--- a/letta/services/provider_manager.py
+++ b/letta/services/provider_manager.py
@@ -675,7 +675,7 @@ class ProviderManager:
for llm_config in llm_models:
logger.info(f" Checking LLM model: {llm_config.handle} (name: {llm_config.model})")
- # Check if model already exists (excluding soft-deleted ones)
+ # Check if model already exists by handle (excluding soft-deleted ones)
existing = await ProviderModelORM.list_async(
db_session=session,
limit=1,
@@ -687,6 +687,19 @@ class ProviderManager:
},
)
+ # Also check by name+provider_id (covers unique_model_per_provider_and_type constraint)
+ if not existing:
+ existing = await ProviderModelORM.list_async(
+ db_session=session,
+ limit=1,
+ check_is_deleted=True,
+ **{
+ "name": llm_config.model,
+ "provider_id": provider.id,
+ "model_type": "llm",
+ },
+ )
+
if not existing:
logger.info(f" Creating new LLM model {llm_config.handle}")
# Create new model entry
@@ -754,7 +767,7 @@ class ProviderManager:
for embedding_config in embedding_models:
logger.info(f" Checking embedding model: {embedding_config.handle} (name: {embedding_config.embedding_model})")
- # Check if model already exists (excluding soft-deleted ones)
+ # Check if model already exists by handle (excluding soft-deleted ones)
existing = await ProviderModelORM.list_async(
db_session=session,
limit=1,
@@ -766,6 +779,19 @@ class ProviderManager:
},
)
+ # Also check by name+provider_id (covers unique_model_per_provider_and_type constraint)
+ if not existing:
+ existing = await ProviderModelORM.list_async(
+ db_session=session,
+ limit=1,
+ check_is_deleted=True,
+ **{
+ "name": embedding_config.embedding_model,
+ "provider_id": provider.id,
+ "model_type": "embedding",
+ },
+ )
+
if not existing:
logger.info(f" Creating new embedding model {embedding_config.handle}")
# Create new model entry