Source refactoring & change logic to get Agent ID