From bf7fea9f6688efaadf7dea669573986e8d7202c1 Mon Sep 17 00:00:00 2001 From: panyehong <2655992392@qq.com> Date: Tue, 2 Dec 2025 21:04:21 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20the=20pending=20of=20agent?= =?UTF-8?q?=20duplicate=20name=20handling.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/services/agent_service.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/services/agent_service.py b/backend/services/agent_service.py index c222efe7a..1db2374b4 100644 --- a/backend/services/agent_service.py +++ b/backend/services/agent_service.py @@ -1056,14 +1056,16 @@ async def import_agent_by_agent_id( regeneration_model_id = business_logic_model_id or model_id if regeneration_model_id: try: - agent_name = _regenerate_agent_name_with_llm( + # Offload blocking LLM regeneration to a thread to avoid blocking the event loop + agent_name = await asyncio.to_thread( + _regenerate_agent_name_with_llm, original_name=agent_name, existing_names=existing_names, task_description=import_agent_info.business_description or import_agent_info.description or "", model_id=regeneration_model_id, tenant_id=tenant_id, language=LANGUAGE["ZH"], # Default to Chinese, can be enhanced later - agents_cache=all_agents + agents_cache=all_agents, ) logger.info(f"Regenerated agent name: '{agent_name}'") except Exception as e: @@ -1088,14 +1090,16 @@ async def import_agent_by_agent_id( regeneration_model_id = business_logic_model_id or model_id if regeneration_model_id: try: - agent_display_name = _regenerate_agent_display_name_with_llm( + # Offload blocking LLM regeneration to a thread to avoid blocking the event loop + agent_display_name = await asyncio.to_thread( + _regenerate_agent_display_name_with_llm, original_display_name=agent_display_name, existing_display_names=existing_display_names, task_description=import_agent_info.business_description or import_agent_info.description or "", model_id=regeneration_model_id, tenant_id=tenant_id, language=LANGUAGE["ZH"], # Default to Chinese, can be enhanced later - agents_cache=all_agents + agents_cache=all_agents, ) logger.info(f"Regenerated agent display_name: '{agent_display_name}'") except Exception as e: