On constructing Lyapunov functions for multi-agent systems