There is an option: withdraw and fight another day
Not in the situation postulated which is a single unit of heavy infantry trapped defending a city against an army of horse archers.
Its a lose lose situation.
That unit can't win by chasing down the much faster horses but it also can't win by sitting there getting shot up.

I'd say probably the best the AI could do in that situation would be to have the defending unit attempt to hold the wall breach & go down in combat there.