.gm on saves from your last use. You would have to do .gm on and then .gm off to get them hostile again even though your not actually GM flagged in chat.
AI_Agents work fine as far as I am aware... You probably have it set up wrong, take a look at the default WhyDB npc's with AI agent scripts.
A Lua script is fine, but when you have hundreds of them it can put quite a load on the server.