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.

chore: identities follow up (#1118)

Shubham Naik51791bc5766e
diff --git a/letta/orm/sqlalchemy_base.py b/letta/orm/sqlalchemy_base.py
index 0bca5dd3f..5652e7a48 100644
--- a/letta/orm/sqlalchemy_base.py
+++ b/letta/orm/sqlalchemy_base.py
@@ -69,6 +69,7 @@ class SqlalchemyBase(CommonSqlalchemyMetaMixins, Base):
join_model: Optional[Base] = None,
join_conditions: Optional[Union[Tuple, List]] = None,
identifier_keys: Optional[List[str]] = None,
+ identifier_id: Optional[str] = None,
**kwargs,
) -> List["SqlalchemyBase"]:
"""
@@ -147,6 +148,10 @@ class SqlalchemyBase(CommonSqlalchemyMetaMixins, Base):
if identifier_keys and hasattr(cls, "identities"):
query = query.join(cls.identities).filter(cls.identities.property.mapper.class_.identifier_key.in_(identifier_keys))
+ # given the identifier_id, we can find within the agents table any agents that have the identifier_id in their identity_ids
+ if identifier_id and hasattr(cls, "identities"):
+ query = query.join(cls.identities).filter(cls.identities.property.mapper.class_.id == identifier_id)
+
# Apply filtering logic from kwargs
for key, value in kwargs.items():
if "." in key:
diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py
index dd75d1cc3..4313c0c9b 100644
--- a/letta/server/rest_api/routers/v1/agents.py
+++ b/letta/server/rest_api/routers/v1/agents.py
@@ -69,7 +69,6 @@ def list_agents(
"project_id": project_id,
"template_id": template_id,
"base_template_id": base_template_id,
- "identifier_id": identifier_id,
}.items()
if value is not None
}
@@ -84,6 +83,7 @@ def list_agents(
tags=tags,
match_all_tags=match_all_tags,
identifier_keys=identifier_keys,
+ identifier_id=identifier_id,
**kwargs,
)
return agents
diff --git a/letta/services/identity_manager.py b/letta/services/identity_manager.py
index 8dcb83ad6..45e77d26f 100644
--- a/letta/services/identity_manager.py
+++ b/letta/services/identity_manager.py
@@ -115,8 +115,8 @@ class IdentityManager:
if replace:
existing_identity.properties = [prop.model_dump() for prop in identity.properties]
else:
- new_properties = existing_identity.properties + identity.properties
- existing_identity.properties = [prop.model_dump() for prop in new_properties]
+ new_properties = existing_identity.properties + [prop.model_dump() for prop in identity.properties]
+ existing_identity.properties = new_properties
self._process_agent_relationship(
session=session, identity=existing_identity, agent_ids=identity.agent_ids, allow_partial=False, replace=replace