I'm afraid you can't shutdown newrelic agent here, as if the rake task depends on another rake task, agent will be shutdown when another rake task finished