Currently, modern power grids are evolving into complex cyber-physical systems integrated with distributed energy resources that can be controlled and monitored by computer-based algorithms. Given the increasing prevalence of artificial intelligence algorithms, it is essential to explore the possibility of energy management in microgrids by implementing control methodologies with advanced processing centers. This study proposes a novel smart multi-agent-based framework under a tendering process framework with a bottom-up approach to control and manage the flow of energy into a grid-connected microgrid (MG). The tendering organization in this structure as an upstream agent allocates demand among generators, creates a balance between supply and demand, and provides optimal energy cost for the MG. To optimize the electricity cost and decrease the use of grid power, the first-price sealed-bid (FPSB) algorithm is implemented over the tendering process. The proposed approach from one side optimally allocates energy among generators, and, from the other side, guarantees the system from blackouts. Theoretical analysis and results demonstrate that the proposed technique is easy to implement and provides a robust and stable control for MGs, which can guarantee energy management as well as flexible and online control. Furthermore, results show the proposed framework besides the real-time allocation of power among providers to optimize the injected power from the grid so that the total injected power by the grid is 146.92 kWh and the injected power to the grid is 214.34 kWh.