Move utility function from RPC to Agent domain.