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

Merged
merged 25 commits into from
Jan 10, 2025

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.

…without-agent-ownership' of github.com:Significant-Gravitas/AutoGPT into swiftyos/open-2276-add-ability-to-execute-store-agents-without-agent-ownership
@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 d0c4a1f
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs-dev/deploys/678109dbb3110f00080681d0

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 canceled.

Name Link
🔨 Latest commit d0c4a1f
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/678109dbd41d850008baafa5

@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
Pwuts
Pwuts previously approved these changes Jan 9, 2025
@github-actions github-actions bot added size/xl and removed size/l labels Jan 10, 2025
@Swiftyos Swiftyos changed the base branch from dev to swiftyos/open-2276-add-ability-to-execute-store-agents-without-agent-ownership January 10, 2025 11:25
@Swiftyos Swiftyos changed the base branch from swiftyos/open-2276-add-ability-to-execute-store-agents-without-agent-ownership to dev January 10, 2025 11:27
@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Jan 10, 2025
Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label Jan 10, 2025
Copy link
Contributor

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

@Swiftyos Swiftyos merged commit 4b17cc9 into dev Jan 10, 2025
20 checks passed
@Swiftyos Swiftyos deleted the swiftyos/open-2278-implement-agent-preset-functionality branch January 10, 2025 11:57
Swiftyos added a commit that referenced this pull request Jan 10, 2025
…ctionality (#9218)

### Changes 🏗️

1. **Core Features**:
   - Add agents to the user's library.
   - Update library agents (auto-update, favorite, archive, delete).
   - Paginate library agents and presets.
   - Execute graphs using presets.

2. **Refactoring**:
   - Replaced `UserAgent` with `LibraryAgent`.
   - Separated routes for agents and presets.

3. **Schema Changes**:
- Added `LibraryAgent` table with fields like `isArchived`, `isDeleted`,
etc.
   - Soft delete functionality for `AgentPreset`.

4. **Testing**:
   - Updated tests for `LibraryAgent` operations.
   - Added edge case tests for deletion, archiving, and pagination.

5. **Database Migrations**:
   - Migration to drop `UserAgent` and add `LibraryAgent`.
   - Added fields for soft deletion and auto-update.


Note this includes the changes from the following PR's to avoid merge
conflicts with them:

#9179 
#9211

---------

Co-authored-by: Reinier van der Leer <[email protected]>
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