Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JASON (AgentSpeak) how to use external actions with variables

I know how to define an external action that is atomic (has to arguments) such as "sitDown" and then manually code it in the Environment Java file within the execute action method.

However, if I define an external action, is there a way for it to accept arguments? Let us say I want to define an action that can be invoked in agent code this way:

destroy(4, 7);

In my environment class, how would I retrieve those values within the execute action method?

like image 992
Behrooz Avatar asked Dec 30 '25 19:12

Behrooz


1 Answers

Yes, you can send arguments to the environment as well as get feedbacks.

For example, in an application, a method that is changing a LED of a robot could be like this (this belongs to a class that extends Artifact - CArtAgO):

@OPERATION 
void changeLedPin(String newState) throws Exception {
     try {
        /** put gpio HIGH */
        if (newState.equals("high")) {
            logger.info("Changing pin to HIGH!");
            ledPin.high();
        }

        /** put gpio LOW */
        if (newState.equals("low")) {
            logger.info("Changing pin to LOW!");
            ledPin.low();
        }
     } catch (Exception e) {
        e.printStackTrace();
   }
}

Jason's agent code to invoke this external action could be like this:

!start.

+!start <- 
    changeLedPin(low).

For feedbacks you can use OpFeedbackParam sending in Jason code a variable to unify. The artifact method is something like this:

@OPERATION 
void inc(OpFeedbackParam<String> value) {
    /* some code */
}

Sources: https://github.com/cleberjamaral/goldminers/blob/master/src/env/mining/Raspi.java https://github.com/cleberjamaral/camel-artifact/blob/master/camelJaCaMoRobot/src/env/artifacts/Counter.java

like image 130
Cleber Jorge Amaral Avatar answered Jan 06 '26 15:01

Cleber Jorge Amaral



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!