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.

feat: add back async list_groups in agent manager [LET-4597] (#5095)

cthomas1b4780fa27b6
diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py
index fe6ec3259..72510370a 100644
--- a/letta/server/rest_api/routers/v1/agents.py
+++ b/letta/server/rest_api/routers/v1/agents.py
@@ -1780,7 +1780,7 @@ async def list_agent_groups(
"""Lists the groups for an agent"""
actor = await server.user_manager.get_actor_or_default_async(actor_id=headers.actor_id)
logger.info("in list agents with manager_type", manager_type)
- return server.agent_manager.list_groups(agent_id=agent_id, manager_type=manager_type, actor=actor)
+ return await server.agent_manager.list_groups_async(agent_id=agent_id, manager_type=manager_type, actor=actor)
@router.post(
diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.py
index 1d275ef42..8a54ed0d9 100644
--- a/letta/services/agent_manager.py
+++ b/letta/services/agent_manager.py
@@ -2634,6 +2634,42 @@ class AgentManager:
tools = result.scalars().all()
return [tool.to_pydantic() for tool in tools]
+ @enforce_types
+ @trace_method
+ async def list_groups_async(
+ self,
+ agent_id: str,
+ actor: PydanticUser,
+ manager_type: Optional[str] = None,
+ ) -> List[PydanticGroup]:
+ """
+ List all groups that contain the specified agent (async version).
+
+ Args:
+ agent_id: ID of the agent to find groups for.
+ actor: User performing the action.
+ manager_type: Optional manager type to filter by.
+
+ Returns:
+ List[PydanticGroup]: List of groups containing the agent.
+ """
+ async with db_registry.async_session() as session:
+ from letta.orm.group import Group as GroupModel
+ from letta.orm.sqlalchemy_base import GroupsAgents
+
+ 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:
+ query = query.where(GroupModel.manager_type == manager_type)
+
+ result = await session.execute(query)
+ groups = result.scalars().all()
+ return [group.to_pydantic() for group in groups]
+
# ======================================================================================================================
# File Management
# ======================================================================================================================