Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: add lazy id generation for providers (#543)
cthomas188313c3bf5e
diff --git a/letta/providers.py b/letta/providers.pyindex deacb0a33..ccec0efc6 100644--- a/letta/providers.py+++ b/letta/providers.py@@ -16,10 +16,15 @@ class ProviderBase(LettaBase):class Provider(ProviderBase):+ id: Optional[str] = Field(None, description="The id of the provider, lazily created by the database manager.")name: str = Field(..., description="The name of the provider")api_key: Optional[str] = Field(None, description="API key used for requests to the provider.")organization_id: Optional[str] = Field(OrganizationManager.DEFAULT_ORG_ID, description="The organization id of the user")+ def resolve_identifier(self):+ if not self.id:+ self.id = ProviderBase._generate_id(prefix=ProviderBase.__id_prefix__)+def list_llm_models(self) -> List[LLMConfig]:return []@@ -40,7 +45,7 @@ class Provider(ProviderBase):class ProviderCreate(ProviderBase):name: str = Field(..., description="The name of the provider.")api_key: str = Field(..., description="API key used for requests to the provider.")- organization_id: str = Field(..., description="The organization id that this provider information pertains to.")+ organization_id: Optional[str] = Field(OrganizationManager.DEFAULT_ORG_ID, description="The organization id of the user")class ProviderUpdate(ProviderBase):diff --git a/letta/services/provider_manager.py b/letta/services/provider_manager.pyindex 8fe9797bf..e19ff3a95 100644--- a/letta/services/provider_manager.py+++ b/letta/services/provider_manager.py@@ -17,6 +17,8 @@ class ProviderManager:def create_provider(self, provider: PydanticProvider) -> PydanticProvider:"""Create a new provider if it doesn't already exist."""with self.session_maker() as session:+ # Lazily create the provider id prior to persistence+ provider.resolve_identifier()new_provider = ProviderModel(**provider.model_dump())new_provider.create(session)return new_provider.to_pydantic()