The smart grid concept is predicated upon the pervasive use of advanced digital communication, information techniques, and artificial intelligence for the current power system, to be more characteristics of the real-time monitoring and controlling of the supply/demand. Microgrids are modern types of power systems used for distributed energy resource (DER) integration. However, the microgrid energy management, the control, and protection of microgrid components (energy sources, loads, and local storage units) is an important challenge. In this paper, the distributed energy management algorithm and control strategy of a smart microgrid is proposed using an intelligent multi-agent system (MAS) approach to achieve multiple objectives in real-time. The MAS proposed is developed with co-simulation tools, which the microgrid model, simulated using MATLAB/Simulink, and the MAS algorithm implemented in JADE through a middleware MACSimJX. The main study is to develop a new approach, able to communicate a multi-task environment such as MAS inside the S-function block of Simulink, to achieve the optimal energy management objectives.