Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(backend): Whitelist Onboarding Agents (#11149)

Krzysztof Czerwinski9c8652b2731a
diff --git a/autogpt_platform/backend/backend/data/onboarding.py b/autogpt_platform/backend/backend/data/onboarding.py
index 2b9389fbde..2c7c8a5fdd 100644
--- a/autogpt_platform/backend/backend/data/onboarding.py
+++ b/autogpt_platform/backend/backend/data/onboarding.py
@@ -11,7 +11,6 @@ from prisma.types import UserOnboardingCreateInput, UserOnboardingUpdateInput
from backend.data.block import get_blocks
from backend.data.credit import get_user_credit_model
-from backend.data.graph import GraphModel
from backend.data.model import CredentialsMetaInput
from backend.server.v2.store.model import StoreAgentDetails
from backend.util.json import SafeJson
@@ -278,8 +277,14 @@ async def get_recommended_agents(user_id: str) -> list[StoreAgentDetails]:
for word in user_onboarding.integrations
]
+ where_clause["is_available"] = True
+
+ # Try to take only agents that are available and allowed for onboarding
storeAgents = await prisma.models.StoreAgent.prisma().find_many(
- where=prisma.types.StoreAgentWhereInput(**where_clause),
+ where={
+ "is_available": True,
+ "useForOnboarding": True,
+ },
order=[
{"featured": "desc"},
{"runs": "desc"},
@@ -288,59 +293,16 @@ async def get_recommended_agents(user_id: str) -> list[StoreAgentDetails]:
take=100,
)
- agentListings = await prisma.models.StoreListingVersion.prisma().find_many(
- where={
- "id": {"in": [agent.storeListingVersionId for agent in storeAgents]},
- },
- include={"AgentGraph": True},
- )
-
- for listing in agentListings:
- agent = listing.AgentGraph
- if agent is None:
- continue
- graph = GraphModel.from_db(agent)
- # Remove agents with empty input schema
- if not graph.input_schema:
- storeAgents = [
- a for a in storeAgents if a.storeListingVersionId != listing.id
- ]
- continue
-
- # Remove agents with empty credentials
- # Get nodes from this agent that have credentials
- nodes = await prisma.models.AgentNode.prisma().find_many(
- where={
- "agentGraphId": agent.id,
- "agentBlockId": {"in": list(CREDENTIALS_FIELDS.keys())},
- },
- )
- for node in nodes:
- block_id = node.agentBlockId
- field_name = CREDENTIALS_FIELDS[block_id]
- # If there are no credentials or they are empty, remove the agent
- # FIXME ignores default values
- if (
- field_name not in node.constantInput
- or node.constantInput[field_name] is None
- ):
- storeAgents = [
- a for a in storeAgents if a.storeListingVersionId != listing.id
- ]
- break
-
- # If there are less than 2 agents, add more agents to the list
+ # If not enough agents found, relax the useForOnboarding filter
if len(storeAgents) < 2:
- storeAgents += await prisma.models.StoreAgent.prisma().find_many(
- where={
- "listing_id": {"not_in": [agent.listing_id for agent in storeAgents]},
- },
+ storeAgents = await prisma.models.StoreAgent.prisma().find_many(
+ where=prisma.types.StoreAgentWhereInput(**where_clause),
order=[
{"featured": "desc"},
{"runs": "desc"},
{"rating": "desc"},
],
- take=2 - len(storeAgents),
+ take=100,
)
# Calculate points for the first X agents and choose the top 2
diff --git a/autogpt_platform/backend/backend/server/v2/store/db_test.py b/autogpt_platform/backend/backend/server/v2/store/db_test.py
index 9301ba0989..8390c58754 100644
--- a/autogpt_platform/backend/backend/server/v2/store/db_test.py
+++ b/autogpt_platform/backend/backend/server/v2/store/db_test.py
@@ -42,6 +42,7 @@ async def test_get_store_agents(mocker):
versions=["1.0"],
updated_at=datetime.now(),
is_available=False,
+ useForOnboarding=False,
)
]
@@ -84,6 +85,7 @@ async def test_get_store_agent_details(mocker):
versions=["1.0"],
updated_at=datetime.now(),
is_available=False,
+ useForOnboarding=False,
)
# Mock active version agent (what we want to return for active version)
@@ -105,6 +107,7 @@ async def test_get_store_agent_details(mocker):
versions=["1.0", "2.0"],
updated_at=datetime.now(),
is_available=True,
+ useForOnboarding=False,
)
# Create a mock StoreListing result
@@ -248,6 +251,7 @@ async def test_create_store_submission(mocker):
isAvailable=True,
)
],
+ useForOnboarding=False,
)
# Mock prisma calls
diff --git a/autogpt_platform/backend/migrations/20251013071709_add_use_for_onboarding/migration.sql b/autogpt_platform/backend/migrations/20251013071709_add_use_for_onboarding/migration.sql
new file mode 100644
index 0000000000..e93df597f5
--- /dev/null
+++ b/autogpt_platform/backend/migrations/20251013071709_add_use_for_onboarding/migration.sql
@@ -0,0 +1,65 @@
+BEGIN;
+-- AlterTable
+ALTER TABLE "StoreListing" ADD COLUMN "useForOnboarding" BOOLEAN NOT NULL DEFAULT false;
+
+-- Drop and recreate the StoreAgent view with useForOnboarding field
+DROP VIEW IF EXISTS "StoreAgent";
+
+CREATE OR REPLACE VIEW "StoreAgent" AS
+WITH latest_versions AS (
+ SELECT
+ "storeListingId",
+ MAX(version) AS max_version
+ FROM "StoreListingVersion"
+ WHERE "submissionStatus" = 'APPROVED'
+ GROUP BY "storeListingId"
+),
+agent_versions AS (
+ SELECT
+ "storeListingId",
+ array_agg(DISTINCT version::text ORDER BY version::text) AS versions
+ FROM "StoreListingVersion"
+ WHERE "submissionStatus" = 'APPROVED'
+ GROUP BY "storeListingId"
+)
+SELECT
+ sl.id AS listing_id,
+ slv.id AS "storeListingVersionId",
+ slv."createdAt" AS updated_at,
+ sl.slug,
+ COALESCE(slv.name, '') AS agent_name,
+ slv."videoUrl" AS agent_video,
+ COALESCE(slv."imageUrls", ARRAY[]::text[]) AS agent_image,
+ slv."isFeatured" AS featured,
+ p.username AS creator_username, -- Allow NULL for malformed sub-agents
+ p."avatarUrl" AS creator_avatar, -- Allow NULL for malformed sub-agents
+ slv."subHeading" AS sub_heading,
+ slv.description,
+ slv.categories,
+ COALESCE(ar.run_count, 0::bigint) AS runs,
+ COALESCE(rs.avg_rating, 0.0)::double precision AS rating,
+ COALESCE(av.versions, ARRAY[slv.version::text]) AS versions,
+ slv."isAvailable" AS is_available,
+ COALESCE(sl."useForOnboarding", false) AS "useForOnboarding"
+FROM "StoreListing" sl
+JOIN latest_versions lv
+ ON sl.id = lv."storeListingId"
+JOIN "StoreListingVersion" slv
+ ON slv."storeListingId" = lv."storeListingId"
+ AND slv.version = lv.max_version
+ AND slv."submissionStatus" = 'APPROVED'
+JOIN "AgentGraph" a
+ ON slv."agentGraphId" = a.id
+ AND slv."agentGraphVersion" = a.version
+LEFT JOIN "Profile" p
+ ON sl."owningUserId" = p."userId"
+LEFT JOIN "mv_review_stats" rs
+ ON sl.id = rs."storeListingId"
+LEFT JOIN "mv_agent_run_counts" ar
+ ON a.id = ar."agentGraphId"
+LEFT JOIN agent_versions av
+ ON sl.id = av."storeListingId"
+WHERE sl."isDeleted" = false
+ AND sl."hasApprovedVersion" = true;
+
+COMMIT;
\ No newline at end of file
diff --git a/autogpt_platform/backend/schema.prisma b/autogpt_platform/backend/schema.prisma
index 4d1b84ba65..7556c45918 100644
--- a/autogpt_platform/backend/schema.prisma
+++ b/autogpt_platform/backend/schema.prisma
@@ -667,6 +667,7 @@ view StoreAgent {
rating Float
versions String[]
is_available Boolean @default(true)
+ useForOnboarding Boolean @default(false)
// Materialized views used (refreshed every 15 minutes via pg_cron):
// - mv_agent_run_counts - Pre-aggregated agent execution counts by agentGraphId
@@ -744,6 +745,9 @@ model StoreListing {
// URL-friendly identifier for this agent (moved from StoreListingVersion)
slug String
+ // Allow this agent to be used during onboarding
+ useForOnboarding Boolean @default(false)
+
// The currently active version that should be shown to users
activeVersionId String? @unique
ActiveVersion StoreListingVersion? @relation("ActiveVersion", fields: [activeVersionId], references: [id])