/*
---------------- ------------------- CREATE AGENT -------------------
----------------
777912
function createAgent (appname, masterSpec, moduleSpec, cb) {
  fs.mkdir(path.join(path.resolve(appname), 'generated', 'agents', moduleSpec.name), function (response) {
    createTemplate(appname, path.join('generated', 'agents', 'agentModule.js'), {
      moduleName: moduleSpec.name,
      states: moduleSpec.states
    })

    var oldPath = path.join(appname, 'generated', 'agents', 'agentModule.js'),
      newPath = path.join(appname, 'generated', 'agents', moduleSpec.name, moduleSpec.name + '.js')
    fs.renameSync(oldPath, newPath)

    // CREATE THE AGENT MAIN CONTROLLER
    fs.mkdir(path.join(path.resolve(appname), 'generated', 'agents', moduleSpec.name, 'controllers'), function (response) {
      createTemplate(appname, path.join('generated', 'agents', 'agentMasterController.js'), {
        moduleName: moduleSpec.name,
        actions: moduleSpec.actions,
        states: moduleSpec.states
      })
      var oldControllerPath = path.join(appname, 'generated', 'agents', 'agentMasterController.js'),
        newControllerPath = path.join(appname, 'generated', 'agents', moduleSpec.name, 'controllers', moduleSpec.name + '.js')
      fs.renameSync(oldControllerPath, newControllerPath)

      // CREATE THE MODULE INIT STATE CONTROLLER AND PARTIAL
      fs.mkdir(path.join(path.resolve(appname), 'generated', 'partials', 'agents', moduleSpec.name), function (response) {
        createTemplate(appname, path.join('generated', 'index.html'), {})

        var oldHtmlPath = path.join(appname, 'generated', 'index.html'),
          newHtmlPath = path.join(appname, 'generated', 'partials', 'agents', moduleSpec.name, 'index.html')
        fs.renameSync(oldHtmlPath, newHtmlPath)

        if (moduleSpec.actions.elements) {
          for (childState in moduleSpec.actions.elements) {
            var state = {
              title: moduleSpec.actions.elements[childState].ui.title,
              components: moduleSpec.actions.elements.init.components,
              initConversation: true
            }
            createAgentChildState(appname, moduleSpec.name, moduleSpec.actions.elements[childState], '', moduleSpec.actions.url)
          }
        }
        // CREATE THE MODULE CHILD STATES
        if (moduleSpec.states) {
          for (var i = moduleSpec.states.length - 1; i >= 0; i--) {
            moduleSpec.states[i] = translateUiTitles(moduleSpec.states[i])
            createAgentState(appname, moduleSpec.name, moduleSpec.states[i], moduleSpec.actions.url)
          }
        }
        moduleSpec.actions.elements = translateUiTitles(moduleSpec.actions.elements)
        fs.mkdir(path.join(path.resolve(appname), 'generated', 'agents', moduleSpec.name, 'services'), function (response) {
          createTemplate(appname, path.join('generated', 'agents', 'agentServices.js'), {
            moduleName: moduleSpec.name,
            actions: moduleSpec.actions,
            states: moduleSpec.states,
            agentSpec: masterSpec.agents
          })
          var oldServicePath = path.join(appname, 'generated', 'agents', 'agentServices.js'),
            newServicePath = path.join(appname, 'generated', 'agents', moduleSpec.name, 'services', moduleSpec.name + 'Services.js')
          fs.renameSync(oldServicePath, newServicePath)
          cb()
        })
      })
    })
  })
}
343272
public void destroyAgent (AgentObject agent)
    {
        FoundAgent found = resolve(null, agent.getOid(), "destroyAgent");
        if (found == null) {
            return;
        }

        log.info("Destroying agent", "agent", agent.which());

        // transition the agent to a new state and perform the effect of the transition
        if (found.state == AgentState.PENDING) {
            found.bureau.agentStates.remove(found.agent);
            _omgr.destroyObject(found.agent.getOid());

        } else if (found.state == AgentState.STARTED) {
            found.bureau.agentStates.put(found.agent, AgentState.STILL_BORN);

        } else if (found.state == AgentState.RUNNING) {
            // TODO: have a timeout for this in case the client is misbehaving or hung
            BureauSender.destroyAgent(found.bureau.clientObj, agent.getOid());
            found.bureau.agentStates.put(found.agent, AgentState.DESTROYED);

        } else if (found.state == AgentState.DESTROYED ||
            found.state == AgentState.STILL_BORN) {
            log.warning("Ignoring request to destroy agent in unexpected state",
                        "state", found.state, "agent", found.agent.which());
        }

        found.bureau.summarize();
    }
440487
public static void applyUserAgent(String agent) {
    LOGGER.info("Applying agent: " + agent);
    System.setProperty("http.agent", agent);
    System.setProperty("https.agent", agent);
  }
1219758
def make_agent(
    agent_type, env, policy_hparams, policy_dir, sampling_temp,
    sim_env_kwargs_fn=None, frame_stack_size=None, rollout_agent_type=None,
    batch_size=None, inner_batch_size=None, env_type=None, **planner_kwargs
):
  """"""
  if batch_size is None:
    batch_size = env.batch_size
  return {
      "random": lambda: rl_utils.RandomAgent(  # pylint: disable=g-long-lambda
          batch_size, env.observation_space, env.action_space
      ),
      "policy": lambda: rl_utils.PolicyAgent(  # pylint: disable=g-long-lambda
          batch_size, env.observation_space, env.action_space,
          policy_hparams, policy_dir, sampling_temp
      ),
      "planner": lambda: rl_utils.PlannerAgent(  # pylint: disable=g-long-lambda
          batch_size, make_agent(
              rollout_agent_type, env, policy_hparams, policy_dir,
              sampling_temp, batch_size=inner_batch_size
          ), make_env(env_type, env.env, sim_env_kwargs_fn()),
          lambda env: rl_utils.BatchStackWrapper(env, frame_stack_size),
          discount_factor=policy_hparams.gae_gamma, **planner_kwargs
      ),
  }[agent_type]()
749553
protected void init() {
		getMobileUserAgentPrefixes().addAll(
				Arrays.asList(KNOWN_MOBILE_USER_AGENT_PREFIXES));
		getMobileUserAgentKeywords().addAll(
				Arrays.asList(KNOWN_MOBILE_USER_AGENT_KEYWORDS));
		getTabletUserAgentKeywords().addAll(
				Arrays.asList(KNOWN_TABLET_USER_AGENT_KEYWORDS));
	}
367474
void initialize() throws ManagerCommunicationException
    {
        ResponseEvents re;

        re = server.sendEventGeneratingAction(new AgentsAction());

        for (ManagerEvent event : re.getEvents())
        {
            if (event instanceof AgentsEvent)
            {
                logger.info( event );
                handleAgentsEvent((AgentsEvent) event);
            }
        }
    }
300571
private CreateRoomSettings createRoomSettings(ApiRoom agent) {
        validateRoomAgentClass(agent);
	    CreateRoomSettings settings = new CreateRoomSettings();
        settings.setName(agent.getName());
        settings.setPassword(agent.getPassword());
        settings.setDynamic(agent.isDynamic());
        settings.setGame(agent.isGame());
        settings.setHidden(agent.isHidden());
        settings.setMaxSpectators(agent.getMaxSpectators());
        settings.setMaxUsers(agent.getMaxUsers());
        settings.setMaxVariablesAllowed(agent.getMaxRoomVariablesAllowed());
        settings.setRoomProperties(agent.getProperties());
        settings.setGroupId(agent.getGroupdId());
        settings.setUseWordsFilter(agent.isUseWordsFilter());
        settings.setAutoRemoveMode(SFSRoomRemoveMode.fromString(agent.getRemoveMode().name()));
        if(agent.getExtension() != null) 
            settings.setExtension(new RoomExtensionSettings(agent.getExtension().getName(), agent.getExtension().getClazz()));
        return settings;
	}
1287496
public void setup() {

        LogActivator.logToFile(logger, this.getName(), Level.ALL);

        // Add the agent to the introspector and obtain the introspector
        // instance.
        introspector = JadeAgentIntrospector.getMyInstance(this);
        logger.fine("Agent " + this.getLocalName()
                + " added to the Intrsopector");

        try {
            this.myMockConfiguration = (MockConfiguration) this.getArguments()[0];
        } catch (Exception e) {
            logger.warning("There was an error reading the BridgeMockAgent configuration.");
            logger.fine("The stack trace: \n" + e.getStackTrace());
            // TODO think about implement this exception or not.
            // throw new BadConfigurationException();
            throw new IllegalArgumentException(
                    "The mock agent didn't receive a configuration"
                            + " object. The first argument have to be a MockConfiguration object");
        }

        // Initialize the believes counts and the mailbox list. 
//        introspector.storeBeliefValue(this, Definitions.RECEIVED_MESSAGE_COUNT, 0);
//        introspector.storeBeliefValue(this, Definitions.SENDED_MESSAGE_COUNT, 0);
        this.mailbox = new ArrayList<ACLMessage>();

        // Attemps to register the aggent.
        boolean register = false;
        for (int i = 0; !register; i++) {
            try {
                AgentRegistration.registerAgent(this,
                        myMockConfiguration.getDFservice(),
                        Definitions.BRIDGE_SERVICE_TYPE);
                // TODO Service_Type could be a custom field of
                // MockCondiguration.
                register = true;
            } catch (FIPAException e) {
                logger.warning("Exception while registering the RespositoryMockAgent");
            }
            if (i >= Definitions.REG_ATTEMPTS) {
                break;
                // TODO check if is necessary to implement this exception.
                // throw new
                // UnableToRegisterException(e.getStackTrace().toString());
            }
        }

        // Adds the behavior that listen for incoming messages.
        addBehaviour(new Listen(this));
    }
736914
protected void createAgentNameEditor(Composite parent, String text) {
		final Group group = SWTFactory.createGroup(parent, text, 2, 1, GridData.FILL_HORIZONTAL);
		this.agentNameTextField = SWTFactory.createSingleText(group, 1);
		this.agentNameTextField.addModifyListener(new ModifyListener() {
			@SuppressWarnings("synthetic-access")
			@Override
			public void modifyText(ModifyEvent event) {
				SARLAgentMainLaunchConfigurationTab.this.lastAgentNameError = null;
				updateLaunchConfigurationDialog();
			}
		});
		ControlAccessibleListener.addListener(this.agentNameTextField, group.getText());
		this.agentNameSearchButton = createPushButton(group, Messages.MainLaunchConfigurationTab_1, null);
		this.agentNameSearchButton.addSelectionListener(new SelectionListener() {
			@Override
			public void widgetDefaultSelected(SelectionEvent event) {
				//
			}

			@Override
			public void widgetSelected(SelectionEvent event) {
				handleAgentNameSearchButtonSelected();
			}
		});
	}
219581
public void setup() {
		this.myIntrospector = JadeAgentIntrospector.getMyInstance((Agent) this);
		LogActivator.logToFile(logger, this.getName(), Level.ALL);
		// Register the service
		try {
			DFAgentDescription dfd = new DFAgentDescription();
			ServiceDescription sd = new ServiceDescription();
	        
	        sd.setType("server");
	        sd.setName("report-service");
	        // Sets the agent description
	        dfd.setName(this.getAID());
	        dfd.addServices(sd);
	        
	        // Register the agent
	        DFService.register(this, dfd);
			
		} catch (Exception e) {
			logger.severe("Exception registering agent in DF. Agent: " + this.getName());
		}

		MessageTemplate t = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
		addBehaviour(new ReportServer(this,t));
	}
350052
@SuppressWarnings("unchecked")
    @Override
    public Boolean execute() {
        for(int i = 0 ; i < agents.length ; i++) {
            createRoom(i);
        }
        return Boolean.TRUE;
    }
105408
static byte[] generateAgentJson(String agent, long coreId, long channelId) throws Exception {
        String id = paddedHex(coreId) + "/" + paddedHex(channelId);
        if (agent.length() > 200) {
            agent = agent.substring(0, 200);
        }

        HashMap<String, String> result = new HashMap<String, String>();
        result.put("a", agent);
        result.put("i", id);
        return DefaultObjectMapper.writeValueAsBytes(result);
    }
1334015
private static void attachAgent(Class<?> vmClass, URL agentJarURL) throws Exception {
        String pid = getPID();
        String agentAbsolutePath = new File(agentJarURL.toURI().getSchemeSpecificPart()).getAbsolutePath();

        Object vm = getAttachMethod(vmClass).invoke(null, new Object[] { pid });
        getLoadAgentMethod(vmClass).invoke(vm, new Object[] { agentAbsolutePath });
        getDetachMethod(vmClass).invoke(vm);
    }
532438
public function setAgent(AgentContract $agent = null)
    {
        if (!$agent) {
            $agent = new Agents\SystemAgent();
        }

        $this->agent = $agent;

        return $this;
    }
926463
void handleAgentsEvent(AgentsEvent event)
    {
        AsteriskAgentImpl agent = new AsteriskAgentImpl(server,
                event.getName(), "Agent/" + event.getAgent(), AgentState.valueOf(event.getStatus()));
        logger.info("Adding agent " + agent.getName() + "(" + agent.getAgentId() + ")");

        addAgent(agent);
    }
574390
void handleAgentCallbackLoginEvent(AgentCallbackLoginEvent event)
    {
        AsteriskAgentImpl agent = getAgentByAgentId("Agent/" + event.getAgent());
        if (agent == null)
        {
            synchronized (agents)
            {
                logger.error("Ignored AgentCallbackLoginEvent for unknown agent "
                                + event.getAgent() + ". Agents: " + agents.values().toString());

            }
            return;
        }
        agent.updateState(AgentState.AGENT_IDLE);
    }
1317866
function onRAgentCreated(agentInfo) {
    DEBUG("ragentCreated", utils.JS(agentInfo))
    var ragent = agents.createRAgent(session, agentInfo)

    session._ragents.set(agentInfo.id, ragent)
    session.emit("ragentCreated", ragent)
  }