move upgrade logic to agent