public void initAg(String[] args) throws JasonException {
        // create a logger
        RunCentralisedMAS.setupLogger();
        logger = Logger.getLogger(SaciAgArch.class.getName() + "." + getAgName());

        // create the jasonId console
        if (MASConsoleGUI.hasConsole()) { // the logger created the MASConsole
            MASConsoleGUI.get().setTitle("MAS Console - " + getSociety());
            MASConsoleGUI.get().setAsDefaultOut();
        }

        // set the agent class
        try {
            String archClassName = null;
            if (args.length < 1) { // error
                throw new JasonException("The Agent Architecture class name was not informed for the SaciAgArch creation!");
            } else {
                archClassName = args[0].trim();
            }

            String agClassName = null;
            if (args.length < 2) { // error
                throw new JasonException("The Agent class name was not informed for the CentralisedAgArch creation!");
            } else {
                agClassName = args[1].trim();
            }

            // parse bb class
            mas2j parser = new mas2j(new StringReader(args[2].replace('$','\"')));
            ClassParameters bbPars = parser.classDef();
            
            // TODO: get and register user directives

            String asSource = null;
            if (args.length < 3) { // error
                throw new JasonException("The AgentSpeak source file was not informed, cannot create the Agent!");
            } else {
                asSource = args[3].trim();
            }
            Settings stts = new Settings();
            if (args.length > 4) {
                if (args[4].equals("options")) {
                    stts.setOptions("[" + args[5] + "]");
                }
            }
            userAgArch = (AgArch) Class.forName(archClassName).newInstance();
            userAgArch.setArchInfraTier(this);
            userAgArch.initAg(agClassName, bbPars, asSource, stts);
            logger.setLevel(userAgArch.getTS().getSettings().logLevel());
        } catch (Exception e) {
            running = false;
            throw new JasonException("as2j: error creating the agent class! - " + e.getMessage());
        }

        // enter in the Environment society
        try {
            Config c = new Config();
            c.set("society.name", getMBox().getSociety() + "-env");
            mboxPercept = new MBoxSAg(getMBox().getName(), c);
            mboxPercept.init();
            mboxPercept.setMboxChangedListener(new MBoxChangedListener() {
                public void mboxChanged() {
                    wake();
                }
            });

            mboxPercept.addMessageHandler("performCycle", "tell", null, "AS-ExecControl", new MessageHandler() {
                public boolean processMessage(saci.Message m) {
                    int cycle = Integer.parseInt(m.get("cycle").toString());
                    userAgArch.setCycleNumber(cycle);
                    //userAgArch.getTS().receiveSyncSignal();
                    receiveSyncSignal();
                    return true; // no other message handler gives this message
                }
            });

            //final Transformer stateSerializer = TransformerFactory.newInstance().newTransformer();
            mboxPercept.addMessageHandler("agState", "ask", null, "AS-ExecControl", new MessageHandler() {
                public boolean processMessage(saci.Message m) {
                    saci.Message r = new saci.Message("(tell)");
                    r.put("receiver", m.get("sender"));
                    r.put("in-reply-to", m.get("reply-with"));
                    r.put("ontology", m.get("ontology"));

                    try {
                        Document agStateDoc = userAgArch.getTS().getAg().getAgState();

                        // serialize
                        // StringWriter so = new StringWriter();
                        // stateSerializer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
                        // stateSerializer.transform(new DOMSource(agStateDoc),
                        // new StreamResult(so));
                        // r.put("content", so.toString());
                        r.putWithoutSerialization("content", agStateDoc);

                        mboxPercept.sendMsg(r);
                    } catch (Exception e) {
                        logger.log(Level.SEVERE, "Error sending message " + r, e);
                    }
                    return true; // no other message handler gives this message
                }
            });

            getMBox().setMboxChangedListener(new MBoxChangedListener() {
                public void mboxChanged() {
                    wake();
                }
            });

        } catch (Exception e) {
            logger.log(Level.SEVERE, "Error entering the environment's society.", e);
        }
    }