Code cleanup in agent.cpp