refactor plugin and agent API

Change-Id: Iab77428bcf159110f743368cf72b02fff931040f