From 56ae3f41a4c939f7366e3b68258d59331e78c3e8 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 19 Nov 2025 16:04:38 -0600 Subject: [PATCH] Update CSV import to append location for duplicate agents --- main.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index e75f9d9..3741913 100644 --- a/main.py +++ b/main.py @@ -1083,19 +1083,14 @@ async def import_agents_csv( for row_num, row in enumerate(csv_reader, start=1): try: - agent_name = row.get("agent_name") - if not agent_name: - continue - - # Check for duplicates (skip if exists) - existing = await crud.get_agent_by_name(agent_name) - if existing and existing["created_by"] == user_id: + agent_name_from_csv = row.get("agent_name") + if not agent_name_from_csv: skipped_count += 1 continue - - # Parse fields + + # Parse fields into agent_data first agent_data = { - "agent_name": agent_name, + "agent_name": agent_name_from_csv, "agent_tool": row.get("agent_tool", ""), "agent_description": row.get("agent_description"), "agent_purpose": row.get("agent_purpose"), @@ -1124,6 +1119,17 @@ async def import_agents_csv( except: pass # Ignore invalid metadata JSON + # Check for existing agent with same name + existing_agent = await crud.get_agent_by_name(agent_data["agent_name"]) + if existing_agent: + # If duplicate, append location to name + location = agent_data.get("agent_location") + if location and location.strip(): + agent_data["agent_name"] = f"{agent_data['agent_name']} - {location.strip()}" + else: + # Fallback if no location + agent_data["agent_name"] = f"{agent_data['agent_name']} - Imported" + # Create agent await crud.create_agent(agent_data, user_id) success_count += 1