Not what he's talking about, he's talking about this menu
It's a simple if-then-elseif list. It starts at the top, so if the first condition is true (my example, if self (this pet) has less than 10% MP) it will do that action (ranged attack). In my setup here I use this to prevent overcasting, as the shooting action will come before all of the later spellcasts if his mp is too low to cast.
If the first condition is false it will go on to the next condition, in this case "If you don't have contingency up cast contingency", then the next "if you already have contingency don't have auto guard, cast absolute protect", and so on. Because of the order it actually reads more like "If you don't have contingency AND have over (or equal) 10% mp, cast contingency", "if you don't have auto guard, but DO have contingency and more than 10% mana, cast absolute protect".
One thing I've noticed is that if an action is considered "impossible" the AI will skip it. If there are no enemies close enough to ranged attack, this AI might choose to cast a spell even if his MP is too low. I COULD work around that, but I consider that to be a particularly unlikely circumstance (since he should try to close distance long before he runs out of mana), so I just ignore it.
What you can take away from that though is to have a "catch all" at the bottom of the list. This is where "if distance > 1, move forward" comes in. This is more noticeable on ranged fighters (without all the spells), but basically it just means if you can't shoot your target (shoot=impossible), try getting closer.
I've generally found that pets don't want to shoot anything more than 5 tiles away even if their weapon or spell allows it, I think that might be a hard-coded limit, maybe to prevent NPCs from sniping you outside your vision.
Last, some more technical details, "preserve target" means to alwaysdo that action against the "entity", regardless of whether that makes sense. This can make pets attack themselves with certain abilities even if they really shouldn't be able to. To increase the number of slots available, increase the pet's Learning or your learning, the lower one of the two determines the limit.
First select it from the "teach a spell or ability" menu, then assign it to be used in the AI. Pets learn by doing, so just make him spam that new ability until he's got it down. When the progress is low he will fail to use it and then skip to the next part of the AI, so plan accordingly. Once it hits 100% he's mastered it and you can start on a new ability.