From 9d96807737b8d0fef970a9c80d7a26a461d3b94c Mon Sep 17 00:00:00 2001 From: Otto Date: Mon, 2 Feb 2026 15:17:33 +0000 Subject: [PATCH] fix(chat): resolve both graph_id and library_agent_id in edit_agent Fixes SECRT-1863 The edit_agent tool's schema claims it accepts either a graph ID or library agent ID, but CoPilot often passes library_agent_id (which it naturally grabs from context after creating/saving an agent), causing the lookup to fail. This adds explicit fallback logic in edit_agent to: 1. First try get_agent_as_json with the ID as-is (treats as graph_id) 2. If not found, try to resolve it as a library_agent_id 3. If found, use the library agent's graph_id to fetch the agent This makes the schema truthful and improves robustness for CoPilot. --- .../backend/api/features/chat/tools/edit_agent.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py b/autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py index 2c2c48226b..70e118eb12 100644 --- a/autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py +++ b/autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py @@ -4,6 +4,7 @@ import logging from typing import Any from backend.api.features.chat.model import ChatSession +from backend.api.features.library import db as library_db from .agent_generator import ( AgentGeneratorNotConfiguredError, @@ -120,6 +121,18 @@ class EditAgentTool(BaseTool): current_agent = await get_agent_as_json(agent_id, user_id) + # If not found by graph_id, try resolving as library_agent_id + if current_agent is None and user_id: + try: + library_agent = await library_db.get_library_agent(agent_id, user_id) + logger.debug( + f"Resolved library_agent_id '{agent_id}' to graph_id " + f"'{library_agent.graph_id}'" + ) + current_agent = await get_agent_as_json(library_agent.graph_id, user_id) + except Exception as e: + logger.debug(f"Could not resolve '{agent_id}' as library_agent_id: {e}") + if current_agent is None: return ErrorResponse( message=f"Could not find agent with ID '{agent_id}' in your library.",