Refactoring and adding unit tests for Agent to Worker messaging