Have you looked at how vanilla animals (e.g. pig or sheep) do it?
Mob entities (which include animals) have goals, which are registered and run by the entity's GoalSelector object. Every mob entity has a goal selector, which is public, and the goal selector has a getRunningGoals() method to get all of the currently-active goals. Take a look at e.g. PigEntity and find the obviously-named goal which controls panic behaviour. That should be all the info you need.
It might actually be simpler just to check that the animal has a non-null getRevengeTarget()... depends on how much control you want over the process. An animal can have a revenge target but not have a running panic goal if it can't find somewhere to flee to, for example.