Use the AINavigationModifier to prevent the AI from running into walls; the correct way is to enclose the entire cave (or a building, same principle) with a ForbiddenArea, and then drawing an AINavigationModifier enclosing all the areas the AI
can walk in. Add AIPoints inside the AINavigationModifier so the AI characters can navigate through the area.

The documentation goes through Forbidden Areas and Nav modifiers in great detail:
http://doc.crydev.net/SandboxManual/SimpleAI.html - although the AIPoint placement isn't optimal in the example pics (in the official docs!). Basically the AI can navigate within the NavigationModifier even without AIPoints, so you don't need to put them every meter or so. You should place an AIPoint at locations where the AI hasn't got a straight path from point A to B within the Nav modifier (for example corridor corners) so when the AI finds himself in a closed corner he always has a STRAIGHT unobstructed path to the nearest AIPoint.

A square room for example would only need AIPoints in the entrance and exit locations. From every corner of the room the AI can find a direct path to the entrance.