agent: adjusted tags file reading/writing strategy and fixed tests