From 54e2574816d9c28833ac85559f15aab3068693a1 Mon Sep 17 00:00:00 2001 From: akhisud3195 Date: Wed, 16 Jul 2025 16:46:31 +0530 Subject: [PATCH] Suppress add new agent and add new tool by copilot if one exists already --- .../[projectId]/copilot/components/messages.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/rowboat/app/projects/[projectId]/copilot/components/messages.tsx b/apps/rowboat/app/projects/[projectId]/copilot/components/messages.tsx index 04c22999..bb376aa9 100644 --- a/apps/rowboat/app/projects/[projectId]/copilot/components/messages.tsx +++ b/apps/rowboat/app/projects/[projectId]/copilot/components/messages.tsx @@ -223,7 +223,11 @@ function AssistantMessage({ // Only apply, do not update appliedActions here if (action.action === 'create_new') { switch (action.config_type) { - case 'agent': + case 'agent': { + // Prevent duplicate agent names + if (workflow.agents.some((agent: any) => agent.name === action.name)) { + return; + } dispatch({ type: 'add_agent', agent: { @@ -232,7 +236,12 @@ function AssistantMessage({ } }); break; - case 'tool': + } + case 'tool': { + // Prevent duplicate tool names + if (workflow.tools.some((tool: any) => tool.name === action.name)) { + return; + } dispatch({ type: 'add_tool', tool: { @@ -241,6 +250,7 @@ function AssistantMessage({ } }); break; + } case 'prompt': dispatch({ type: 'add_prompt', @@ -276,7 +286,7 @@ function AssistantMessage({ break; } } - }, [dispatch]); + }, [dispatch, workflow.agents, workflow.tools]); // Memoized handleApplyAll for useEffect dependencies const handleApplyAll = useCallback(() => {