title: How to pass Agent as argument
body: <p>How it is possible to Pass agent as argument to another agent?
  I know that we should pass arguments as an Object to <code>createNewAgent</code> method But I don't know how to retrieve recently created agent which exists in agent controller.</p>
  <pre><code>/**
   * create Three Collector agents
   */
  private void _createCollectorAgent(AgentContainer agentContainer, AgentController[] controller, Map&lt;String, String&gt; agentNames, GUI gui) {
      try {
          Object[] arg = new Object[1];
          arg[0] = gui;
  
          for (int i = 0; i &lt;= 2; i++) {
              controller[i] = agentContainer.createNewAgent(agentNames.get(String.format(&quot;CollectorAgent%d&quot;, i)), CollectorAgent.class.getName(), arg);
              controller[i].start();
          }
      } catch (StaleProxyException e) {
          e.printStackTrace();
      }
  }
  
  private void _createSearcherAgent(AgentContainer agentContainer, AgentController[] controller, Map&lt;String, String&gt; agentNames, GUI gui) {
      try {
  
          List&lt;AID&gt; lstCollectors = new ArrayList&lt;&gt;(3);
          lstCollectors.add( ?);//How get recently created agent inorder to pass in argument
          lstCollectors.add( ?);
          lstCollectors.add( ?);
          Object[] args = new Object[2];
          args[0] = gui;
          args[1] = lstCollectors;
          controller[3] = agentContainer.createNewAgent(agentNames.get(&quot;SearcherAgent&quot;), SearcherAgent.class.getName(), args);
          controller[3].start();
      } catch (StaleProxyException e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>
  <p>And here is Searcher Agent which needs argument:</p>
  <pre><code>public class SearcherAgent extends Agent implements AgentEntity {
  
      @Override
      protected void setup() {
          super.setup();
          System.out.println(&quot;Setup of SearcherAgent called &quot;);
          GUI gui = (GUI) getArguments()[0];
          AID[] lstCollectors= (AID[]) getArguments()[1];//Here is Ok 
          addBehaviour(new SearchingBehaviour(this, 1000,gui,lstCollectors));
      }
  
  }
  </code></pre>