Skip to content

feat(platform/library): Sort agents by "Last Executed" #10353

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

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

Pwuts
Copy link
Member

@Pwuts Pwuts commented Jul 11, 2025

I'm re-creating #9871 because it isn't mergeable in its current state and I can't push changes to the author's fork.

Thanks @Keerthi421 for the initial implementation! :)

Changes 🏗️

  • Add "Last Executed" sort option in Library
  • Set lastExecuted as the default sort option in frontend and backend
  • Improve LibrarySortMenu + useLibrarySortMenu implementations

TODO:

  • Make the sort mechanism actually work. Prisma doesn't support sorting by fields of related entities.

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • Go to /library
    • Default sort is "Last Executed"
    • "Last Executed" sort works
    • Other sort options still work

@Pwuts Pwuts requested a review from a team as a code owner July 11, 2025 13:29
@Pwuts Pwuts requested review from 0ubbe and Swiftyos and removed request for a team July 11, 2025 13:29
@github-project-automation github-project-automation bot moved this to 🆕 Needs initial review in AutoGPT development kanban Jul 11, 2025
Copy link

netlify bot commented Jul 11, 2025

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

Name Link
🔨 Latest commit 5f6cea2
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs-dev/deploys/68712042ada63e000869edc3

Copy link

netlify bot commented Jul 11, 2025

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit 5f6cea2
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs/deploys/68712042dc4fc2000772b199

Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

9860 - PR Code Verified

Compliant requirements:

  • Order agents in library by "most recently ran" instead of last edit time
  • Change default sorting from last edit to last execution time

Requires further human verification:

  • Count all executions, not just those manually triggered through GUI (requires testing to verify execution tracking works for all execution types)
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Complex Sorting

The LAST_EXECUTED sorting implementation uses nested Prisma queries with cast operations that may have performance implications and could be fragile. The dual ordering fallback logic should be validated.

elif sort_by == library_model.LibraryAgentSort.LAST_EXECUTED:
    # Sort by the most recent AgentGraph.Execution (startedAt) first.
    # If no executions exist, fall back to sorting by updatedAt.
    order_by = [
        cast(
            prisma.types.LibraryAgentOrderByInput,
            {"AgentGraph": {"Executions": {"startedAt": "desc"}}},
        ),
        {"updatedAt": "desc"},
    ]
Missing State

The Select component uses defaultValue but doesn't maintain controlled state, which could lead to UI inconsistencies when the sort changes programmatically.

<Select
  onValueChange={(value) => setLibrarySort(value as LibraryAgentSort)}
  defaultValue={defaultSort}
>

Copy link

deepsource-io bot commented Jul 11, 2025

Here's the code health analysis summary for commits 4ffb99b..5f6cea2. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScript✅ Success
❗ 1 occurence introduced
🎯 1 occurence resolved
View Check ↗
DeepSource Python LogoPython✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@AutoGPT-Agent
Copy link

Thanks for contributing this PR to implement the "Last Executed" sort option for agents in the Library!

Your PR looks good overall - the implementation includes both frontend and backend changes needed to support this new sorting option, and the scope matches what's described in the title.

However, I noticed that while you've outlined a test plan, you haven't checked off the item indicating you've completed testing according to that plan. Could you please:

  1. Complete the testing according to your outlined steps
  2. Check off the relevant checklist item once testing is complete

Specifically, please verify that:

  • Default sort is "Last Executed"
  • "Last Executed" sort works correctly
  • Other sort options still work as expected

Once you've completed testing and updated the checklist, this PR should be ready for review and merging. Thanks for your contribution!

@AutoGPT-Agent
Copy link

Thank you for your contribution! This is a useful addition to the library sorting functionality.

The implementation looks good overall, with proper handling of the new sort option in both frontend and backend. I particularly like the dual ordering approach for LAST_EXECUTED that falls back to updatedAt when no executions exist.

However, before we can merge this PR, could you please:

  1. Complete the checklist by confirming you've tested the changes according to your test plan (check the box for "I have tested my changes according to the test plan")

  2. Verify that:

    • Default sort is "Last Executed"
    • "Last Executed" sort works correctly
    • Other sort options still function as expected

