This is not a new question. You're basically talking about automated intrusion detection and automated prevention. This has been around for some time.
What should AI do if it detects an attack? Depends on the environment and what your risks are. Typically, there are systems that can shut down a connection, isolate a system, force a user to go through additional confirmation etc.
It may, for example, terminate a high risk process and require human approval for it to start again.
This is not a new problem and is far from insurmountable. It comes down to defining what actions you want ahead of time.