If the AI really 'wants/needs' to take a particular city, Armies will always be attacked if they are the top defender, regardless of stats.
Out in the field, though, "it depends" on relative A/D values and HP remaining.
Basically, the AI won't attack an Army (or any unit) directly, if it 'thinks' that its best attacking unit's probability of victory is insufficiently 'high'. While I have not conducted any systematic tests, just from having watched what the AI does under various circumstances, I would estimate that the threshold at which the AI decides that an attack is worthwhile, is ~10% probability of winning all possible combat-rounds.
That is, the AI generally avoids attacking Armies, because it is comparing each potential attacker's strength to that of the Army on an individual basis, and finding each potential attacker too 'weak' due to the Army's usually very high HP. It does not understand that it would likely kill the Army if it threw multiple units at the Army, one after the other.
(When a large stack of units also includes bombard-capable units, the AI will similarly also tend to send its attackers past the stack to go after a 'softer' target(s), rather than attacking the stack directly)
Conversely, if the AI can build and use its own Armies or other high-HP units (e.g. if running the Flintlock patch, or a mod containing individual units which have +6-8 bonus-HP), it will use those to attack enemy Armies.
And when an Army has been badly injured, it will also become fair game for attacks by individual (low-HP) units — and if those attackers have M=2 or more, the Army will also be unable to retreat.
Some examples from my past games:
AI-controlled ACavs (which have +1 HP by default, so an eACav has 6 HP) will attack reasonably healthy (green-yellow HP-bar) Berserk-Armies.
AI-controlled Cavalries will attack badly-damaged (red HP-bar) Infantry Armies — including one memorable instance where Khan used a stack of 20+ Ironclads to bomb my 3-vet-Inf-Army — fortified in a Barricaded Fortress, blocking a 1-tile land-bridge to his section of the Continent — down to 1 HP, before sending in his Cavs to kill it (which were then trapped in the Barricade, so became easy pickings for all my Arty + Cavs(?) during the following turn).
If not defended by mobile AA-capable units (and sometimes even when they are!), Armies will also be preferentially targeted by AI-Bombers (and by bombard-capable land-units, if running the Flintlock patch)
And I played one game (Player1 Fanatic's tweak-mod, Large 70% Archi, as the Celts, IIRC) where, during a Modern-Age war towards Domination, Cathy abandoned the AI's usual "No First Use" policy to nuke my stacked MechInf-Armies, apparently because she was losing so badly.