Core refactoring + Prepare agent layer