He first experiences a bad crowd and then experiences being swallowed by a whale, inside which he meets up with Geppetto again. They exit the whale and go home together, whereupon the Good Fairy comes back and changes the experienced puppet from animated wood into Real Boy material. Well that all makes sense. An extremely wealthy family wants an au pair, so they buy a robot. It doesn't find any.
More years pass.
It still doesn't find any. There are no others like it. It comes home. It builds itself a Real Boy body and asks Congress to declare it a human, but Congress won't. It asks the World Council to declare it a human, and they do.