[agent] make toJSON resialiant to circular refs
[agent] refactor Search