changed DB agent code to take AS as first parameter to support Setup as AS
added more agent management code