BDI in action

During the agent execution, classic SPADE behaviours can coexist with the BDI model. Every time that a new Goal is introduced into the agent, it will try to achieve it looking for a Plan that fits the task. All this work happens in a completely transparent way for the user.

		import spade
		from spade.bdi import *

		agent = BDIAgent("bdi@127.0.0.1","secret")
		agent.setDebugToScreen()
		agent.addBelieve(expr("Value(0)"))

		g = Goal(expr("Value(2)"))

		class Serv1(Service):
		    def run(self):
		        print "Service 1 running"
		        self.addBelieve(expr("Value(1)"))
		class Serv2(Service):
		    def run(self):
		        print "Service 2 running"
		        self.addBelieve(expr("Value(2)"))

		s1 = Serv1(P=expr("Value(0)"),Q=expr("Value(1)"))
		s2 = Serv2(P=expr("Value(1)"),Q=expr("Value(2)"))

		p = Plan(P=expr("Value(0)"),Q=expr("Value(2)"))
		p.appendService(s1)
		p.appendService(s2)

		agent.addPlan(p)
		agent.addGoal(g)

		agent.start()

		import time
		try:
		    while True:
		        time.sleep(1)
		except:
		    agent.stop()

		sys.exit(0)