Libya armed groups agree to leave Tripoli after deadly fighting