From 4362aaab75648a210aba73af5b0ffbfcded9707f Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Fri, 30 Jan 2026 15:24:32 -0600 Subject: [PATCH] fix: populate user_id in AgentExecutorBlock nodes at save time Generated agents have empty user_id in AgentExecutorBlock nodes. This fix populates the actual user_id when saving the agent to the library, ensuring sub-agents run with correct permissions. --- .../chat/tools/agent_generator/core.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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 72f4f13e03..a31474ec10 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 @@ -26,6 +26,9 @@ from .service import ( logger = logging.getLogger(__name__) +# Block ID for AgentExecutorBlock - used to identify sub-agent nodes +AGENT_EXECUTOR_BLOCK_ID = "e189baac-8c20-45a1-94a7-55177ea42565" + class ExecutionSummary(TypedDict): """Summary of a single execution for quality assessment.""" @@ -671,6 +674,27 @@ def _reassign_node_ids(graph: Graph) -> None: link.sink_id = id_map[link.sink_id] +def _populate_agent_executor_user_ids(agent_json: dict[str, Any], user_id: str) -> None: + """Populate user_id in AgentExecutorBlock nodes. + + The external agent generator creates AgentExecutorBlock nodes with empty user_id. + This function fills in the actual user_id so sub-agents run with correct permissions. + + Args: + agent_json: Agent JSON dict (modified in place) + user_id: User ID to set + """ + for node in agent_json.get("nodes", []): + if node.get("block_id") == AGENT_EXECUTOR_BLOCK_ID: + input_default = node.get("input_default", {}) + if not input_default.get("user_id"): + input_default["user_id"] = user_id + node["input_default"] = input_default + logger.debug( + f"Set user_id for AgentExecutorBlock node {node.get('id')}" + ) + + async def save_agent_to_library( agent_json: dict[str, Any], user_id: str, is_update: bool = False ) -> tuple[Graph, Any]: @@ -684,6 +708,9 @@ async def save_agent_to_library( Returns: Tuple of (created Graph, LibraryAgent) """ + # Populate user_id in AgentExecutorBlock nodes before conversion + _populate_agent_executor_user_ids(agent_json, user_id) + graph = json_to_graph(agent_json) if is_update: