Improved to be able to define agent name using external command.
(cherry picked from commit 22d72ed80c9006f5fee76b361d4195f1b20eab07)