added new Agent code and a test function to main