refactor the AI role-judgment mechanism by haveatry823