Abstract. We consider the problem of exploiting the microgenerators connected to the low voltage or medium voltage grid in order to provide distributed reactive power compensation in the power distribution network, solving the optimal reactive power flow problem for the minimization of power distribution losses subject to voltage constraints. The proposed strategy requires that all the intelligent agents, located at the generator buses, measure their voltage and share these data with the other agents via a communication infrastructure. The agents then adjust the amount of reactive power injected into the grid according to a policy which is a specialization of duality-based methods for constrained convex optimization. Convergence of the algorithm to the configuration of minimum losses and feasible voltages is proved analytically. Simulations are provided in order to demonstrate the algorithm behavior, and the innovative feedback nature of such strategy is discussed.