Well... I would like to have that issue with AI not taking my cities. LOL.
Maybe it's a 'level' issue... bc in Deity the AI seems to be coming for my cities a lot... walls or not...
You can manipulate the AI into not attacking on deity, and it works pretty well once you game the system that way.
The AI generally attacks based on its military score relative to yours, as a proportion oh how much they're ahead in that score.
There is no hard and fast rule at which point they attack, but generally it seems to be when they are (at a minimum) about 3 times stronger in that department than you.
This is also influenced by what sort of leader you're dealing with (Gandhi usually won't invade until the scales tip far further, while Chandragupta doesn't take much convincing).
This is why I usually open slinger or warrior on deity, both as a way to get my military score up (less likely to be invaded by turn 10), and because it gives me the flexibility of having one more unit for attacking the AI
if I choose to go down that route later.
The thing with military score is that its also a deeply flawed system, as it basically just sums up the base combat strength of your units into a combined "military score".
This makes it easy to manipulate and abuse, because you cannot accurately represent the strength of an army by the sum of its units base combat strengths.
In civ 6, combat modifiers work exponentially and not additively.
For instance, a warrior has a base combat strength of 20, whereas a swordsman has a base combat strength of 35.
But since the game calculates military score by adding units together, the AI sees the military scores of 2x warriors as
40 (20+20), and thus as
stronger than a swordsman's
35 (which we all know isn't the case, as a single swordsman can plow through multiple warriors on his own).
This means that if you are trying to avoid getting invaded by a technologically superior AI, you can invest in a buch of cheap warriors (to get your military score up) and be relatively safe as long as you keep an eye on the score and dont drop below ~1/3 of the AIs combined military score relative to yours.
You can also use this in reverse, and bait a backwards AI into attacking you.
I had a game once where I played as Gitarja, and I had very few units apart from some rather high tech ones (cuirassiers, artillery and battleships), at about 300+ military score.
Meanwhile Trajan, who had about 1100 military score, decided it was a good idea to declare on me, even though his army consisted almost completely of legions and catapults.
Needless to say, his army got utterly massacred, in part due to how poorly the AI judged military strength when looking at military score as a basis for deciding to attack into cuirassiers, artillery and battleships with classical era tech.