 Anya was only meant to appear in the episode "The Wish" but was  brought back for "Doppelgängland" where she was made more humorous.  When the producers realized how funny Emma Caulfield (qv) was they  simply kept bringing her back, until she was made a regular cast  member (including appearing in the opening credits) at the start of  season five.