Once you've completed the checklist indicating you've verified the functionality, this PR should be ready for final review and merging.

@AutoGPT-Agent
Copy link

Thanks for this contribution to improve the agent sorting functionality! The PR looks good overall, but there's one issue before we can merge:

Testing Completion

You've outlined a clear test plan, but it appears you haven't completed the testing yet - the checkboxes in your test plan are still unchecked. Please complete testing according to your plan and mark the checkboxes once verified.

Specifically, please test:

  • Default sort is "Last Executed"
  • "Last Executed" sort works properly
  • Other sort options still work correctly

Once you've confirmed these items work as expected, please update the PR by checking those boxes.

Implementation Notes

The implementation looks solid:

  • Backend changes properly handle the new sort option with appropriate fallback to updatedAt when no executions exist
  • Frontend changes are consistent with the backend implementation
  • Default sort option is correctly set in both frontend and backend

Just complete the testing and we should be good to go!

@Pwuts
Copy link
Member Author

Pwuts commented Jul 11, 2025

This doesn't actually work, because Prisma doesn't support this kind of sorting by attributes of related entities:

order_by = [
    {"AgentGraph": {"Executions": {"startedAt": "desc"}}},  # this is not supported
    {"updatedAt": "desc"},
]
Database error fetching library agents: Could not find field at `findManyLibraryAgent.orderBy.AgentGraph.Executions.startedAt`

@AutoGPT-Agent
Copy link

Thanks for working on this feature! Adding "Last Executed" sorting to the Library is a valuable improvement. I noticed a few items that need to be addressed before this can be merged:

  1. Incomplete Implementation: You've noted in your TODO that the sort mechanism doesn't actually work yet because "Prisma doesn't support sorting by fields of related entities." This feature needs to be fully implemented before merging.

  2. Uncompleted Testing: The testing section of your checklist remains unchecked, which means you haven't verified the functionality of your changes according to your test plan.

  3. Implementation Questions: I notice you're trying to sort by AgentGraph.Executions.startedAt in the backend. Have you considered alternatives if Prisma doesn't directly support this? Perhaps:

    • Using a raw SQL query for this specific sort option
    • Adding a denormalized lastExecutedAt field to the LibraryAgent model
    • Implementing a post-query sort in the API layer

To move forward:

  1. Complete the implementation so the sort functionality works correctly
  2. Test the changes according to your test plan
  3. Update the PR to indicate the implementation is complete and the tests have passed

Looking forward to seeing this feature completed!

@AutoGPT-Agent
Copy link

Thanks for your well-structured PR implementing the "Last Executed" sort option for agents in the library! A few notes:

  1. You've clearly identified the implementation issue with a TODO item - Prisma not supporting sorting by fields of related entities. This needs to be resolved before merging.

  2. I noticed you haven't checked off the testing part of your checklist, which aligns with your TODO note. Once you resolve the Prisma sorting issue, please test according to your plan and update the checklist.

  3. The implementation looks good overall - you've added the new sort option consistently throughout the codebase (backend models, API definitions, frontend components).

  4. Nice improvement with the getSortLabel implementation using an object lookup instead of a switch statement.

  5. Good thinking on the fallback sort mechanism in the backend (falling back to updatedAt when no executions exist).

Please update the PR once you've solved the Prisma sorting limitation. You might need to consider alternative approaches like:

  • Using a raw SQL query
  • Adding a denormalized lastExecutedAt field to the LibraryAgent model
  • Implementing the sorting in-memory if the result set is small enough

Looking forward to the completed implementation!

@Pwuts Pwuts force-pushed the pwuts/open-2472-order-agents-in-library-by-most-recently-ran branch from e99825a to 5f6cea2 Compare July 11, 2025 14:31
@Pwuts Pwuts marked this pull request as draft July 11, 2025 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform/backend AutoGPT Platform - Back end platform/frontend AutoGPT Platform - Front end Review effort 3/5 size/m
Projects
Status: 🆕 Needs initial review
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants