Update CSV import to append location for duplicate agents
This commit is contained in:
parent
30a1c4ab46
commit
56ae3f41a4
1 changed files with 16 additions and 10 deletions
26
main.py
26
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue