From aef705007bca7c0e7c243ce5e48962eda9c80b91 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Fri, 30 Jan 2026 07:45:00 -0600 Subject: [PATCH] refactor: remove aggressive ERROR status filter from library agent search The ERROR status filter was too aggressive - a single failed execution would exclude an agent from sub-agent composition, even if it had many successful runs. Removed the filter for now. Future enhancement: Add quality filtering based on execution success rate or correctness_score (stored in AgentGraphExecution stats) rather than the binary ERROR status. --- .../chat/tools/agent_generator/core.py | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py b/autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py index 514f3af25e..093de80390 100644 --- a/autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py +++ b/autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py @@ -6,7 +6,6 @@ import uuid from typing import Any, TypedDict from backend.api.features.library import db as library_db -from backend.api.features.library import model as library_model from backend.api.features.store import db as store_db from backend.data.graph import ( Graph, @@ -184,52 +183,41 @@ async def get_library_agents_for_generation( search_query: str | None = None, exclude_graph_id: str | None = None, max_results: int = 15, - exclude_error_status: bool = True, ) -> list[LibraryAgentSummary]: """Fetch user's library agents formatted for Agent Generator. Uses search-based fetching to return relevant agents instead of all agents. This is more scalable for users with large libraries. - Quality filtering: By default, excludes agents with ERROR status to avoid - recommending broken or draft agents for sub-agent composition. - Args: user_id: The user ID search_query: Optional search term to find relevant agents (user's goal/description) exclude_graph_id: Optional graph ID to exclude (prevents circular references) max_results: Maximum number of agents to return (default 15) - exclude_error_status: Filter out agents with ERROR status (default True) Returns: List of LibraryAgentSummary with schemas for sub-agent composition + + Note: + Future enhancement: Add quality filtering based on execution success rate + or correctness_score from AgentGraphExecution stats. The current + LibraryAgentStatus.ERROR is too aggressive (1 failed run = ERROR). + Better approach: filter by success rate (e.g., >50% successful runs) + or require at least 1 successful execution. """ try: - # Fetch more than needed to account for filtered out agents - fetch_size = max_results * 2 if exclude_error_status else max_results response = await library_db.list_library_agents( user_id=user_id, search_term=search_query, page=1, - page_size=fetch_size, + page_size=max_results, ) results: list[LibraryAgentSummary] = [] for agent in response.agents: - if len(results) >= max_results: - break - if exclude_graph_id is not None and agent.graph_id == exclude_graph_id: continue - # Quality filter: skip agents in ERROR state (broken/draft agents) - if ( - exclude_error_status - and agent.status == library_model.LibraryAgentStatus.ERROR - ): - logger.debug(f"Skipping agent '{agent.name}' due to ERROR status") - continue - results.append( LibraryAgentSummary( graph_id=agent.graph_id,