Perry the platypus, aka Agent P is the pet platypus of Phineas and Ferb. Unknown to them, he is a secret agent working for the O.W.C.A, which is a front for Zeus and the High Council. He was sent by the Gods to watch over his owners since they have the potential to be one of the great forces of good but too young to be recruited by the High Council. His other responsibilities include training new recruits from the animal kingdom. His battles with Dr. Doofenshmirtz are not related to the above since Doof himself has no dealing with the Devils (He's not bad as he wants them to believe, so they have no interest).
He has a lair under the Flynn-Fletcher's house that can be accessed through various passages. There, he receives mission briefing from Major Monogram, the leader of his division in the O.W.C.A.