refactor agent