The SPADE Agent Management System (AMS)

The SPADE AMS is our implementation of the standard FIPA AMS component to manage, identify and search for agents in the platform. It is a special platform agent that is always present in all SPADE platforms and that is started automatically whenever the platform is initiated. It manages the registration of the agents in the platform. So, when you start one of your agents and the registration process is autmatically taken care of by the SPADE Agent Library, it is the AMS who is on "the other side of the counter", managing the registry of agents. It also gets to de-register an agent once its life cycle has ended.

Additionally, the AMS offers some services that any agent inside the platform can use. First is the Platform Information service, a basic query that gives the agent some information regarding the platform. It can be invoked with the getPlatformInfo method of the agents. Let's see an example:

import spade

class MyAgent(spade.Agent.Agent):
	class MyBehav(spade.Behaviour.OneShotBehaviour):

		def _process(self):			
			pi = self.myAgent.getPlatformInfo()
			print "Platform Information: ", pi

	def _setup(self):
		print "MyAgent starting . . ."
		b = self.MyBehav()
		self.addBehaviour(b, None)

if __name__ == "__main__":
	a = MyAgent("agent@myhost.myprovider.com", "secret")
	a.start()
		
$ python agent.py
Agent: agent@myhost.myprovider.com registered correctly (inform)
Platform Information: (ap-description :name xmpp://acc.myhost.myprovider.com :ap-services 
(set (ap-service :name xmpp://ams.myhost.myprovider.com :type fipa.agent-management.ams 
:addresses (sequence acc.myhost.myprovider.com))
		

As you can see, the method returns the information collected from the AMS in the FIPA-SL semantic language (more on that later).

Agents can also use the Search Agent service. This service allows them to look for a fellow agent registered in the platform using some search criteria. In order to introduce those criteria, the class spade.AMS.AmsAgentDescription must be used. It represents some data fields that can be filled in with agent information: the name of the agent, its ownership and its state. Once an object of the spade.AMS.AmsAgentDescription class has been filled with the search criteria, you can use it with the searchAgent method of an agent:

import spade

class MyAgent(spade.Agent.Agent):
        class MyBehav(spade.Behaviour.OneShotBehaviour):
                def onStart(self):
                        print "Starting behaviour . . ."

                def _process(self):
                        print "I'm going to search for an agent"
                        aad = spade.AMS.AmsAgentDescription()
                        search = self.myAgent.searchAgent(aad)
                        print search

                def onEnd(self):
                        print "Ending behaviour . . ."

        def _setup(self):
                print "MyAgent starting . . ."
                b = self.MyBehav()
                self.addBehaviour(b, None)

if __name__ == "__main__":
        a = MyAgent("agent@myhost.myprovider.com", "secret")
        a.start()
		
((result  (set (ams-agent-description
:name (agent-identifier
:name ams.myhost.myprovider.com
:addresses 
(sequence
xmpp://ams.myhost.myprovider.com
)
)

:ownership SPADE
:state active)
 (ams-agent-description
:name (agent-identifier
:name df.myhost.myprovider.com
:addresses 
(sequence
xmpp://df.myhost.myprovider.com
)
)

:ownership SPADE
:state active)
 (ams-agent-description
:name (agent-identifier
:name agent@myhost.myprovider.com
:addresses 
(sequence
xmpp://agent@myhost.myprovider.com
)
)

:ownership agent@myhost.myprovider.com
)
 )))
		

Another service offered by the AMS is the Modify service. It allows for an agent to modify its own information, published in the AMS, in order to update it to reflect its current status or make it easier for other agents to find it. It can be invoked using the modifyAgent method of the agents and a spade.AMS.AmsAgentDescription object that includes the updated information of the agent:

import spade

class MyAgent(spade.Agent.Agent):
        class MyBehav(spade.Behaviour.OneShotBehaviour):
                def onStart(self):
                        print "Starting behaviour . . ."

                def _process(self):
                        print "I'm going to modify my data"
                        aad = spade.AMS.AmsAgentDescription()
                        aad.ownership = "FREE"
                        result = self.myAgent.modifyAgent(aad)
                        if result:
                                print "Modification OK"
                        print "I'm going to check the modification"
                        search = self.myAgent.searchAgent(aad)
                        print search

                def onEnd(self):
                        print "Ending behaviour . . ."

        def _setup(self):
                print "MyAgent starting . . ."
                b = self.MyBehav()
                self.addBehaviour(b, None)

if __name__ == "__main__":
        a = MyAgent("agent@myhost.myprovider.com", "secret")
        a.start()
		
$ python agent.py
Agent: agent@myhost.myprovider.com registered correctly (inform)
MyAgent starting . . .
Starting behaviour . . .
I'm going to modify my data
Modification OK
I'm going to check the modification
((result  (set (ams-agent-description
:name (agent-identifier
:name agent@myhost.myprovider.com
:addresses 
(sequence
xmpp://agent@myhost.myprovider.com
)
)

:ownership FREE
)
 )))