So I see people talking about the Bartimaeus group in Hogwarts and what house they'd be in and I like this, but I'll raise you one better.
In Nathaniel's first year, he goes into the forbidden section of the library, like you do, and discovers a so old book that nobody even remembers it exists. It's about summon spirits, supposedly, so of course Nate has to try it out and poof, summons Bartimaeus.
Bart likes screwing with all the other students, especially Nate, that he decides to stick around. None of the teachers recognise him, but he's here so he must be unrolled, so none question him because they don't want to look like they forgot a student.
Dumbledore knows exactly what's going on and just let's it happen. Bart's not hurting anyone after all.
Kitty eventually figures it out and the three become frienemies mostly out of necessities to keep Bart's identify a secret because Kitty actually kind of likes Bart and Nat doesn't want to get in trouble for going into the forbidden part of the library.