Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): Add Support for Managing Agent Presets with Pagination and Soft Delete #9211

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

Swiftyos
Copy link
Contributor

@Swiftyos Swiftyos commented Jan 7, 2025

Summary

  • New Models: Added LibraryAgentPreset, LibraryAgentPresetResponse, Pagination, and CreateLibraryAgentPresetRequest.
  • Database Changes:
    • Added isDeleted column in AgentPreset for soft delete.
    • CRUD operations for AgentPreset:
      • get_presets with pagination.
      • get_preset by ID.
      • create_or_update_preset for upsert.
      • delete_preset to soft delete.
  • API Routes:
    • GET /presets: Fetch paginated presets.
    • GET /presets/{preset_id}: Fetch a single preset.
    • POST /presets: Create a preset.
    • PUT /presets/{preset_id}: Update a preset.
    • DELETE /presets/{preset_id}: Soft delete a preset.
  • Tests:
    • Coverage for models, CRUD operations, and pagination.
  • Migration:
    • Added isDeleted field to support soft delete.

Review Notes

  • Validate migration scripts and test coverage.
  • Ensure API aligns with project standards.

@Swiftyos Swiftyos requested a review from a team as a code owner January 7, 2025 10:01
@Swiftyos Swiftyos requested review from Pwuts and majdyz and removed request for a team January 7, 2025 10:01
@github-actions github-actions bot added platform/backend AutoGPT Platform - Back end size/l labels Jan 7, 2025
Copy link

netlify bot commented Jan 7, 2025

Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
🔨 Latest commit 1f82ceb
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs-dev/deploys/6780e3ce61c6ee0008f05d2d

Copy link

qodo-merge-pro bot commented Jan 7, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Filter

The get_presets function does not filter out soft deleted presets. The where clause should include isDeleted: false to prevent returning deleted presets.

    where={"userId": user_id},
    skip=page * page_size,
    take=page_size,
)
Data Validation

The create_or_update_preset function does not validate if the agent_id and agent_version exist before creating/updating a preset. This could lead to orphaned presets.

new_preset = await prisma.models.AgentPreset.prisma().upsert(
    where={
        "id": preset_id if preset_id else "",
    },
    data={
        "create": prisma.types.AgentPresetCreateInput(
            userId=user_id,
            name=preset.name,
            description=preset.description,
            agentId=preset.agent_id,
            agentVersion=preset.agent_version,
            Agent=prisma.types.AgentGraphUpdateOneWithoutRelationsInput(
                connect=prisma.types.AgentGraphWhereUniqueInput(
                    id=preset.agent_id,
                    version=preset.agent_version,
                ),
            ),
            isActive=preset.is_active,
            InputPresets={
                "create": [
                    {"name": name, "data": json.dumps(data)}
                    for name, data in preset.inputs.items()
                ]
            },
        ),
        "update": prisma.types.AgentPresetUpdateInput(
            name=preset.name,
            description=preset.description,
            isActive=preset.is_active,
        ),
    },
)
Input Validation

The page and page_size parameters in get_presets endpoint lack validation for negative values or upper bounds, which could cause performance issues.

    page: int = 1,
    page_size: int = 10,
) -> backend.server.v2.library.model.LibraryAgentPresetResponse:

Copy link

netlify bot commented Jan 7, 2025

Deploy Preview for auto-gpt-docs ready!

Name Link
🔨 Latest commit 1f82ceb
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/6780e3cedb53870008c1d9c5
😎 Deploy Preview https://deploy-preview-9211--auto-gpt-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Pwuts Pwuts changed the title feat(platform): Add Support for Managing Agent Presets with Pagination and Soft Delete feat(backend): Add Support for Managing Agent Presets with Pagination and Soft Delete Jan 7, 2025
@Swiftyos Swiftyos requested a review from Pwuts January 7, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants