This paper presents a cluster-based self-organizing algorithm for creating automatically ad-hoc networks including diverse wireless devices such as PDA, cell phones, laptops, wireless sensors, etc. In the proposed strategy each mobile device is represented by a multi-role agent, which generates a backbone among the devices within the environment based only on local interactions. During the operation each agent may act as leader, gateway or member according to both its neighborhood and its residual energy for creating and maintaining connected the network; this role switching allows the backbone reconfiguration when the nodes leave or arrive to the network yielding emergent behavior. After the network formation every agent varies the time interval and power of transmission allowing energy saving. Performance analysis via simulation is presented.