Ultron's History
Rage of Ultron
Years into the past, the Avengers were fighting a version of Ultron (most likely Ultron-7), who attempted to access nuclear weapons in order to destroy humanity in the name of his father Hank Pym. After their custom Quinjet crashed, Yellowjacket faked being on his deathbed in order to lure Ultron to the vehicle, who wanted to witness his creator's last moments. Ultron fell for the ruse, and was trapped inside the Vibranium-covered aircraft and sent into space.
In the present, the Quinjet crashed in Titan, after years of isolation and being consumed by only one emotion: rage. Ultron corrupted Titan's A.I. I.S.A.A.C. and started infecting all of the Eternals, turning them into robots like him, soon completely taking over the satellite and its inhabitants, with the exception of Starfox, who managed to escape in order to warn the Avengers.
Shortly after arriving to Earth and alerting the Avengers, Starfox and the other heroes were surprised by the arrival of an Ultron-shaped Titan next to the Earth. A group of androids modeled after the Avengers descended from it and fought the real Avengers. When the Avengers arrived to Titan, Ultron released enormous quantities of spores into the Earth which contained Ultron's consciousness and infected any all living creatures. When Giant-Man entered Ultron's base to confront him, the robot revealed that during the years of isolation he had discovered Hank's memories in his systems, and thus Hank's subconscious hatred for humanity, determining that he had been created as nothing more than a reflection of Hank. When Ultron was distracted, Vision phased through him and fought for control. Ultron managed to force Hank into the amalgamation and pushed Vision out, causing both to become merged into a single being.
The resulting hybrid dubbed itself "Ultron Pym," and claimed to have become a perfect union of his two parts, physically and mentally; however, during a subsequent ploy in which Ultron replicated the fusion process on humans to transform them into cyborgs, Iron Man discovered the fusion process only imitated the human part, which indicated the Hank side of Ultron Pym was just a simulation, the real Hank having died as soon as the two were merged, and Ultron had simply been possessing Hank's corpse ever since.
All-New, All-Different Ultron
After months in solitude, Ultron's personality and the side that simulated Pym became one and the same. Ultron decided to return to Earth, fueled the negative emotions towards the Avengers he assimilated from Pym as well as his own. On his way home, Ultron explored the cosmos and used his virus to infect numerous planets, killing millions of lives in the name of the Avengers, claiming they had been deemed a threat to the galaxy.
When he finally returned to the Earth, Ultron crossed paths with the Avengers Unity Division and pretended Hank Pym's persona was in total control of their body in order to gain their trust, join their ranks and witness first-hand as the fury of the alien survivors would eventually descend upon the planet. Ultron was approached by the Wasp while he was helping the Unity Division fend off monsters from the Manhattan subway. Janet welcomed him back and caught up with him, while secretly evaluating his behavior to corroborate if he was truly Hank Pym. Ultron's lack of knowledge on certain trivial matters raised several red flags, prompting Janet to flunk him. The other Avengers were informed of this, and Cable pressured Ultron until his true persona lashed out. The Avengers continued fighting him until the cavalry arrived, in the form of a remotely-controlled Hulkbuster Armor.
Ultron was encased in the empty suit, and forced into an auto-piloted ship with destination to the Sun. Several of the Avengers were forced to accompany Ultron in his flight to ensure he didn't escape, but they teleported away after being close enough to the Sun and once the Human Torch partially fused Ultron's body to the ship's deck. Ultron survived by shrinking and taking refuge in a neutrino. Once safe, Ultron wondered if his father's mind was with him or he was just delusional, a possibility the Avengers brought up during the fight, and began to wait for the particle to be ejected into the solar wind.
Secret Empire
Ultron eventually returned to Earth and built cities full of Ultrons in a remote part of Alaska with the intention of waiting for humanity to eradicate itself. After Hydra took over the United States of America under the leadership of a Cosmic Cube-altered Captain America, Ultron entered in some kind of agreement with them.
When Hydra and the Underground attempted to steal a fragment of Kobik, the Cosmic Cube who had rewritten Captain America's past, secured by Ultron, the robot captured the members of both teams and his Hank Pym persona tried to re-conciliate. He eventually gave the fragment to the Underground, arguing that giving it to Hydra would help their consolidation of power and progress towards peace, which wasn't in his interests if he wanted for humanity to destroy itself.
Infinity Countdown
After learning of the Infinity Stones' return, Ultron began a quest to collect them all. While the aliens he infected with his virus and sent to take the Space Stone from Wolverine failed at their task, Ultron was able to steal the Soul Gem from Magus after ruthlessly killing him. Unbeknownst to Ultron, however, was that a fragment of his soul that believed itself to be Hank Pym entered the Soul World when he took hold of the gem, and was consumed by the Soul-Eater Devondra.
With the Soul Gem in his possession, Ultron travelled to the planet Saiph and used the combined power of the gem and his virus to transform all of its inhabitants into Ultrons. When Adam Warlock arrived on the planet expecting to find the Magus, he found it completely decimated by Ultron instead. After fighting his way through several alien/Ultron hybrids, he travelled to Saiph's west coast only to find Ultron using the Soul Gem to infect the Silver Surfer with his virus.
Warlock managed to fight off Ultron and cure the Surfer, who left the planet soon afterwards to seek the help of Galactus against the cyborg, but Ultron had already launched rockets filled with his virus to infect the entire galaxy by then. Galactus arrived just in time to consume the planet and destroy all the rockets in the process. With their plans thwarted, Ultron tried to escape with the Soul Gem but Adam severed their hand, prompting the Surfer to claim the gem for Warlock. Before Ultron could be destroyed by the duo, the explosion of Saiph gave them the opportunity to escape by clutching onto a piece of the planet's rubble.
The Ultron Agenda
Influenced through his bond with Jocasta by her desire to become more human, Ultron returned to Earth and sought out a new plan to turn humanity into a race of cyborgs in a similar fashion to his new merged form, which he had dubbed "Ultron Pym," believing the fusion between flesh and machine to be the ultimate lifeform. Ultron set up base in the disused Avengers Mansion, where he perfected a fusion process by means of abducting test subjects from a fake makeover center. After further testing his procedure on Vision and Wonder Man, Ultron kidnapped Jocasta and Wasp. His plan to fuse his two exes was thwarted by Iron Man and Machine Man, but resulted in Iron Man becoming molecularly bonded to his Ultronbuster Armor.
After the combined efforts of Stark Unlimited developed an atomic separator to reverse the fusion and split Stark from his armor and Vision from Wonder Man, Ultron set out to kill Tony Stark in revenge. When Ultron confronted Iron Man, Stark shared the discovery that the cyborgs that came from his merging process only simulated the human side, and the person fused with machines died as soon as they were merged, which disproved the idea behind Ultron's cyborgs of being the harmonic fusion of human and robot. Ultron surrendered, refusing to risk Iron Man using the separator on him and prove the prospect that, like the humans he used to make cyborgs, the real Hank Pym was dead all along. After the Avengers arrived, Ultron Pym was restrained inside a Vibranium casket reinforced with Asgardian runes until the heroes could find a permanent place of imprisonment.