Refactor Agent class

Move error-message formatting code to separate error modules