Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/backend/backend/server/v2/store/db.py (Python)

Code before:
        )

        total = await prisma.models.LibraryAgent.prisma().count(where=search_filter)
        total_pages = (total + page_size - 1) // page_size

        my_agents = [
            backend.server.v2.store.model.MyAgent(
                agent_id=agent.id,
                agent_version=agent.version,
                agent_name=agent.name or "",
                last_edited=agent.updatedAt or agent.createdAt,
                description=agent.description or "",
                agent_image=entry.imageUrl,
            )
            for entry in library_agents
            if (agent := entry.Agent)
        ]

        return backend.server.v2.store.model.MyAgentsResponse(
            agents=my_agents,
            pagination=backend.server.v2.store.model.Pagination(
                current_page=page,
                total_items=total,
                total_pages=total_pages,
                page_size=page_size,
            ),
        )
    except Exception as e:
        logger.error(f"Error getting my agents: {e}")
        raise backend.server.v2.store.exceptions.DatabaseError(
            "Failed to fetch my agents"
        ) from e


async def get_agent(
    store_listing_version_id: str, version_id: Optional[int]
) -> GraphModel:
    """Get agent using the version ID and store listing version ID."""
    try:
        store_listing_version = (
            await prisma.models.StoreListingVersion.prisma().find_unique(
                where={"id": store_listing_version_id}, include={"Agent": True}
            )
        )

        if not store_listing_version or not store_listing_version.Agent:
            raise fastapi.HTTPException(
                status_code=404,
                detail=f"Store listing version {store_listing_version_id} not found",
            )


Review comment (refactor):
nit, confusing/ambiguous naming:
```suggestion
            if (graph := entry.Agent)
```
although this should be refactored everywhere so feel free to leave it in this PR

Code after:
            isArchived=False,
            isDeleted=False,
        )

        library_agents = await prisma.models.LibraryAgent.prisma().find_many(
            where=search_filter,
            order=[{"agentVersion": "desc"}],
            skip=(page - 1) * page_size,
            take=page_size,
            include={"Agent": True},
        )

        total = await prisma.models.LibraryAgent.prisma().count(where=search_filter)
        total_pages = (total + page_size - 1) // page_size

        my_agents = [
            backend.server.v2.store.model.MyAgent(
                agent_id=agent.id,
                agent_version=agent.version,
                agent_name=agent.name or "",
                last_edited=agent.updatedAt or agent.createdAt,
                description=agent.description or "",
                agent_image=entry.imageUrl,
            )
            for entry in library_agents
            if (agent := entry.Agent)
        ]

        return backend.server.v2.store.model.MyAgentsResponse(
            agents=my_agents,
            pagination=backend.server.v2.store.model.Pagination(
                current_page=page,
                total_items=total,
                total_pages=total_pages,
                page_size=page_size,
            ),
        )
    except Exception as e:
        logger.error(f"Error getting my agents: {e}")
        raise backend.server.v2.store.exceptions.DatabaseError(
            "Failed to fetch my agents"
        ) from e


async def get_agent(
    store_listing_version_id: str, version_id: Optional[int]
) -> GraphModel:
    """Get agent using the version ID and store listing version ID."""
    try:
        store_listing_version = (
            await prisma.models.StoreListingVersion.prisma().find_unique(