Designing emergent behaviors: from local interactions to collective intelligence