Significant-Gravitas/AutoGPT · error · DatabaseError

Failed to fetch agent

Error message

Failed to fetch agent

What it means

DatabaseError raised by get_available_graph when the StoreListingVersion/AgentGraph query itself fails or GraphModel(WithoutNodes).from_db cannot build the model (e.g. malformed graph JSON in the DB). The NotFoundError case is deliberately wrapped too — unlike sibling functions it has no 'except NotFoundError: raise', so not-found surfaces as this DatabaseError upstream.

Source

Thrown at autogpt_platform/backend/backend/api/features/store/db.py:388

                    "isAvailable": True,
                    "isDeleted": False,
                },
                include={"AgentGraph": {"include": AGENT_GRAPH_INCLUDE}},
            )
        )

        if not store_listing_version or not store_listing_version.AgentGraph:
            raise NotFoundError(
                f"Store listing version {store_listing_version_id} not found",
            )

        return (GraphModelWithoutNodes if hide_nodes else GraphModel).from_db(
            store_listing_version.AgentGraph
        )

    except Exception as e:
        logger.error(f"Error getting agent: {e}")
        raise DatabaseError("Failed to fetch agent") from e


async def get_store_agent_by_version_id(
    store_listing_version_id: str,
) -> store_model.StoreAgentDetails:
    """Get agent details from the StoreAgent view (APPROVED agents only).

    See also: `get_store_agent_details_as_admin()` which bypasses the
    APPROVED-only StoreAgent view for admin preview of pending submissions.
    """
    logger.debug(f"Getting store agent details for {store_listing_version_id}")

    try:
        agent = await prisma.models.StoreAgent.prisma().find_first(
            where={"listing_version_id": store_listing_version_id}
        )

        if not agent:

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Check logs for 'Error getting agent' with the chained cause.
  2. If it's graph JSON/model drift, re-save the affected graph with the current backend or run the graph-migration fix for stored JSON.
  3. Regenerate the Prisma client after schema changes.
  4. On persistent failure, verify the specific listing version's graph rows directly in the DB for corruption.

Example fix

# before — not-found is swallowed into DatabaseError
except Exception as e:
    raise DatabaseError("Failed to fetch agent") from e
# after — preserve the 404 semantics
except NotFoundError:
    raise
except Exception as e:
    raise DatabaseError("Failed to fetch agent") from e
Defensive patterns

Strategy: try-catch

Validate before calling

// Nothing user-side can prevent DB/model failures; validate the id shape at least
if (!/^[a-z0-9]{20,}$/.test(versionId)) throw new RangeError('bad version id');

Type guard

function isDatabaseError(e: unknown): e is DatabaseError {
  return e instanceof Error && e.message === 'Failed to fetch agent';
}

Try / catch

try { return await getAvailableGraph(versionId); }
catch (e) {
  // note: not-found is ALSO wrapped here — check the cause chain
  if (e instanceof DatabaseError && e.__cause__ instanceof NotFoundError) return null;
  throw e;
}

Prevention

When it happens

Trigger: Fetching an available graph while the DB errors, the include of AgentGraph with AGENT_GRAPH_INCLUDE fails on inconsistent relations, or graph node/link JSON stored in the DB doesn't match the model (schema drift between graph versions).

Common situations: Graphs created by an older backend version with fields the current from_db rejects; interrupted graph saves leaving partial JSON; Prisma client/schema mismatch; DB connectivity issues.

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/ec0a3e4c63a56056. Report an issue: GitHub.