jacamo-lang / jacamo

This project aims to promote the MultiAgent Oriented Programming (MAOP) approach by providing a suitable integration of tools and languages for programming agents, their environment and organisation.
https://jacamo-lang.github.io
GNU Lesser General Public License v3.0
77 stars 31 forks source link

"noenv" error when creating agents from artifacts or user-defined internal actions #8

Closed lcpz closed 7 years ago

lcpz commented 7 years ago

REDACTED: This is more general than I thought, so I made my post concise.

I've encountered an issue related to #7. My test case is:

  1. agent bob creates a workspace wsp and an artifact art;
  2. art creates agent carl, which wants to join wsp.

But carl fails to do so because of a "noenv" error.

Following are the full listings.

example.jcm

mas example {

    agent bob

    // agent source path
    asl-path: src/agt, src/agt/inc

}

bob.asl

!start.

+!start
<-
    .print("creating a workspace");
    createWorkspace("myworkspace");
    joinWorkspace("myworkspace", _);
    makeArtifact("myenv", "example.Test");
    createCarl. // operation defined in myenv

carl.asl

!start.

+!start : true
<-
    .print("I'll try to join Bob's workspace");
    joinWorkspace("wsp", _);
    .print("Succeeded").

-!start[error(E), error_msg(M)]
<-
    .print("error '", E, "' while executing 'start' goal: ", M).

src/env/example/Test.java

// [...]
public class Test extends Artifact {
    @OPERATION
    void createCarl() {
       //RuntimeServicesInfraTier rs = RunCentralisedMAS.getRunner().getRuntimeServices();
       RuntimeServicesInfraTier rs = JaCaMoLauncher.getJaCaMoRunner().getRuntimeServices();
        try {
            rs.createAgent("carl", "carl.asl", null, null, null, null, null);
            rs.startAgent("carl");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Console output:

CArtAgO Http Server running on http://127.0.0.1:3273
Jason Http Server running on http://127.0.0.1:3272
[bob] creating a workspace
[carl] I'll try to join Bob's workspace
[carl] error 'action_failed' while executing 'say' goal: no environment configured!

I also attach the related project: example2.zip

What am I doing wrong? Thanks in advance.

lcpz commented 7 years ago

This also happens with user-defined internal actions which create agents:

bob.asl

!start.

+!start
<-
    .print("creating a workspace");
    createWorkspace("wsp");
    joinWorkspace("wsp", _);
    jia.create_carl. // 'noenv' error
    //.create_agent(carl, "carl.asl"). // this works

src/jia/create_carl.java

// [...]
public class create_carl extends DefaultInternalAction {
    @Override
    public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
        RuntimeServicesInfraTier rs = ts.getUserAgArch().getRuntimeServices();
        rs.createAgent("carl", "carl.asl", null, null, null, null, ts.getAg());
        rs.startAgent("carl");
        return true;
    }
}

Variant project: example3.zip

jomifred commented 7 years ago

Hi, thanks again for reporting the bug and providing the example (that simplifies a lot our testing). It will be fixed in the next release of jacamo. Meanwhile, you can solve it by calling createAgent as follows:

    ...
    List<String> archs = new ArrayList<String>();
    archs.add("jaca.CAgentArch");
    archs.add("jacamo.infra.JaCaMoAgArch");
    rs.createAgent("carl", "carl.asl", null, archs, null, null, ts.getAg());
lcpz commented 7 years ago

I confirm it works in both test cases, thanks.

I've set archs as a one-liner in the class like this:

public static List<String> archs = new ArrayList<String>(Arrays.asList("jaca.CAgentArch", "jacamo.infra.JaCaMoAgArch"));