Refactor puppet agent in puppet::agent