Centralization has become a de facto standard for implementing networked environments such as the Cyber–Physical Systems (CPS). Though easy to implement and control, centralized systems are difficult and expensive to scale in terms of the number of devices and the flow of information. This set of circumstances calls for a decentralized and distributed architecture for realizing such networked systems. However, due to the absence of global information in decentralized systems, one of the primary challenges is to find the best solution for problems distributed across the devices which are part of the CPS. Since the problems are distributed and no participating device has access to the full information, the devices may need to interact and share the information to select the best solution for a problem occurred. In this paper, we present a decentralized and distributed mechanism, which adapts to a stream of varying problems and continuously evolves and learns the best mappings between the problems and their associated solutions. The proposed approach integrates the concepts propounded in the three major Immune theories and can cater to real-world situations. The evolved mappings are shared across the physical network, thereby accelerating the search for the best set of solutions. In order to validate the performance of the proposed mechanism, we present the results obtained from solving a problem of sorting a stream of varying data in an emulated decentralized and distributed manner. To substantiate its working in real-world scenarios, we also describe the results obtained by embodying the system in real robots that discover the best path-following algorithms.