createAgent function added