mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-30 09:28:19 -05:00
feat: add quality filtering to exclude ERROR status library agents
Filter out library agents with ERROR status when searching for sub-agent composition candidates. This prevents recommending broken or draft agents that have failed executions.
This commit is contained in:
@@ -6,6 +6,7 @@ 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,
|
||||
@@ -183,34 +184,52 @@ 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
|
||||
"""
|
||||
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=max_results,
|
||||
page_size=fetch_size,
|
||||
)
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user