Re: [spade-users] Agent Communication: Sending and Receiving Messages doesn't work

106 views
Skip to first unread message
Message has been deleted

Markus Schatten

unread,
Dec 1, 2016, 4:19:39 AM12/1/16
to spade...@googlegroups.com
Hello!

Yes, the example is missing an additional instance of behaviour, e.g. something like:

ab = self.AnotherBehav()

Hope this helps!

Best,

M.



--
Markus Schatten, PhD
Assistant professor and head of Artificial Intelligence Lab
University of Zagreb
Faculty of Organization and Informatics
Pavlinska 2, 42000 Varazdin, Croatia
http://www.foi.hr/nastavnici/schatten.markus/index.html
http://www.researchgate.net/profile/Markus_Schatten1
http://ai.foi.hr

On Thu, Dec 1, 2016 at 8:04 AM, salima <mnifs...@gmail.com> wrote:
Hello I am new to the SPADE platform. When I try to run the example below of the documentation. I get the error below 
Exception in thread ag...@127.0.0.1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 530, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\spade\Agent.py", line 1001, in run
    self._setup()
  File "D:/DropboxSalimaJan2016/Dropbox/Mes travaux de Recherche/Implementation/Examples python2.7 et SPADE/MyAgentSendReceiveMsg.py", line 45, in _setup
    self.addBehaviour(ab, mt)
NameError: global name 'ab' is not defined

The variable ab is missing.

import spade

class MyAgent(spade.Agent.Agent):
	class ReceiveBehav(spade.Behaviour.Behaviour):
		"""This behaviour will receive all kind of messages"""

		def _process(self):
			self.msg = None
			
			# Blocking receive for 10 seconds
			self.msg = self._receive(True, 10)
			
			# Check wether the message arrived
			if self.msg:
				print "I got a message!"
			else:
				print "I waited but got no message"

	class AnotherBehav(spade.Behaviour.Behaviour):
		"""This behaviour will receive only messages of the 'cooking' ontology"""	
		def _process(self):
			self.msg = None
			
			# Blocking receive indefinitely
			self.msg = self._receive(True)
			
			# Check wether the message arrived
			if self.msg:
				print "I got a cooking message!"
			else:
				print "I waited but got no cooking message"				

	def _setup(self):
		# Add the "ReceiveBehav" as the default behaviour
		rb = self.ReceiveBehav()
		self.setDefaultBehaviour(rb)
		
		# Prepare template for "AnotherBehav"
		cooking_template = spade.Behaviour.ACLTemplate()
		cooking_template.setOntology("cooking")
		mt = spade.Behaviour.MessageTemplate(cooking_template)

		# Add the behaviour WITH the template
		self.addBehaviour(ab, mt)				

if __name__ == "__main__":
	a = MyAgent("ag...@127.0.0.1", "secret")
	a.start()

--
You received this message because you are subscribed to the Google Groups "spade-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spade-users+unsubscribe@googlegroups.com.
To post to this group, send email to spade...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

salima

unread,
Dec 1, 2016, 4:58:17 AM12/1/16
to spade-users
thank you for the help. I already tried to add ab = self.AnotherBehav() but it seems not working.


Le jeudi 1 décembre 2016 12:19:39 UTC+3, Markus Schatten a écrit :
Hello!

Yes, the example is missing an additional instance of behaviour, e.g. something like:

ab = self.AnotherBehav()

Hope this helps!

Best,

M.



--
Markus Schatten, PhD
Assistant professor and head of Artificial Intelligence Lab
University of Zagreb
Faculty of Organization and Informatics
Pavlinska 2, 42000 Varazdin, Croatia
http://www.foi.hr/nastavnici/schatten.markus/index.html
http://www.researchgate.net/profile/Markus_Schatten1
http://ai.foi.hr

On Thu, Dec 1, 2016 at 8:04 AM, salima <mnifs...@gmail.com> wrote:
Hello I am new to the SPADE platform. When I try to run the example below of the documentation. I get the error below 
Exception in thread ag...@127.0.0.1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 530, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\spade\Agent.py", line 1001, in run
    self._setup()
To unsubscribe from this group and stop receiving emails from it, send an email to spade-users...@googlegroups.com.

Markus Schatten

unread,
Dec 1, 2016, 6:55:27 PM12/1/16
to spade...@googlegroups.com
Hi,

it works fine for me... How did you test it?

Did you first run:

configure.py localhost

and then:

runspade.py

?

If yes, did you send a "cooking" message from the admin interface, e.g. http://localhost:8008?

I am getting the expected output for various messages...

$ python test.py
I got a message!

I got a cooking message!
I got a cooking message!
I got a message!

Best,

M.

--
Markus Schatten, PhD
Assistant professor and head of Artificial Intelligence Lab
University of Zagreb
Faculty of Organization and Informatics
Pavlinska 2, 42000 Varazdin, Croatia
http://www.foi.hr/nastavnici/schatten.markus/index.html
http://www.researchgate.net/profile/Markus_Schatten1
http://ai.foi.hr

To unsubscribe from this group and stop receiving emails from it, send an email to spade-users+unsubscribe@googlegroups.com.

salima

unread,
Dec 7, 2016, 2:38:40 AM12/7/16
to spade-users
Hello,
Thank you for the help. I do this steps configure.py localhost and then: runspade.py. But I don't understand how can I send  send a "cooking" message from the admin interface, e.g. http://localhost:8008?. 
Another question Can I send a message from a simple python  program to the agent. I yes how can I dot it?

Best,

Markus Schatten

unread,
Dec 7, 2016, 5:02:52 AM12/7/16
to spade...@googlegroups.com
Hi,

to send a "cooking" message from the administrative interface go to;

http://localhost:8008/agents (password is "secret")

Click on the "Send Msg" button right of your agent. Then enter
"cooking" into the "Ontology" field of the message and send it.

Of course you can send messages from Python scripts, this is the
intention of MAS ;-)

Create another script like (haven't tested it, but should work):

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import spade

sender = spade.Agent.Agent( 'sen...@127.0.0.1', 'password' )

receiver = spade.AID.aid( name="rece...@127.0.0.1", addresses=[
"rece...@127.0.0.1" ] )
msg = spade.ACLMessage.ACLMessage()
msg.setPerformative( "inform" )
msg.setOntology( "cooking" )
msg.addReceiver( receiver )
msg.setContent( "hello" )
sender.send( self.msg )


Where receiver is the other agent...

hth

Best,

M.
--
Markus Schatten, PhD
Assistant professor and head of Artificial Intelligence Lab
University of Zagreb
Faculty of Organization and Informatics
Pavlinska 2, 42000 Varazdin, Croatia
http://www.foi.hr/nastavnici/schatten.markus/index.html
http://www.researchgate.net/profile/Markus_Schatten1
http://ai.foi.hr


Reply all
Reply to author
Forward
0 new messages