DEV Community

Cover image for JADE: NEW ON JADE ? Create your FIRST agent while using your cmd PART 2.
NEEDTOCODEH24
NEEDTOCODEH24

Posted on

JADE: NEW ON JADE ? Create your FIRST agent while using your cmd PART 2.

level : Noob/New
Version : Windows 10
language : java 17.0.10 (jade Framework 4.6.0)

CREATING MY FIRST AGENT:

So, if you're new to the world of Multi-Agent Systems (MAS), we’ve got you. In this article, we’re going to take it step-by-step—and I mean CLEAR steps. Ugh, I know the struggle of doing something for the first time: repeating the same lines of code, scrolling through Google, jumping to ChatGPT... only to end up in what we call 'Event Spaghetti.' Tons of info, but none of it actually works (or at least not the way it should). It’s draining, and as developers, we’ve all been there.

GET TO THE POINT NOW, lets follow these steps one by one :

1: Open File Explorer on your computer.
2: In the address bar, go to the folder where your jade-bin-[version] is located.
3: Click on it
4: You'll see "lib folder" and normally in it you'll find jade (jar extension).
5: back to the jade folder.
6: Create a folder called "src" if it's not already there.
7: Click on it.
8: Create another folder dedicated for the package, name it whatever you want in our case "Modeles".
9: Click on it.
10: Create a .txt file and name it whatever you want this one is dedicated to your class.
11: Now, this is where things start to get interesting: head over to your CMD.
12: HIT

cd c:\Tools\JADE-bin-4.6.0\jade\src\modeles
Enter fullscreen mode Exit fullscreen mode

13: the path will change to this one
14: Remember, we created the class with a .txt extension earlier. Don’t forget to change it to .java in your CMD now, so it's ready to go!

ren NameOfYourClass.txt NameOfYourClass.java
Enter fullscreen mode Exit fullscreen mode

15: To make sure your class extension matches exactly what we need:

dir 
Enter fullscreen mode Exit fullscreen mode

You should see the contents of your current folder. Check the extensions if everything went well, you'll see your file there: NameOfYourClass.java.

16: Now, before doing anything else go back to your NameOfYourClass.java and lets start writing a small code, simple one for the test:

package modeles;
import jade.core.Agent;

plublic class NameOfYourClass extends Agent{
   protected void setup(){
      System.out.println("hi! My name is " + getLocalName());
                         }
}
Enter fullscreen mode Exit fullscreen mode

17: Once evrything is setup, you need to compile your java class:

cd .. 
javac -cp "..\lib\jade.jar" modeles\NameOFYourClass.java
Enter fullscreen mode Exit fullscreen mode

18: Once the compiling is done and a new command line appears, you're ready to create your first agents in the Main Container (the 'brain' of the platform). Since agents are all about being dynamic, you'll need to open another CMD window in parallel to host your simple container (second container in our case).

19: in your current CMD window, you'll create your first agents in the "mainContainer":

cd .. 
java -cp "lib\jade.jar;src" jade.Boot -gui -agents "NameOfYourAgent:modeles.NameOfYourClass"
Enter fullscreen mode Exit fullscreen mode

To create a bunch of them (3 agents in our case), use a ';' between each agent to separate them and avoid errors:

java -cp "lib\jade.jar;src" jade.Boot -gui -agents "Agent1:modeles.NameOfYouClass;Agent2:modeles.NameOfYouClass;Agent3:modeles.NameOfYouClass"
Enter fullscreen mode Exit fullscreen mode

Now, HIT Enter. You should see the messages from your agents popping up in the CMD window (the ones we wrote earlier in the class, like 'Hi, my name is agent1...). At the same time, the JADE RMA GUI (Remote Monitoring Agent) will appear.
Click on the 'AgentPlatform' folder, then on the key icon, and follow the hierarchy until you see your 3 agents sitting right next to the 3 main ones (df, ams, and rma).

20: Now, let’s head over to the next CMD window so we can create another simple container to hold our new agents:

cd c:\Tools\JADE-bin-4.6.0\jade 
java -cp "lib\jade.jar;src" jade.Boot -gui -container "Agent4:modeles.YourClassName"
Enter fullscreen mode Exit fullscreen mode

Hit Enter and you’ll see a message from your agent! Check the GUI and you'll see a new container popping up—that’s your second one, holding your 4th agent. CONGRATS, YOU MADE IT!

NOTE: Once you close your CMD windows, the GUI is gone too. If you want to jump back in, just pick your class and repeat steps 19 and 20, just make sure you're in the right path!:

cd c:\Tools\JADE-bin-4.6.0\jade  
Enter fullscreen mode Exit fullscreen mode

Now, you’re an expert at creating agents right from your CMD. HAVE FUN with your exam!

jade.Boot: the main class to start JADE.
-gui: opens the main jade GUI , including the rma (Remote Monitoring Agent).
-cp: class Path (tells where libraries are).

Top comments (0)