artificial-intelligenceagentartificial-life

Unable to send an action to another Jason agent


I am using Jason language to communicate between two agents. But I am unable to use send action, it gives an error.

These are my two agents,

Agent1:

// Agent Agent1 in project factorial3.mas2j

/* Initial goals */
!start.

/* Plans */

+!start : true
<- .print("starting..");
    !query_factorial(2).

+!query_factorial(X) : true <-
.send(agent2,tell,giveme(X)).

/*+fact(X,Y) : true <-
.print("factorial ", X, " is ", Y, " thank you expert").*/

Agent2:

// Agent agent2 in project IdEx.mas2j

/* Initial beliefs and rules */

/* Initial goals */

!begin.

/* Plans */

+!begin : true
    <- .print("expert starting.......");
        !giveme(X).

+!giveme(X):true
    <- !fact(X,Y);
    .print("Factorial of ", X, " is ", Y).
    //.send(agent1,achive,fact(X,Y)).
    
+!fact(X,1) : X == 0.

+!fact(X,Y) : X > 0
<- !fact(X-1,Y1);
    Y = Y1 * X.

So, I am getting this error when I am trying to call send action in agent1 and agent2 gives an receive error.

[agent2] *** Error adding var into renamed vars. var=X, value=(_229-1).
java.lang.ClassCastException: jason.asSyntax.ArithExpr cannot be cast to jason.asSyntax.VarTerm
    at jason.asSemantics.TransitionSystem.prepareBodyForEvent(TransitionSystem.java:877)
    at jason.asSemantics.TransitionSystem.applyExecInt(TransitionSystem.java:728)
    at jason.asSemantics.TransitionSystem.applySemanticRule(TransitionSystem.java:222)
    at jason.asSemantics.TransitionSystem.reasoningCycle(TransitionSystem.java:1429)
    at jason.infra.centralised.CentralisedAgArch.run(CentralisedAgArch.java:205)
    at java.lang.Thread.run(Thread.java:745)

Solution

  • If you want to ask for an agent to perform a plan (in case of agent1 when you say +!query_factorial(X)...) it should be an achieve message. Uncommenting the "plan" +fact(X,Y) : true <- .print("factorial ", X, " is ", Y, " thank you expert") you should use the operator ! at the begining to make it a plan. So, if I undertood the general idea of your test project, it can be rewritten as follows:

    Agent1 code:

    !start.
    
    +!start : true
    <- .print("starting..");
        !query_factorial(2).
    
    +!query_factorial(X) : true <-
        .send(agent2,achieve,giveme(X)).
    

    Agent2 code:

    +!giveme(X):true
        <- !fact(X,Y);
        .print("Factorial of ", X, " is ", Y).
    
    +!fact(X,1) : X == 0.
    
    +!fact(X,Y) : X > 0
        <- !fact(X-1,Y1);
        Y = Y1 * X.
    

    You can see, I am not using the "begin plan" of your original code since the Agent1 is doing the job, making Agent2 work when asked.