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.

fix(backend): library agent creation and version update improvements (#11731)

Zamil Majdy22ca8955c593
diff --git a/autogpt_platform/backend/backend/api/features/library/db.py b/autogpt_platform/backend/backend/api/features/library/db.py
index 69ed0d2730..1c17e7b36c 100644
--- a/autogpt_platform/backend/backend/api/features/library/db.py
+++ b/autogpt_platform/backend/backend/api/features/library/db.py
@@ -489,7 +489,7 @@ async def update_agent_version_in_library(
agent_graph_version: int,
) -> library_model.LibraryAgent:
"""
- Updates the agent version in the library if useGraphIsActiveVersion is True.
+ Updates the agent version in the library for any agent owned by the user.
Args:
user_id: Owner of the LibraryAgent.
@@ -498,20 +498,31 @@ async def update_agent_version_in_library(
Raises:
DatabaseError: If there's an error with the update.
+ NotFoundError: If no library agent is found for this user and agent.
"""
logger.debug(
f"Updating agent version in library for user #{user_id}, "
f"agent #{agent_graph_id} v{agent_graph_version}"
)
- try:
- library_agent = await prisma.models.LibraryAgent.prisma().find_first_or_raise(
+ async with transaction() as tx:
+ library_agent = await prisma.models.LibraryAgent.prisma(tx).find_first_or_raise(
where={
"userId": user_id,
"agentGraphId": agent_graph_id,
- "useGraphIsActiveVersion": True,
},
)
- lib = await prisma.models.LibraryAgent.prisma().update(
+
+ # Delete any conflicting LibraryAgent for the target version
+ await prisma.models.LibraryAgent.prisma(tx).delete_many(
+ where={
+ "userId": user_id,
+ "agentGraphId": agent_graph_id,
+ "agentGraphVersion": agent_graph_version,
+ "id": {"not": library_agent.id},
+ }
+ )
+
+ lib = await prisma.models.LibraryAgent.prisma(tx).update(
where={"id": library_agent.id},
data={
"AgentGraph": {
@@ -525,13 +536,13 @@ async def update_agent_version_in_library(
},
include={"AgentGraph": True},
)
- if lib is None:
- raise NotFoundError(f"Library agent {library_agent.id} not found")
- return library_model.LibraryAgent.from_db(lib)
- except prisma.errors.PrismaError as e:
- logger.error(f"Database error updating agent version in library: {e}")
- raise DatabaseError("Failed to update agent version in library") from e
+ if lib is None:
+ raise NotFoundError(
+ f"Failed to update library agent for {agent_graph_id} v{agent_graph_version}"
+ )
+
+ return library_model.LibraryAgent.from_db(lib)
async def update_library_agent(
@@ -825,6 +836,7 @@ async def add_store_agent_to_library(
}
},
"isCreatedByUser": False,
+ "useGraphIsActiveVersion": False,
"settings": SafeJson(
_initialize_graph_settings(graph_model).model_dump()
),
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/hooks/useMarketplaceUpdate.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/hooks/useMarketplaceUpdate.ts
index fc32ba4b8d..158fd3f134 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/hooks/useMarketplaceUpdate.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/hooks/useMarketplaceUpdate.ts
@@ -92,29 +92,33 @@ export function useMarketplaceUpdate({ agent }: UseMarketplaceUpdateProps) {
const isUserCreator = agent?.owner_user_id === user?.id;
- // Check if there's a pending submission for this specific agent version
const submissionsResponse = okData(submissionsData) as any;
- const hasPendingSubmissionForCurrentVersion =
- isUserCreator &&
- submissionsResponse?.submissions?.some(
- (submission: StoreSubmission) =>
- submission.agent_id === agent.graph_id &&
- submission.agent_version === agent.graph_version &&
- submission.status === "PENDING",
- );
+ const agentSubmissions =
+ submissionsResponse?.submissions?.filter(
+ (submission: StoreSubmission) => submission.agent_id === agent.graph_id,
+ ) || [];
+
+ const highestSubmittedVersion =
+ agentSubmissions.length > 0
+ ? Math.max(
+ ...agentSubmissions.map(
+ (submission: StoreSubmission) => submission.agent_version,
+ ),
+ )
+ : 0;
+
+ const hasUnpublishedChanges =
+ isUserCreator && agent.graph_version > highestSubmittedVersion;
if (!storeAgent) {
return {
hasUpdate: false,
latestVersion: undefined,
isUserCreator,
- hasPublishUpdate:
- isUserCreator && !hasPendingSubmissionForCurrentVersion,
+ hasPublishUpdate: agentSubmissions.length > 0 && hasUnpublishedChanges,
};
}
- // Get the latest version from the marketplace
- // agentGraphVersions array contains graph version numbers as strings, get the highest one
const latestMarketplaceVersion =
storeAgent.agentGraphVersions?.length > 0
? Math.max(
@@ -124,18 +128,11 @@ export function useMarketplaceUpdate({ agent }: UseMarketplaceUpdateProps) {
)
: undefined;
- // Show publish update button if:
- // 1. User is the creator
- // 2. No pending submission for current version
- // 3. Either: agent not published yet OR local version is newer than marketplace
const hasPublishUpdate =
isUserCreator &&
- !hasPendingSubmissionForCurrentVersion &&
- (latestMarketplaceVersion === undefined || // Not published yet
- agent.graph_version > latestMarketplaceVersion); // Or local version is newer
+ agent.graph_version >
+ Math.max(latestMarketplaceVersion || 0, highestSubmittedVersion);
- // If marketplace version is newer than user's version, show update banner
- // This applies to both creators and non-creators
const hasMarketplaceUpdate =
latestMarketplaceVersion !== undefined &&
latestMarketplaceVersion > agent.graph_version;
diff --git a/autogpt_platform/frontend/src/components/contextual/EditAgentModal/components/EditAgentForm.tsx b/autogpt_platform/frontend/src/components/contextual/EditAgentModal/components/EditAgentForm.tsx
index 6a6e7401a3..5c0c4fa1de 100644
--- a/autogpt_platform/frontend/src/components/contextual/EditAgentModal/components/EditAgentForm.tsx
+++ b/autogpt_platform/frontend/src/components/contextual/EditAgentModal/components/EditAgentForm.tsx
@@ -133,7 +133,7 @@ export function EditAgentForm({
<Input
id={field.name}
label="Changes Summary"
- type="text"
+ type="textarea"
placeholder="Briefly describe what you changed"
error={form.formState.errors.changes_summary?.message}
{...field}
diff --git a/autogpt_platform/frontend/src/components/contextual/EditAgentModal/components/useEditAgentForm.ts b/autogpt_platform/frontend/src/components/contextual/EditAgentModal/components/useEditAgentForm.ts
index 88ec698f8a..4f2ea49506 100644
--- a/autogpt_platform/frontend/src/components/contextual/EditAgentModal/components/useEditAgentForm.ts
+++ b/autogpt_platform/frontend/src/components/contextual/EditAgentModal/components/useEditAgentForm.ts
@@ -47,7 +47,7 @@ export const useEditAgentForm = ({
changes_summary: z
.string()
.min(1, "Changes summary is required")
- .max(200, "Changes summary must be less than 200 characters"),
+ .max(500, "Changes summary must be less than 500 characters"),
agentOutputDemo: z
.string()
.refine(validateYouTubeUrl, "Please enter a valid YouTube URL"),
diff --git a/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/useAgentInfoStep.ts b/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/useAgentInfoStep.ts
index d46357846e..448d65b195 100644
--- a/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/useAgentInfoStep.ts
+++ b/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/useAgentInfoStep.ts
@@ -53,21 +53,24 @@ export function useAgentInfoStep({
useEffect(() => {
if (initialData?.agent_id) {
setAgentId(initialData.agent_id);
- const initialImages = [
- ...(initialData?.thumbnailSrc ? [initialData.thumbnailSrc] : []),
- ...(initialData.additionalImages || []),
- ];
- setImages(initialImages);
-
- // Update form with initial data
+ setImages(
+ Array.from(
+ new Set([
+ ...(initialData?.thumbnailSrc ? [initialData.thumbnailSrc] : []),
+ ...(initialData.additionalImages || []),
+ ]),
+ ),
+ );
form.reset({
- changesSummary: initialData.changesSummary || "",
+ changesSummary: isMarketplaceUpdate
+ ? ""
+ : initialData.changesSummary || "",
title: initialData.title,
subheader: initialData.subheader,
slug: initialData.slug.toLocaleLowerCase().trim(),
youtubeLink: initialData.youtubeLink,
category: initialData.category,
- description: initialData.description,
+ description: isMarketplaceUpdate ? "" : initialData.description,
recommendedScheduleCron: initialData.recommendedScheduleCron || "",
instructions: initialData.instructions || "",
agentOutputDemo: initialData.agentOutputDemo || "",
@@ -149,12 +152,7 @@ export function useAgentInfoStep({
agentId,
images,
isSubmitting,
- initialImages: initialData
- ? [
- ...(initialData?.thumbnailSrc ? [initialData.thumbnailSrc] : []),
- ...(initialData.additionalImages || []),
- ]
- : [],
+ initialImages: images,
initialSelectedImage: initialData?.thumbnailSrc || null,
handleImagesChange,
handleSubmit: form.handleSubmit(handleFormSubmit),