agent: refactoring logWriter out of the agent