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: tag matching (#585)

mlong930e7fe5dfe56f
diff --git a/letta/orm/sqlalchemy_base.py b/letta/orm/sqlalchemy_base.py
index 9ab1e4d38..dc3822760 100644
--- a/letta/orm/sqlalchemy_base.py
+++ b/letta/orm/sqlalchemy_base.py
@@ -100,9 +100,13 @@ class SqlalchemyBase(CommonSqlalchemyMetaMixins, Base):
if match_all_tags:
# Match ALL tags - use subqueries
- for tag in tags:
- subquery = select(cls.tags.property.mapper.class_.agent_id).where(cls.tags.property.mapper.class_.tag == tag)
- query = query.filter(cls.id.in_(subquery))
+ subquery = (
+ select(cls.tags.property.mapper.class_.agent_id)
+ .where(cls.tags.property.mapper.class_.tag.in_(tags))
+ .group_by(cls.tags.property.mapper.class_.agent_id)
+ .having(func.count() == len(tags))
+ )
+ query = query.filter(cls.id.in_(subquery))
else:
# Match ANY tag - use join and filter
query = (