How to use the spade.Agent function in spade

To help you get started, we’ve selected a few spade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github javipalanca / spade / examples / unittests / rpcTestCase.py View on Github external
import os
import sys
import time
import types
import unittest

sys.path.append('../..')

import spade

host = "127.0.0.1"

class MyAgent(spade.Agent.Agent):

	def _setup(self):
		self.result  = None

def sumVec(vec):
    r = 0
    for i in vec:
       r+=int(i)
    return {"sum":r}

def CreateService(name, owner, P=None,Q=None):
    return spade.DF.Service(name, owner, P=P,Q=Q)

def Invoke(agent, service,inputs=None):

    agent.result = agent.invokeService(service,inputs)
github javipalanca / spade / examples / unittests / dfTestCase.py View on Github external
import os
import sys
import time
import unittest

sys.path.append('../..')

import spade

host = "127.0.0.1"

class MyAgent(spade.Agent.Agent):

	def _setup(self):
            self.result = None
            #self.setDebugToScreen()

#with DAD
def Register_DAD(agent, param):


            sd = spade.DF.ServiceDescription()
            sd.setName("unittest_name_1_"+param)
            sd.setType("unittest_type_1_"+param)

            dad = spade.DF.DfAgentDescription()
            dad.addService(sd)
            sd = spade.DF.ServiceDescription()
github javipalanca / spade / examples / unittests / basicTestCase.py View on Github external
import os
import sys
import time
import unittest

sys.path.append('../..')

import spade

host = "127.0.0.1"

class MyAgent(spade.Agent.Agent):

	def _setup(self):
		self.pi  = None
		self.msg  = None


class GetPIBehav(spade.Behaviour.OneShotBehaviour):

	def _process(self):
		self.myAgent.pi = self.myAgent.getPlatformInfo()
		
class SendMsgBehav(spade.Behaviour.OneShotBehaviour):

    def _process(self):
        msg = spade.ACLMessage.ACLMessage()
        msg.setPerformative("inform")
github javipalanca / spade / examples / unittests / p2pTestCase.py View on Github external
import os
import sys
import time
import unittest

sys.path.append('../..')

import spade

host = "127.0.0.1"

class MyAgent(spade.Agent.Agent):

	def _setup(self):
		self.msg  = None


		
class p2pSendMsgBehav(spade.Behaviour.OneShotBehaviour):
    
    def __init__(self,method):
        spade.Behaviour.OneShotBehaviour.__init__(self)
        self.method = method

    def _process(self):
        msg = spade.ACLMessage.ACLMessage()
        msg.setPerformative("inform")
        msg.addReceiver(spade.AID.aid("b@"+host,["xmpp://b@"+host]))
github javipalanca / spade / examples / dalmuti / jugador.py View on Github external
import sys
sys.path.append("../..")

import spade
import random
import time
import string
from cartas import Carta
from cartas import jugada

servidor="localhost"

nombreAgente = ""

class jugador(spade.Agent.Agent):

    class inicioBehav(spade.Behaviour.OneShotBehaviour):
        def _process(self):
            self.msg = None
            
            # Esperamos indefinidamente hasta que empiece la partida
            self.msg = self._receive(True)
        
            # En este punto habra empezado
            print nombreAgente+": Ok!! A ver si hay suerte..."

            # Escogemos una carta al azar para establecer los
            # roles iniciales de la partida
            lim = string.atoi(self.msg.getContent())

            carta = random.randint(0, lim-1)
github javipalanca / spade / examples / rpc.py View on Github external
'''
This file shows a simple agent which just asks for the 
Platform Information (pi) to the AMS agent and prints it 
to the debug system.
It uses a OneShot Behaviour
You need to be running a SPADE platform on the same host
'''

import os
import sys
sys.path.append('..'+os.sep+'trunk')
sys.path.append('..')

import spade

