The research of this paper is framed in the context of multi-layered, optimization-based approaches for microgrid control. Specifically, we focus on the design of real-time objectives that are typically proxies of long-term ones. Examples include tracking a predetermined dispatch plan or a battery state of-charge trajectory while satisfying the grid's operational constraints. If there is no formalized way of choosing the cost functions that reflect these objectives, an arbitrary choice could lead to a biased control in favor of certain objectives. The common approaches of configuring microgrid controllers usually rely on "oracle-based"approaches assumed to know exactly the studied scenarios. In this paper, we formalize the design goals of a real-time microgrid-control system by employing distributed energy-storage systems, and we give guidelines on how to design cost functions that satisfy them. Our method requires only certain parameters that can be chosen intuitively and gives a priori insight on the controller's behavior. The application of the theoretical work is verified in multiple scenarios by simulations performed using a realistic model of a microgrid.& COPY; 2023 The Authors. Published by Elsevier Ltd. This is an open access article under the CC BY license (http://creativecommons.org/licenses/by/4.0/).