The only way your ever gonna stop the AI from mindlessly attacking you is to completely destroy them, just remember that every city you capture is one less place for them to recruit from and one more province they have to trek across to reach your important territories.