Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: remove groups selectin from agents model (#3429)
cthomas9c1ec9782c2a
diff --git a/letta/orm/agent.py b/letta/orm/agent.pyindex 4504bbc06..44e8a6f06 100644--- a/letta/orm/agent.py+++ b/letta/orm/agent.py@@ -128,7 +128,7 @@ class Agent(SqlalchemyBase, OrganizationMixin, AsyncAttrs):groups: Mapped[List["Group"]] = relationship("Group",secondary="groups_agents",- lazy="selectin",+ lazy="raise",back_populates="agents",passive_deletes=True,)diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.pyindex a9c7e0086..ff7abfba6 100644--- a/letta/services/agent_manager.py+++ b/letta/services/agent_manager.py@@ -28,7 +28,7 @@ from letta.orm import AgentPassage, AgentsTagsfrom letta.orm import Block as BlockModelfrom letta.orm import BlocksAgentsfrom letta.orm import Group as GroupModel-from letta.orm import IdentitiesAgents+from letta.orm import GroupsAgents, IdentitiesAgentsfrom letta.orm import Source as SourceModelfrom letta.orm import SourcePassage, SourcesAgentsfrom letta.orm import Tool as ToolModel@@ -1423,10 +1423,17 @@ class AgentManager:@trace_methoddef list_groups(self, agent_id: str, actor: PydanticUser, manager_type: Optional[str] = None) -> List[PydanticGroup]:with db_registry.session() as session:- agent = AgentModel.read(db_session=session, identifier=agent_id, actor=actor)+ query = (+ select(GroupModel)+ .join(GroupsAgents, GroupModel.id == GroupsAgents.group_id)+ .where(GroupsAgents.agent_id == agent_id, GroupModel.organization_id == actor.organization_id)+ )+if manager_type:- return [group.to_pydantic() for group in agent.groups if group.manager_type == manager_type]- return [group.to_pydantic() for group in agent.groups]+ query = query.where(GroupModel.manager_type == manager_type)++ result = session.execute(query)+ return [group.to_pydantic() for group in result.scalars()]# ======================================================================================================================# In Context Messages Management