An algorithm that mimics our tribal instincts could help AI learn to socialize