A key strategic objective of the University courses is the promotion and development of new and innovative teaching activities, also through the e-learning environment, with the aim of providing students with direct involvement in the learning process. Collaborative activities represent important and effective teaching methodologies that allow the improvements of learning outcomes through active learning. Furthermore, they can allow the development of soft skills because they enable learners to work together and practice critical reflection and conflict negotiation. Recently, online learning environments are being used to design and deliver assignments based on student work groups. Indeed, the development of digital technologies allows the organization of these online activities in a flexible way for both students and teachers. The goal of this work is to develop successful collaborative activities for undergraduate students to ensure the improvement of knowledge and soft skills on a specific topic. One of the fundamental factors that influence the success of collaborative learning is the students’ group formation, which consists in the realization of heterogeneous groups in terms of cognitive resources, characteristics, and behaviors, composed by four or five students. However, the correct implementation of groups requires careful profiling of each student’s behavior which can be difficult for the teacher to detect. In this work an intelligent software, developed using Artificial Intelligence algorithms, was used to assist the teacher in the realization of heterogeneous groups of students. It is composed of a Machine Learning model, consisting in clustering techniques applied to Moodle learning analytics performed to return clusters that identifies different students’ profiles, and a specific algorithm that automatically organizes the groups, ensuring the heterogeneity including at least one student from each cluster. At the end of the execution the software returns the list of the heterogeneous groups to the teacher. The software was applied to assignments that required working group within a specific online course for university students, using a Moodle e-learning platform. The quantitative analysis demonstrated the effectiveness of the numerical method for group composition proposed in this work to ensure successful collaborative activities, confirmed also by the perceptions of the students on the course.