In this case, I made a complete change to the auto battle logic; the auto identifier for spells is now directly in the spell selection and not in the menu.
When the MP reaches zero, auto mode is automatically disabled, and a popup appears on the screen.
At the end of each battle, the auto battle memories are reset.
I added a chase system for players to reposition themselves for enemies that are pushed too far away.