Search code examples
agentmulti-agent

How to execute a second plan, when the first fail in qwery, in JASON AgnetSpeak


I have a little problem with my program, in one secction one agent X send a tell to the agent Y, and this agent, checks his belief base to verify the fact, the problem is when the plan fails, he tried adding a -plan but its not worked, I appreciate any help, I have changed the context of the problem so that it is better understood, but the main idea is the same

/* Initial beliefs and rules */

wedding_guests(john). wedding_guests(anna). wedding_guests(bob). wedding_guests(ed).

/* Initial goals */

/* Plans */

+I_can_enter(R)[source(Ag)] <- ?wedding_guests(R) .print(R,"You are on the guest list") riesgo2.

-I_can_enter(R) <- .print("You can not pass").


Solution

  • failure plans can be used only for goals and, in your case, the plan +i_can_enter... reacts to new beliefs and not new goals. The plan -i_can_enter.... reacts to the deletion of such belief. (note that the lower case in i_can_enter, otherwise it is a variable.)

    There are many ways to solve your problem:

    1. use the performative achieve instead of tell, so that the receiver will have a new goal instead of a new belief. The plan then could be +!i_can_enter(R) ... with the plan failure being -!i_can_enter(R) ....

    2. place the test in the context of the plan:

    +i_can_enter(R)[source(Ag)] : wedding_guests(R) <- .print(R,"You are on the guest list").
    
    +i_can_enter(R) <- .print("You can not pass").
    
    1. use askOne performative. In the receiver:
    +?can_enter(R,ok) : wedding_guests(R). // R can enter if it is a wedding guest
    +?can_enter(R,nok).                    // R cannot otherwise
    

    in the sender:

    .send(receiver_name, askOne, can_enter(john,_), can_enter(_,ok)); // only continue if answer is "ok"
    

    or

    .send(receiver_name, askOne, can_enter(john,_), can_enter(_,A));
    .print("it is ",A," for john to enter");
    

    The forth term in the .send unifies with the answer.