Agent refactoring