Before new mail agent and mail rules

Rules in mail-db and before new mail agents both are triggered by the router task. When I have a rule and an agent, which act first?

Regards

Wolfgang