This paper points out the lack of understanding of how individual-level psychological processes in collective intelligence, especially human collective intelligence, generate self-organizing structures at the social level. Unlike previous studies that have focused on general principles while overlooking psychological factors, this paper emphasizes the role of 'Theory of Mind' in enhancing flexible collective intelligence of humans, while emphasizing the broad applicability of the principles of collective intelligence through examples of other complex adaptive systems. It presents the hypothesis that AI with Theory of Mind can enhance collective intelligence in a similar way to humans, and analyzes the large-scale impact by considering AI as an agent of 'social ecosystem' rather than a mere tool. Finally, it explains the process of individuals (humans or AI) adapting to socio-cognitive niches and integrating into groups, rather than through genetic or algorithmic programming.