class MyAgent(spade.Agent.Agent):
	class MyBehav(spade.Behaviour.OneShotBehaviour):
	    
		def onStart(self):
			self.myAgent.DEBUG("Starting behaviour . . .",'ok')
			
			s = spade.DF.Service(name="RPCmethod",owner=self.myAgent.getAID(),P="P")			
			
			self.myAgent.registerService(s,self.myAgent.RPCmethod)
			
			self.myAgent.DEBUG("Service registered "+str(s),'ok')

		def _process(self):
		    self.myAgent.DEBUG("Starting process . . .")
		    
		    s = self.myAgent.searchService(spade.DF.Service(name="RPCmethod"))
		    self.myAgent.DEBUG("Found service " + str(s[0]),'ok')
github javipalanca / spade / examples / thomas.py View on Github external
import os
import sys
sys.path.append('..'+os.sep+'trunk')
sys.path.append('..')

import spade

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

		def _process(self):
			# Show platform info
			pi = self.myAgent.getPlatformInfo()
			print pi

			# Set the receiver data
			receiver = spade.AID.aid(name="OMS@clapton:1099/JADE", 
                                     addresses=["http://clapton.dsic.upv.es:7778/acc"])
			
			# Build the message to register in THOMAS
			self.msg = spade.ACLMessage.ACLMessage()  # Instantiate the message
			#self.msg.setPerformative("inform")       # Set the "request" FIPA performative
github javipalanca / spade / examples / dalmuti / gameManager.py View on Github external
#!/usr/bin/env python

import sys
import os
sys.path.append(".."+os.sep+"..")
import spade
import string
import random
import time
from cartas import Carta
from cartas import jugada

servidor="127.0.0.1"

class gameManager(spade.Agent.Agent):

    jugadores = {}
    vKey = 0

    class inscripcionBehav(spade.Behaviour.Behaviour):
        def _process(self):
            self.msg = None
            mA=self.myAgent
            
            if mA.nInscritos < mA.nPlayers:
                print ">> Inscripcion: Esperando (",(mA.nPlayers-mA.nInscritos),"restantes )\n"
                # Esperamos indefinidamente un mensaje de un jugador
                self.msg = self._receive(True)

                # Nos solicitan entrar en la partida
                jugador, name = mA.datosSender(self.msg.getSender().getName())
github javipalanca / spade / examples / benchmark / bench1_receiver.py View on Github external
import sys
sys.path.append("/home/magentix/pybenchmarks/spade/")
import spade
import time

class ReceptorBenchmark1(spade.Agent.Agent):
	
	def __init__(self, jid, password, smethod="p2p"):
		spade.Agent.Agent.__init__(self, jid, password, p2p=True)
		self.nemisores = 0
                self.smethod = str(smethod)
		self._debug = True

	def _setup(self):
            temp = spade.Behaviour.ACLTemplate()
            temp.setPerformative("request")
	    t = spade.Behaviour.MessageTemplate(spade.Behaviour.ACLTemplate())
	    self.addBehaviour(self.behav(),t)
	
	class behav(spade.Behaviour.OneShotBehaviour):
	
	    def _process(self):
github javipalanca / spade / examples / fsm.py View on Github external
#  FSM EXAMPLE                      #
#####################################
'''
This file shows a simple agent which runs
a Finite State Machine Behaviour (FSM).
You need to be running a SPADE platform on the same host
'''

import sys,os
sys.path.append('..'+os.sep+'trunk')
sys.path.append('..')

import spade
import time

class MyAgent(spade.Agent.Agent):
	class StateOne(spade.Behaviour.OneShotBehaviour):
		def _process(self):
			print "This is State One..."
			self.myAgent.counter = self.myAgent.counter + 1
			if self.myAgent.counter > 2:
				self._exitcode = self.myAgent.TRANSITION_TO_TWO
			else:
				self._exitcode = self.myAgent.TRANSITION_DEFAULT

 	class StateTwo(spade.Behaviour.OneShotBehaviour):
		def _process(self):
			print "This is State Two..."
			self.myAgent.counter = self.myAgent.counter + 1
			if self.myAgent.counter > 5:
				self._exitcode = self.myAgent.TRANSITION_TO_THREE
			else: