Depth sorting and ai framework