@@ -1033,6 +1033,80 @@ def mock_get_model(model_id):
10331033 mock_get_model_by_model_id .assert_any_call (789 )
10341034
10351035
1036+ @patch ('backend.services.agent_service.get_model_by_model_id' )
1037+ @patch ('backend.services.agent_service.query_sub_agents_id_list' )
1038+ @patch ('backend.services.agent_service.search_tools_for_sub_agent' )
1039+ @patch ('backend.services.agent_service.search_agent_info_by_agent_id' )
1040+ @pytest .mark .asyncio
1041+ async def test_get_agent_info_impl_with_business_logic_model_no_display_name (mock_search_agent_info , mock_search_tools , mock_query_sub_agents_id , mock_get_model_by_model_id ):
1042+ """
1043+ Test get_agent_info_impl with business_logic_model_id but model has no display_name.
1044+
1045+ This test verifies that:
1046+ 1. The function correctly retrieves business logic model information when business_logic_model_id is not None
1047+ 2. It sets business_logic_model_name to None when model_info exists but has no display_name
1048+ """
1049+ # Setup
1050+ mock_agent_info = {
1051+ "agent_id" : 123 ,
1052+ "model_id" : 456 ,
1053+ "business_logic_model_id" : 789 ,
1054+ "business_description" : "Test agent"
1055+ }
1056+ mock_search_agent_info .return_value = mock_agent_info
1057+
1058+ mock_tools = [{"tool_id" : 1 , "name" : "Tool 1" }]
1059+ mock_search_tools .return_value = mock_tools
1060+
1061+ mock_sub_agent_ids = [101 , 102 ]
1062+ mock_query_sub_agents_id .return_value = mock_sub_agent_ids
1063+
1064+ # Mock model info for main model
1065+ mock_main_model_info = {
1066+ "model_id" : 456 ,
1067+ "display_name" : "GPT-4" ,
1068+ "provider" : "openai"
1069+ }
1070+
1071+ # Mock model info for business logic model without display_name
1072+ mock_business_logic_model_info = {
1073+ "model_id" : 789 ,
1074+ "provider" : "anthropic"
1075+ # No display_name field
1076+ }
1077+
1078+ # Mock get_model_by_model_id to return different values based on input
1079+ def mock_get_model (model_id ):
1080+ if model_id == 456 :
1081+ return mock_main_model_info
1082+ elif model_id == 789 :
1083+ return mock_business_logic_model_info
1084+ return None
1085+
1086+ mock_get_model_by_model_id .side_effect = mock_get_model
1087+
1088+ # Execute
1089+ result = await get_agent_info_impl (agent_id = 123 , tenant_id = "test_tenant" )
1090+
1091+ # Assert
1092+ expected_result = {
1093+ "agent_id" : 123 ,
1094+ "model_id" : 456 ,
1095+ "business_logic_model_id" : 789 ,
1096+ "business_description" : "Test agent" ,
1097+ "tools" : mock_tools ,
1098+ "sub_agent_id_list" : mock_sub_agent_ids ,
1099+ "model_name" : "GPT-4" ,
1100+ "business_logic_model_name" : None # Should be None when display_name is not in model_info
1101+ }
1102+ assert result == expected_result
1103+
1104+ # Verify both models were looked up
1105+ assert mock_get_model_by_model_id .call_count == 2
1106+ mock_get_model_by_model_id .assert_any_call (456 )
1107+ mock_get_model_by_model_id .assert_any_call (789 )
1108+
1109+
10361110async def test_list_all_agent_info_impl_success ():
10371111 """
10381112 Test successful retrieval of all agent information.
0 commit comments