User blog comment:Mobo85/Hot off the Presses: "Across the Second Dimension" Debuts August 5/@comment-181516-20110608095506/@comment-3212462-20110608100450

It seems from the trailer that they don't discover he's an agent until after they enter the other dimension. I suspect they run into trouble with Alt. Doofenshmirtz and that's when he has to reveal himself so he can save them. In fact, I think it says that in the official movie description.

From the movie clip sneak peek, I'd say he gets captured almost right after that when he gets stuck in the skull.