DEV Community

vishalmysore
vishalmysore

Posted on • Edited on

Agentic Frameworks in Java with JADE

Overview
In this article, I will discuss the concepts of AI and AGI, and explore how to build a multi-agent system using an Agentic Framework built on top of Tools4AI & JADE, based on the IEEE FIPA (Foundation for Intelligent Physical Agents) specification, which provides standards for agent communication and interoperability. Additionally, I will provide hands-on code and examples to help you implement these concepts in practice.

Two agents, OpenAIAgent and GeminiAIAgent, will communicate with each other on various topics such as life philosophy, sports, and more, utilizing open FIPA standards.

Enjoy!

Code for this article is here

What is AGI?
AGI stands for Artificial General Intelligence, which refers to a type of artificial intelligence that possesses the ability to understand, learn, and apply knowledge in a wide variety of tasks at a human level of intelligence. Unlike narrow AI, which is designed to perform specific tasks (like playing chess or recognizing faces), AGI would be capable of performing any intellectual task that a human can do, including reasoning, problem-solving, abstract thinking, and learning across domains without being explicitly programmed for each one

All current AI systems are considered narrow AI, which means they are designed to perform specific tasks, often at a high level of efficiency, but they lack the ability to transfer their knowledge across different tasks or domains.

What is Narrow AI?
Most AI models today are built to handle specific tasks within a narrow domain of knowledge. For example:

AlphaGo is excellent at playing the game of Go but knows nothing about playing chess.
GPT-4 can generate text based on a prompt, but it can’t drive a car or make decisions in the stock market without being explicitly trained in those tasks.
This specialization means that these systems don’t have a generalized understanding of the world and can’t apply their learned knowledge outside of their narrow domain

Transfer learning and generalized learning are two important concepts in AI that describe different approaches to how an AI system handles knowledge across tasks and domains. They both deal with applying knowledge learned in one setting to another, but they differ in terms of scope and implementation.

Transfer learning helps AI systems perform new tasks with minimal retraining by leveraging knowledge from related tasks. It’s highly efficient for domain-specific applications but remains task-specific.

Generalized learning, on the other hand, enables AI systems to apply their knowledge across a wide range of tasks without additional retraining, and is essential for achieving true AGI, where an AI can adapt and solve new problems in different domains.

So What is AGI anyways?

In simple terms “A system can be termed as AGI when it can use knowledge from one domain in another.” Just because a system knows how to play chess, Go, Snakes and Ladders, or several other games does not make it AGI. What makes it AGI is if it can use the knowledge learned from all those games to successfully learn a new game by itself. Yes, it’s dangerous, but that’s what it is.

Can I build AGI using multiple agents working in tandem?

No, multiple AI agents working together would not be considered AGI by themselves. While you can have multiple specialized AI agents, each excelling in specific tasks (like playing different games or performing different functions), AGI refers to a single system or entity capable of generalizing knowledge across domains and autonomously learning new tasks without specialized training for each one.

In other words, AGI is about unified intelligence in a single system that can adapt to and solve a broad range of problems. Just combining multiple specialized AIs wouldn’t make them AGI; they’d still be individually limited to their specific tasks. AGI implies a single intelligence that can handle tasks across various domains without needing to be reprogrammed or retrained for each one.

So How Can I build an AGI system?

You can create multi-agent systems using Java. While these agents wouldn’t be AGI, MAS architectures can simulate intelligent, adaptive behaviors by allowing agents to communicate and learn together.

JADE (Java Agent DEvelopment Framework) is a well-known framework for creating multi-agent systems.
You can create agents that simulate intelligent behavior in various environments, including cooperation, learning, and adaptation.
What is Jade?
JADE (Java Agent DEvelopment Framework) provides a framework for building multi-agent systems compliant with FIPA (Foundation for Intelligent Physical Agents) standards. JADE supports building complex, interoperable agent-based applications, particularly for environments requiring distributed, intelligent behavior.

I have created sample project on how to use Jade with Multi Agent system here

Example 1 : In this simple example I have created a senderagent and receiver agent they communicate using OneShotBehavior

Sender Agent

protected void setup() {
        log.info("Hello! Agent " + getLocalName() + " is ready.");

        addBehaviour(new OneShotBehaviour() {
            /**
             * The action method is called when the behaviour is executed.
             * It creates a new ACLMessage, sets the receiver and content, and sends the message.
             */
            public void action() {
                ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
                msg.addReceiver(new AID("ReceiverAgent", AID.ISLOCALNAME));
                msg.setContent("Hello from HelloAgent!");
                send(msg);
                log.info("Message sent: " + msg.getContent());
            }
        });
    }
Enter fullscreen mode Exit fullscreen mode

