Skip to content

Commit e4da2de

Browse files
committed
Bugfix: Agent cannot run based on the corresponding version
1 parent f1a0283 commit e4da2de

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

backend/agents/create_agent_info.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from services.memory_config_service import build_memory_context
2020
from services.image_service import get_vlm_model
2121
from 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
2223
from database.tool_db import search_tools_for_sub_agent
2324
from database.model_management_db import get_model_records, get_model_by_model_id
2425
from 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)

backend/services/agent_service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ async def prepare_agent_run(
15691569
user_id=user_id,
15701570
language=language,
15711571
allow_memory_search=allow_memory_search,
1572+
is_debug=agent_request.is_debug,
15721573
)
15731574
agent_run_manager.register_agent_run(
15741575
agent_request.conversation_id, agent_run_info, user_id)

0 commit comments

Comments
 (0)