The installation of smart grids by utilities is driving the growth of the energy industry, allowing energy management systems (EMSs) to improve operational efficiency. Increasing consumers' interest in efficient energy consumption and distributed energy resources requires an EMS that can manage large numbers of powered devices within homes, buildings, and residential areas. An energy management agent (EMA) is a technology standard under development by ISO/IEC JTC 1/SC 25/WG 1. The EMA standard offers convenient and intelligent energy management services while supporting interoperability for demand response signals to smart grids. As wireless providers transition toward 5G and optical networks, EMAs are evolving into powerful frameworks of interconnected EMAs associated with cloud and edge computing. This article proposes a hierarchical distributed architecture that combines the advantages of both hierarchical and distributed architectures. A hierarchical architecture provides large-scale information acquisition, communications, processing, and control for cooperative energy management in homes and grids through cloud computing, while a distributed architecture provides autonomous decision making capability with agent-based intelligence through edge computing. The experimental results demonstrate the substantial achievements of the proposed hierarchical distributed EMA framework based on an actual protocol and system implementation. Finally, this article introduces various opportunities for using this framework with selected emerging technologies in smart city environments.