One of the plot points of Age of Ultron is that Ultron is not a robot, it is an intelligence hosted into many separate robots. As a consequence, the only way to destroy it is to destroy each individual robot; so long as even one robot remains, Ultron is still there and can go on Ultroning. And yet, Ultron decides to bring every single robot hosting his intelligence into the final battle. The Avengers destroy all the robots and Ultron is no more (technically, this is a spoiler, but seriously, did anybody think even for a moment that anything different was ever going to happen?)
But things didn't have to be this way. Ultron could have done what effectively amounts to a security backup: take a couple dozen robots and hide them in various remote secure locations. Given the size of his army, this wouldn't have affected the immediate outcome of the final battle (if the Avengers can take on an Army of 1000 robots, they can also take on an Army of 1020 robots), but Ultron could have used the backup to remain active and stage a comeback some time in the future.