refactored agent controller into a service class and added tests to wrap it [#6]