refactoring factory for agent