agent self upgrade refactor[unfinished]

agent self upgrade refactor[unfinished]