Receiver Agent

 protected void setup() {
        log.info("ReceiverAgent " + getLocalName() + " is ready.");

        addBehaviour(new Behaviour() {
            boolean messageReceived = false;
            /**
             * The action method is called when the behaviour is executed.
             * It checks for an incoming message and prints it if one is received.
             */
            public void action() {
                ACLMessage msg = receive();
                if (msg != null) {
                    log.info("Message received: " + msg.getContent());
                    messageReceived = true;
                } else {
                    block();
                }
            }
            /
Enter fullscreen mode Exit fullscreen mode

Once you execute the program you can see the agents running in Jade GUI

Image description

As you can see from the example the behaviour we used was OneShotBehavior . It is a type of behavior that performs its task once and then terminates, while the custom subclass of Behaviour used in ReceiverAgent continues to check for incoming messages until a message is received.

Slight Detour Starts

Some of the other Behaviour in Jade are

Behaviour: This is the base class for all behaviours in JADE. It provides the basic structure and methods that all behaviours must have.
SimpleBehaviour: This is a direct subclass of Behaviour and provides a simple, straightforward implementation of a behaviour. It continues to execute until its done() method returns true.
OneShotBehaviour: This is a behaviour that performs its task once and then terminates. It’s a subclass of SimpleBehaviour.
CyclicBehaviour: This is a behaviour that performs its task in a loop. It’s also a subclass of SimpleBehaviour.
TickerBehaviour: This is a behaviour that performs its task at regular intervals. It’s a subclass of Behaviour.
WakerBehaviour: This is a behaviour that performs its task once after a specified delay. It’s a subclass of Behaviour.
SequentialBehaviour **and ParallelBehaviour: These are composite behaviours that allow you to group multiple behaviours together and execute them either sequentially or in parallel.
**FSMBehaviour
: This is a behaviour that allows you to define a finite state machine. It’s a subclass of Behaviour.

Jade is not JMS
Purpose: JADE is a software framework to develop agent-based systems. An agent in JADE can send and receive messages, and has behaviors that define its actions. JMS, on the other hand, is a Java API for sending and receiving messages between two or more clients. It is not tied to the concept of agents and behaviors.

Communication Model: JADE uses an agent communication model, where each agent can send messages to other agents directly. JMS uses a messaging model, where messages are sent to a queue or topic, and then received by one or more consumers.

Message Delivery: In JADE, message delivery is asynchronous and non-blocking. Agents do not wait for a response after sending a message. In JMS, both synchronous and asynchronous message delivery is possible.

Interoperability: JADE is FIPA-compliant, which means it follows the standards set by the Foundation for Intelligent Physical Agents for interoperable intelligent multi-agent systems. JMS is a part of the Java EE platform, and it can interoperate with any system that supports JMS.

Complexity: JADE is more complex than JMS as it involves concepts like agents, behaviors, and ontologies. JMS is simpler and only involves concepts like messages, queues, and topics.

Slight Detour Ends

*Example 2 *: In this example both the agents will talk to each other continuously using CyclicBehaviour

You can execute the examples using this command

java -cp jade-4.5.0.jar;target/classes jade.Boot -gui LoopSenderAgent:io.github.vishalmysore.loop.LoopSenderAgent;LoopReceiverAgent:io.github.vishalmysore.loop.LoopReceiverAgent
Enter fullscreen mode Exit fullscreen mode

Example 3 : OpenAiAgent and GeminiAiAgent Discussion

To Execute

java -cp jade-4.5.0.jar;target/af4j-1.0-SNAPSHOT-jar-with-dependencies.jar jade.Boot -g

Future
In the current setup, the OpenAiAgent and GeminiAiAgent are communicating with each other, exchanging messages. This is a simple example of how multi-agent systems can interact. In more complex scenarios, these agents could indeed work together to solve more complex problems. For example, one agent could be specialized in image processing and could analyze an image and inform the other agent about its findings. The other agent, based on this information, could take appropriate actions. Furthermore, in an even more advanced setup, one agent could pass on its learnings or state to another agent, which could then use this information to make decisions or take actions. This is a concept known as cooperative learning or collaborative multi-agent systems.

Some other ideas could be .

  1. Knowledge Sharing Through Messages: Agents can share information or results, but not the actual “learning” process. For example, if one agent is trained to recognize objects in images, it can send the recognized objects to another agent that might act based on those results. This is not a transfer of learning, but a sharing of knowledge or conclusions.

Example:

Agent A (image processing) sends a message: “This image contains a car.”
Agent B (decision-making) receives the message and decides to alert the user or take an action.

  1. Collaborative Learning: In more advanced setups, especially in multi-agent reinforcement learning (MARL) or federated learning, agents can collaboratively learn by sharing their experiences or gradients (in the case of neural networks). This allows one agent to benefit from the learning or experiences of others.

Federated Learning: Agents train locally and periodically share updates (gradients) with a central model or directly with other agents. The other agents use these updates to improve their own models.
Reinforcement Learning: Agents share learned policies or strategies with each other to improve their performance collectively.

  1. Transfer Learning in Multi-Agent Systems: While traditional MAS platforms like JADE are not designed for transferring deep learning models between agents, this concept could be applied in setups where agents are embedded with machine learning models. One agent could “train” a model, and the parameters of that model could be shared with another agent, which then uses the model to continue learning or making decisions.

Example in a Neural Network Context:

Agent A is trained on a task (e.g., image classification).
The trained model weights are shared with Agent B, which adapts the model to a related task (e.g., video classification).
This would be akin to transfer learning but within a multi-agent framework.

  1. Shared Memory or Distributed Learning: In some advanced systems, agents might share a common memory or knowledge base (like a database or distributed system). Each agent writes its learned outcomes or conclusions to this shared memory, and others read and apply it. This is more about sharing knowledge rather than direct transfer of a learning process.

Thank you for being with me so far. This is an evolving field, and it’s exciting to see how future developments will unfold. Let’s continue to stay informed and adapt as new advancements emerge.

Top comments (0)