It's been a while since I looked at my mod so I don't remember all the details, but, the AI uses the espionage system but doesn't use the unit itself. The AI still spawns the unit (as production of the unit is just based on a new yield I introduced which AI would accumulate normally through the games flavor system prompting it to build espionage buildings). However, once the unit spawns, the AI doesn't have to move it. It has access to the spy missions based on its current intelligence yield, visibility, and a few other factors I check, then chooses a target based on diplomacy factors, how many game points they have, and distance, and then chooses a mission from there. Once the mission is done, the AI unit is killed, and they won't access it again until they spawn a new unit.
I felt for the human player it was much more fun to use a unit and interact with the map. However, I knew the AI would never do this and made a separate system for them. It's not perfect, and the two aren't completely identical, but I think they're comparable and both AI and humans have access to the same stuff. I think, but don't completely remember, I might have even adjusted it in a later patch to give the AI a slight advantage with lower costs, etc. just to compensate for a human player being able to use everything better. However, my mod didn't just add the unit. I created a whole little espionage system with the unit, missions, buildings, wonders, yields, beliefs, policies, specialist functions, visibility, rumors, etc. and the AI can use the majority of it normally with no issue.
One thing that was important for all my mods was for them to be completely add-on and not mod any core files or require any modded DLL. This was to ensure the widest range of compatibility and usability. There are several things I could have easily coded and done better (especially AI) if I made a custom DLL (or even just used one of Whowards) but I felt that would've have locked out a lot of users.