refactor agents