The fact that the bike had problems at higher speeds/RPM, probably eliminate a battery problem, and makes fuel starvation more likely.
Fuel line routing can be an issue, partucularly when the tank is at low levels, or simply nearing the stand pipe level. Loops of fuel line usually contain bubbles that can block/restrict flow when the tank head pressure is low. As the fuel level drops in the carb bowls, the slow jets starve first, leaning those cylinders, idle becomes more difficult if even possible. Far cylinders from the fuel supply starve first.
Check your filter(s) for debris. You only need one good one. But, if it is the capture type instead of the blockage type, trapped particles also reduce the flow capacity. It's hard to get specific without knowing the year/model of your specific bike.
If the interior coating of your tank is failing, you will continue to have problems until it is addressed properly.
Cheers,