@@ -573,6 +573,15 @@ async def get_agent_info_impl(agent_id: int, tenant_id: str):
573573 elif "business_logic_model_name" not in agent_info :
574574 agent_info ["business_logic_model_name" ] = None
575575
576+ # Check agent availability
577+ is_available , unavailable_reasons = check_agent_availability (
578+ agent_id = agent_id ,
579+ tenant_id = tenant_id ,
580+ agent_info = agent_info
581+ )
582+ agent_info ["is_available" ] = is_available
583+ agent_info ["unavailable_reasons" ] = unavailable_reasons
584+
576585 return agent_info
577586
578587
@@ -1168,23 +1177,13 @@ async def list_all_agent_info_impl(tenant_id: str) -> list[dict]:
11681177 if not agent ["enabled" ]:
11691178 continue
11701179
1171- unavailable_reasons : list [str ] = []
1172-
1173- tool_info = search_tools_for_sub_agent (
1174- agent_id = agent ["agent_id" ], tenant_id = tenant_id )
1175- tool_id_list = [tool ["tool_id" ]
1176- for tool in tool_info if tool .get ("tool_id" ) is not None ]
1177- if tool_id_list :
1178- tool_statuses = check_tool_is_available (tool_id_list )
1179- if not all (tool_statuses ):
1180- unavailable_reasons .append ("tool_unavailable" )
1181-
1182- model_reasons = _collect_model_availability_reasons (
1183- agent = agent ,
1180+ # Use shared availability check function
1181+ _ , unavailable_reasons = check_agent_availability (
1182+ agent_id = agent ["agent_id" ],
11841183 tenant_id = tenant_id ,
1184+ agent_info = agent ,
11851185 model_cache = model_cache
11861186 )
1187- unavailable_reasons .extend (model_reasons )
11881187
11891188 # Preserve the raw data so we can adjust availability for duplicates
11901189 enriched_agents .append ({
@@ -1295,6 +1294,56 @@ def _check_single_model_availability(
12951294 return []
12961295
12971296
1297+ def check_agent_availability (
1298+ agent_id : int ,
1299+ tenant_id : str ,
1300+ agent_info : dict | None = None ,
1301+ model_cache : Dict [int , Optional [dict ]] | None = None
1302+ ) -> tuple [bool , list [str ]]:
1303+ """
1304+ Check if an agent is available based on its tools and model configuration.
1305+
1306+ Args:
1307+ agent_id: The agent ID to check
1308+ tenant_id: The tenant ID
1309+ agent_info: Optional pre-fetched agent info (to avoid duplicate DB queries)
1310+ model_cache: Optional model cache for performance optimization
1311+
1312+ Returns:
1313+ tuple: (is_available: bool, unavailable_reasons: list[str])
1314+ """
1315+ unavailable_reasons : list [str ] = []
1316+
1317+ if model_cache is None :
1318+ model_cache = {}
1319+
1320+ # Fetch agent info if not provided
1321+ if agent_info is None :
1322+ agent_info = search_agent_info_by_agent_id (agent_id , tenant_id )
1323+
1324+ if not agent_info :
1325+ return False , ["agent_not_found" ]
1326+
1327+ # Check tool availability
1328+ tool_info = search_tools_for_sub_agent (agent_id = agent_id , tenant_id = tenant_id )
1329+ tool_id_list = [tool ["tool_id" ] for tool in tool_info if tool .get ("tool_id" ) is not None ]
1330+ if tool_id_list :
1331+ tool_statuses = check_tool_is_available (tool_id_list )
1332+ if not all (tool_statuses ):
1333+ unavailable_reasons .append ("tool_unavailable" )
1334+
1335+ # Check model availability
1336+ model_reasons = _collect_model_availability_reasons (
1337+ agent = agent_info ,
1338+ tenant_id = tenant_id ,
1339+ model_cache = model_cache
1340+ )
1341+ unavailable_reasons .extend (model_reasons )
1342+
1343+ is_available = len (unavailable_reasons ) == 0
1344+ return is_available , unavailable_reasons
1345+
1346+
12981347def insert_related_agent_impl (parent_agent_id , child_agent_id , tenant_id ):
12991348 # search the agent by bfs, check if there is a circular call
13001349 search_list = deque ([child_agent_id ])
0 commit comments