Fixing utils.defer that notify can be immediately used in non async functions
and protect function with capture try/catch.
Refactoring structure agent.
Refactoring connection between agent cmd and agent client.