how to prevent AI agent failures