From 41beae11226d79ba6a29c9c97cee886101875508 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Thu, 29 Jan 2026 21:16:20 -0600 Subject: [PATCH] fix: resolve library agent IDs to graph IDs in get_agent_as_json get_agent_as_json claimed to accept both graph IDs and library agent IDs but only tried direct graph lookup. When a library agent ID was passed, the function would return None (agent_not_found error). Now the function: 1. First tries direct graph lookup with the provided ID 2. If not found, resolves the ID as a library agent ID to get the graph_id 3. Then fetches the graph using the resolved graph_id --- .../chat/tools/agent_generator/core.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 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 f54d173cd6..f9d6b124c6 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 @@ -557,12 +557,12 @@ async def save_agent_to_library( async def get_agent_as_json( - graph_id: str, user_id: str | None + agent_id: str, user_id: str | None ) -> dict[str, Any] | None: """Fetch an agent and convert to JSON format for editing. Args: - graph_id: Graph ID or library agent ID + agent_id: Graph ID or library agent ID user_id: User ID Returns: @@ -570,8 +570,22 @@ async def get_agent_as_json( """ from backend.data.graph import get_graph - # Try to get the graph (version=None gets the active version) - graph = await get_graph(graph_id, version=None, user_id=user_id) + # First try to get the graph directly with the provided ID + graph = await get_graph(agent_id, version=None, user_id=user_id) + + # If not found, try to resolve as a library agent ID + if not graph and user_id: + try: + from backend.api.features.library import db as library_db + + library_agent = await library_db.get_library_agent(agent_id, user_id) + graph = await get_graph( + library_agent.graph_id, version=None, user_id=user_id + ) + except Exception: + # Library agent lookup failed, graph remains None + pass + if not graph: return None