Cyber-physical systems (CPSs) are nowadays an important component of most industrial infrastructures and materialize the integration of control systems with advanced information technologies. Commonly, they aggregate distinct communication platforms and networked devices or nodes with different capabilities and goals. The resulting increase in complexity has inevitably brought into playing new challenges, namely, on the physical world and cyber space. In these systems, the development and gaining of state awareness and how to deal with the inherent vulnerabilities of the overall system are essential and also challenging. In this paper, the problem of resilience enhancement in CPSs is addressed based on a hierarchical multi-agent framework that is implemented over a distributed middleware, in which each agent carries out specific tasks. Physical and cyber vulnerabilities are taken into account, and state and context awarenesses of the whole system are targeted. The proposed framework ensures a minimum level of acceptable performance in case of physical disturbances and malicious attacks, as demonstrated by experiments on an IPv6-based test-bed.