Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: add pagination to groups endpoint (#2900)
cthomas4d716a6fb282
diff --git a/letta/server/rest_api/routers/v1/groups.py b/letta/server/rest_api/routers/v1/groups.pyindex 0093a518b..00aeb355a 100644--- a/letta/server/rest_api/routers/v1/groups.py+++ b/letta/server/rest_api/routers/v1/groups.py@@ -1,4 +1,4 @@-from typing import Annotated, List, Optional+from typing import Annotated, List, Literal, Optionalfrom fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, statusfrom fastapi.responses import JSONResponse@@ -21,9 +21,17 @@ async def list_groups(server: "SyncServer" = Depends(get_letta_server),actor_id: Optional[str] = Header(None, alias="user_id"),manager_type: Optional[ManagerType] = Query(None, description="Search groups by manager type"),- before: Optional[str] = Query(None, description="Cursor for pagination"),- after: Optional[str] = Query(None, description="Cursor for pagination"),- limit: Optional[int] = Query(None, description="Limit for pagination"),+ before: Optional[str] = Query(+ None, description="Group ID cursor for pagination. Returns groups that come before this group ID in the specified sort order"+ ),+ after: Optional[str] = Query(+ None, description="Group ID cursor for pagination. Returns groups that come after this group ID in the specified sort order"+ ),+ limit: Optional[int] = Query(50, description="Maximum number of groups to return"),+ order: Literal["asc", "desc"] = Query(+ "asc", description="Sort order for groups by creation time. 'asc' for oldest first, 'desc' for newest first"+ ),+ order_by: Literal["created_at"] = Query("created_at", description="Field to sort by"),project_id: Optional[str] = Query(None, description="Search groups by project id"),show_hidden_groups: bool | None = Query(False,@@ -42,6 +50,7 @@ async def list_groups(before=before,after=after,limit=limit,+ ascending=(order == "asc"),show_hidden_groups=show_hidden_groups,)diff --git a/letta/services/group_manager.py b/letta/services/group_manager.pyindex 1427e7c7f..609a2a894 100644--- a/letta/services/group_manager.py+++ b/letta/services/group_manager.py@@ -29,6 +29,7 @@ class GroupManager:before: Optional[str] = None,after: Optional[str] = None,limit: Optional[int] = 50,+ ascending: bool = True,show_hidden_groups: Optional[bool] = None,) -> list[PydanticGroup]:async with db_registry.async_session() as session:@@ -50,7 +51,7 @@ class GroupManager:query = query.where((GroupModel.hidden.is_(None)) | (GroupModel.hidden == False))# Apply pagination- query = await _apply_group_pagination_async(query, before, after, session, ascending=True)+ query = await _apply_group_pagination_async(query, before, after, session, ascending=ascending)if limit:query = query.limit(limit)