1919from services .memory_config_service import build_memory_context
2020from services .image_service import get_vlm_model
2121from database .agent_db import search_agent_info_by_agent_id , query_sub_agents_id_list
22+ from database .agent_version_db import query_current_version_no
2223from database .tool_db import search_tools_for_sub_agent
2324from database .model_management_db import get_model_records , get_model_by_model_id
2425from database .client import minio_client
@@ -75,13 +76,14 @@ async def create_agent_config(
7576 language : str = LANGUAGE ["ZH" ],
7677 last_user_query : str = None ,
7778 allow_memory_search : bool = True ,
79+ version_no : int = 0 ,
7880):
7981 agent_info = search_agent_info_by_agent_id (
80- agent_id = agent_id , tenant_id = tenant_id )
82+ agent_id = agent_id , tenant_id = tenant_id , version_no = version_no )
8183
8284 # create sub agent
8385 sub_agent_id_list = query_sub_agents_id_list (
84- main_agent_id = agent_id , tenant_id = tenant_id )
86+ main_agent_id = agent_id , tenant_id = tenant_id , version_no = version_no )
8587 managed_agents = []
8688 for sub_agent_id in sub_agent_id_list :
8789 sub_agent_config = await create_agent_config (
@@ -91,10 +93,11 @@ async def create_agent_config(
9193 language = language ,
9294 last_user_query = last_user_query ,
9395 allow_memory_search = allow_memory_search ,
96+ version_no = version_no ,
9497 )
9598 managed_agents .append (sub_agent_config )
9699
97- tool_list = await create_tool_config_list (agent_id , tenant_id , user_id )
100+ tool_list = await create_tool_config_list (agent_id , tenant_id , user_id , version_no = version_no )
98101
99102 # Build system prompt: prioritize segmented fields, fallback to original prompt field if not available
100103 duty_prompt = agent_info .get ("duty_prompt" , "" )
@@ -202,13 +205,13 @@ async def create_agent_config(
202205 return agent_config
203206
204207
205- async def create_tool_config_list (agent_id , tenant_id , user_id ):
208+ async def create_tool_config_list (agent_id , tenant_id , user_id , version_no : int = 0 ):
206209 # create tool
207210 tool_config_list = []
208211 langchain_tools = await discover_langchain_tools ()
209212
210213 # now only admin can modify the agent, user_id is not used
211- tools_list = search_tools_for_sub_agent (agent_id , tenant_id )
214+ tools_list = search_tools_for_sub_agent (agent_id , tenant_id , version_no = version_no )
212215 for tool in tools_list :
213216 param_dict = {}
214217 for param in tool .get ("params" , []):
@@ -355,7 +358,21 @@ async def create_agent_run_info(
355358 user_id : str ,
356359 language : str = "zh" ,
357360 allow_memory_search : bool = True ,
361+ is_debug : bool = False ,
358362):
363+ # Determine which version_no to use based on is_debug flag
364+ # If is_debug=false, use the current published version (current_version_no)
365+ # If is_debug=true, use version 0 (draft/editing state)
366+ if is_debug :
367+ version_no = 0
368+ else :
369+ # Get current published version number
370+ version_no = query_current_version_no (agent_id = agent_id , tenant_id = tenant_id )
371+ # Fallback to 0 if no published version exists
372+ if version_no is None :
373+ version_no = 0
374+ logger .info (f"Agent { agent_id } has no published version, using draft version 0" )
375+
359376 final_query = await join_minio_file_description_to_query (minio_files = minio_files , query = query )
360377 model_list = await create_model_config_list (tenant_id )
361378 agent_config = await create_agent_config (
@@ -365,6 +382,7 @@ async def create_agent_run_info(
365382 language = language ,
366383 last_user_query = final_query ,
367384 allow_memory_search = allow_memory_search ,
385+ version_no = version_no ,
368386 )
369387
370388 remote_mcp_list = await get_remote_mcp_server_list (tenant_id = tenant_id )
0 commit comments