Commit b07b6dea by serfrape

Send trigger action on message body

parent 4c97471f
!start.
+!start <-
+car(rojo);
.a_function(3,W);
.print("w =", W);
literal_function(rojo,Y);
.print("Y =", Y);
.custom_action(8);
.print("sending individual message ...");
.send("BDIAgent@localhost", achieve, hello(15));
.print("sent a message").
+truck(azul).
+car(amarillo)
<- .print("El carro es amarillo.").
+!hello(Msg)[source(Sender)] <-
.print("got a message from", Sender, "saying", Msg).
\ No newline at end of file
+!hello(Msg)[source(Sender)] <-
.print("got a message from", Sender, "saying", Msg).
\ No newline at end of file
from spade_bdi.bdi import BDIAgent
a = BDIAgent("RECEIVERBDIAgent@localhost", "bditest1", "receiver.asl")
a.start()
!start.
+!start <-
+car(rojo);
//.a_function(3,W);
//.print("w =", W);
//literal_function(rojo,Y);
//.print("Y =", Y);
//.custom_action(8);
.print("sending individual message ...");
.send("RECEIVERBDIAgent@localhost", achieve, hello(15));
.print("sent a message").
+truck(azul).
+car(Color)
<- .print("El carro es ",Color).
\ No newline at end of file
from spade_bdi.bdi import BDIAgent
a = BDIAgent("BDIAgent@localhost", "bditest", "plan.asl")
a = BDIAgent("BDIAgent@localhost", "bditest", "sender.asl")
a.start()
import time
......
from spade_bdi.bdi import BDIAgent
a = BDIAgent("BDIAgent@localhost", "bditest", "plan.asl")
a.start()
import time
time.sleep(1)
a.bdi.set_belief("car", "azul", "big")
a.bdi.print_beliefs()
print("GETTING FIRST CAR BELIEF")
print(a.bdi.get_belief("car"))
a.bdi.print_beliefs()
a.bdi.remove_belief("car", 'azul', "big")
a.bdi.print_beliefs()
print(a.bdi.get_beliefs())
a.bdi.set_belief("car", 'amarillo')
!start.
+!start <-
+car(rojo);
.a_function(3,W);
.print("w =", W);
literal_function(rojo,Y);
.print("Y =", Y);
.custom_action(8);
.print("sending individual message ...");
.send("BDIAgent@localhost", achieve, hello(15));
.print("sent a message").
+truck(azul).
+car(amarillo)
<- .print("El carro es amarillo.").
+!hello(Msg)[source(Sender)] <-
.print("got a message from", Sender, "saying", Msg).
\ No newline at end of file
......@@ -39,10 +39,9 @@ class BDIAgent(Agent):
return
ilf_type = ilf.functor
mdata = {"performative": "BDI",
"ilf_type": ilf_type,
"message": term.args[2]}
# Optional body
body = json.dumps({})
"ilf_type": ilf_type, }
body = json.dumps({"functor": str(term.args[2].functor),
"args": str(term.args[2].args)})
msg = Message(to=receiver, body=body, metadata=mdata)
self.agent.submit(self.send(msg))
print("SENT!!!")
......@@ -90,7 +89,7 @@ class BDIAgent(Agent):
pyson.runtime.Intention())
def get_belief(self, key):
"""Get an existing agent's belief. The first belief matching
"""Get an existing agent's belief. The first belief matching
<key> is returned """
key = str(key)
for beliefs in self.bdi_agent.beliefs:
......@@ -158,12 +157,13 @@ class BDIAgent(Agent):
raise pyson.PysonError(
"unknown illocutionary force: %s" % ilf_type)
intention = pyson.runtime.Intention()
message = pyson.freeze(mdata["message"], intention.scope, {})
message = pyson.Literal(
received["functor"], tuple([received["args"]]))
message = pyson.freeze(message, intention.scope, {})
tagged_message = message.with_annotation(
pyson.Literal("source", (pyson.Literal(self.bdi_agent.name), )))
pyson.Literal("source", (pyson.Literal(str(msg.sender)), )))
self.bdi_agent.call(trigger, goal_type,
tagged_message, intention)
# print("RECEIVED\n", received)
self.bdi_agent.step()
async def on_end(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment