<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Distributed Runtime Verification of JADE and Jason Multiagent Systems with Prolog?</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Daniela Briola</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Viviana Mascardi</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Davide Ancona</string-name>
          <email>davide.ancona@unige.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>DIBRIS, Genoa University</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <fpage>319</fpage>
      <lpage>323</lpage>
      <abstract>
        <p>Verifying properties of interactions taking place inside open, complex, distributed, dynamic systems is of paramount importance for most applications and is mandatory for safety-critical ones. Verification can take place at design time (o✏ine or static verification) or at runtime (online or dynamic). For runtime verification some layer between the monitor executing the verification engine and the system under monitoring must exist, so that actual interactions can be intercepted and the compliance of each one against the protocol can be checked. A common way to improve eciency and fault tolerance of the runtime verification is to distribute it among many monitors. This requires that the protocol is projected onto subsets of participants. If the system has been engineered as a multiagent system (MAS), which is a good option when openness, complexity, distribution, dynamics are characterizing features, then the choice of either JADE, http://jade.tilab.com/, or Jason http://jason.sourceforge.net/, as the platform for implementing it may be a very natural one. JADE, implemented in Java, is the state-of-the-art tool for MAS development and has been used for many real industrial applications. Jason, implemented in Java as well and based on a Prolog engine built from scratch by its developers, is one of the most widely used frameworks when the agents under development are designed according to the Belief, Desire, Intentions (BDI) architecture. Due to the wide range of possible application fields of Jason and to the large amount of real use cases of JADE, being able to verify interactions taking place in MASs implemented in one of these two frameworks is a concrete step towards making MASs more reliable and enhancing their industrial and commercial usability. In this demo we show our contribution for the achievement of this goal. We have in fact designed and implemented a framework for distributed runtime verification of MASs and ad hoc interfaces for monitoring JADE and Jason interactions. The framework consists of four layers: (1) a formalism for describing agent interaction protocols (AIPs) based on constrained global types [1] and their extension with attributes [7]; (2) a mechanism for projecting AIPs onto subsets of agents, obtaining a new protocol in the same formalism of constrained global types [2]; (3) a mechanism for verifying that interactions are compliant</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        Introduction
? Paper presented at the CILC 2014 Demo Session, based on published material [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
        ].
with the AIP [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]; and (4) a mechanism for intercepting messages involving the
agents under monitoring, be them JADE or Jason ones, in a way as transparent
as possible.
      </p>
      <p>The strength of our framework, represented in Figure 1, is its high
modularity and potential for code reuse: the first three layers are independent from
the actual MAS under monitoring and have been implemented in Prolog. The
“protocol representation” and “compliance verification” layers have been tested
and improved over time, reaching an almost stable version now, whereas the
projection layers works under the assumption that the protocol contains no
attributes (namely, it is a “plain” constrained global type) and has not been tested
extensively yet. The fourth layer depends on the MAS framework under
monitoring: nothing prevents us from adding new agent frameworks at the bottom of
our architecture by developing ad hoc mechanisms for message interception, still
leaving the first three layers unchanged. By exploiting the components o↵ered by
our stacked framework it is possible to implement both monitors external to the
MAS, implemented as completely separate processes that do not intervene in the
observed system, and agents which are able to monitor the protocol executions
and have the power to intervene when they detect a violation. Associating the
“compliance verification” capability with an artifact (as in the first case) or with
an agent (as in the second case) are two di↵erent design choices, each with pros
and cons. We experimented both approaches, as discussed in Section 3 where
monitoring is performed by a Java artifact that does not intervene in the MAS
activity, and in Section 4 where the Jason agent in charge of the monitoring
activity can prevent other agents from sending non compliant messages.</p>
      <p>Whatever the choice, compliance verification should be an ecient process.
Although eciency issues are still to be explored, distributing the runtime
verification by projecting onto subsets of agents could be a way to balance the load
of the monitoring activity among more entities.
2</p>
      <p>
        Background
Global types [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] are a behavioral type and process algebra approach to the
problem of specifying and verifying multiparty interactions between distributed
components. We took inspiration from global types to propose a formalism,
constrained global types, suitable for representing AIPs. Because of space
constraints we cannot go into the details of the formalism which can be found in
[
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. Since attribute global types are interpreted coinductively, it is possible to
specify protocols that are not allowed to terminate like for example the SERVER
protocol defined by the equation
      </p>
      <p>SERVER = (receive request,0):(serve request,0):SERVER
where SERVER is a logical variable which is unified with a recursive (or cyclic,
or infinite) Prolog term consisting of a receive request producer interaction
type, followed by a serve request producer interaction type (both requiring
0 consumers), followed by the term itself. This protocol models the (infinite)
behavior of a server which is always ready to receive and serve requests; the only
valid interaction trace is the infinite sequence receive request serve request
receive request serve request ....</p>
      <p>
        By means of attribute global types we were able to concisely represent
protocols which are well known in the concurrent systems and MAS communities
like the Alternating Bit Protocol (en.wikipedia.org/wiki/Alternating bit
protocol) and the FIPA Iterated Contract Net Protocol (fipa.org/specs/fipa00030).
FYPA (Find Your Path, Agent! [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]) is not as well known, but is a negotiation
protocol for a real MAS used by Ansaldo STS, and is far more complex than the
two others. We exploited our formalism to model FYPA as well [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ].
      </p>
      <p>
        Constrained global types can be easily expressed as a set of Prolog
equations like the one defining SERVER. Attributes and constraints on their values
are represented as additional Prolog facts. In order to allow agents to verify
only a sub-protocol of the global interaction protocol, we designed a
projection algorithm that takes a constrained global type and a set of agents Ags as
input, and returns a constrained global type which contains only interactions
involving agents in Ags as output [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. Projection can be described as a function
⇧ : CT ⇥ P(AGS) ! CT where CT is the set of constrained global types and
AGS is the set of agents. The intuition besides the algorithm is that interactions
that do not involve agents in Ags are removed from the projected constrained
global type.
      </p>
      <p>Whatever the protocol to be monitored (global one or projection) and the
framework (JADE or Jason), a monitor keeps track of the runtime evolution of
the protocol by saving its current state (which is an attribute global type) and
checking that each interaction taking place in the MAS is allowed by the current
state (namely, can lead to a new state by means of the transition function which
defines the semantics of attribute global types, implemented in Prolog). If the
interaction is not allowed, an error is reported. The monitor also checks agents
responsiveness by means of a time-out whose value can be set by the user: if
the current state of the monitor corresponds to the empty protocol (that is,
the protocol must terminate), then the monitor reports an error as soon as an
interaction is detected (independently of the time-out); if the current state is not
final (that is, the protocol is not allowed to terminate), then the monitor reports
a warning as soon as the time-out expires, if no interaction is detected (and of
course an error is reported in case an invalid interaction is detected before the
time-out).
3</p>
      <p>
        Runtime Verification of JADE MASs
In order to verify the interactions taking place in a JADE MAS, we have designed
a monitor meeting the following requirements for non intrusiveness and code
reuse [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]: (1) the monitor must be able to supervise the execution of the MAS
without interfering with it, (2) the monitor activity must require no changes to
the agents’ code, (3) the formalism for representing the AIP must be attribute
global types, and (4) the Prolog code already developed for implementing
verification of interactions w.r.t. attribute global types and for protocol projection
must be re-used as it is.
      </p>
      <p>To meet requirements 1 and 2 we extended the JADE Sni↵er agent which is
able to sni↵ all the messages exchanged during the execution of the MAS in a
non intrusive way: JADE is developed under the LGPL (Lesser General Public
License) and the Java source code is available to the research community, so we
were able to modify it to achieve our goals.</p>
      <p>To meet requirements 3 and 4 we exploited the JLP library1 providing a
bidirectional interface between Java and SWI Prolog. As all our previous work on
attribute global types was implemented in Prolog, allowing our JADE Monitor
to consult Prolog programs and to call Prolog predicates was the best way to
ensure reusability.</p>
      <p>The monitor reads a file containing the Prolog code implementing verification
and projection, and a configuration file listing the agents to be monitored, and
onto which the protocol projection will be performed. A log file is written as the
monitoring goes on. The Prolog file contains definitions for three predicates:
– initialize(LogFile, SniffedAgents) which sets LogFile as the file where
writing the outcome of the verification, and projects the global protocol - which
must be defined by the global type/1 predicate -, onto Sni↵edAgents.</p>
      <p>– remember(ParsedMsg) which inserts the Prolog representation of the JADE
sni↵ed message into a message list, where messages are ordered by time stamp
(if they have a time stamp, which is not mandatory) or in order of arrival.</p>
      <p>– verify(CurrentTime) which verifies the compliance of each message
remembered in the message list and whose time stamp is lower than CurrentTime
to the global protocol.</p>
      <p>These predicates are called in di↵erent methods of the monitor code,
implementing the wanted behavior.</p>
      <p>With this approach no changes are required to the monitored agents and hence
existing MASs can be monitored without accessing to their code, but the monitor
detects a violation only after it took place and even in case of a protocol violation
the MAS execution goes on.
1 http://www.swi-prolog.org/packages/jpl/java api/</p>
      <p>
        Runtime Verification of Jason MASs
Since Jason agents can integrate Prolog facts and rules for defining their
knowledge, the Jason monitor [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] can be generated in a trivial way by integrating
directly into its code the Prolog code for protocol specification, monitoring and
projection that the JADE monitor must instead read from the Prolog file. The
way interactions are sni↵ed in Jason depends on some assumption on the agents’
code and requires some modifications to it: we assume that agents interact via
asynchronous exchange of messages with tell performatives; their original code
must be modified in the following way:
1. the .send built-in action for message delivery is replaced by !my send and
2. two plans must be added for managing the interaction with the monitor.
      </p>
      <p>The first plan is triggered by the !my send internal goal; my send has the
same signature as the .send internal action, but, instead of sending a message
with performative Perf and Content to Receiver, it sends a tell message
to the monitor with content msg(Sender, Receiver, Perf, Content). When
received, this message will be checked by the monitor against the attribute global
type representing the protocol, as briefly explained in Section 2.</p>
      <p>The second plan is triggered by the reception of the monitor’s message that
allows the agent to actually send Content to Receiver. In reaction to the
reception of such a message, the agent sends the corresponding message to the
expected agent.</p>
      <p>With this approach the code of the monitored agents must be conceived and
implemented in a way that makes monitoring possible, but the monitor detects a
violation prior than the actual message is sent and can stop the agent violating
the protocol by not allowing it to send the “wrong” message.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>D.</given-names>
            <surname>Ancona</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Barbieri</surname>
          </string-name>
          , and
          <string-name>
            <given-names>V.</given-names>
            <surname>Mascardi</surname>
          </string-name>
          .
          <article-title>Constrained global types for dynamic checking of protocol conformance in multi-agent systems</article-title>
          .
          <source>In SAC. ACM</source>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>D.</given-names>
            <surname>Ancona</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Briola</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. E. F.</given-names>
            <surname>Seghrouchni</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Mascardi</surname>
          </string-name>
          , and
          <string-name>
            <given-names>P.</given-names>
            <surname>Taillibert</surname>
          </string-name>
          .
          <article-title>Ecient verification of MASs with projections</article-title>
          .
          <source>In EMAS Pre-proceedings</source>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>D.</given-names>
            <surname>Ancona</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Drossopoulou</surname>
          </string-name>
          , and
          <string-name>
            <given-names>V.</given-names>
            <surname>Mascardi</surname>
          </string-name>
          .
          <article-title>Automatic generation of selfmonitoring MASs from multiparty global session types in Jason</article-title>
          . In DALT X, volume
          <volume>7784</volume>
          <source>of LNAI</source>
          . Springer,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>D.</given-names>
            <surname>Briola</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Mascardi</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D.</given-names>
            <surname>Ancona</surname>
          </string-name>
          .
          <article-title>Distributed runtime verification of JADE multiagent systems</article-title>
          .
          <source>In IDC, Studies in Computational Intelligence</source>
          . Springer,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>D.</given-names>
            <surname>Briola</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Mascardi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Martelli</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Caccia</surname>
          </string-name>
          , and
          <string-name>
            <given-names>C.</given-names>
            <surname>Milani</surname>
          </string-name>
          .
          <article-title>Dynamic resource allocation in a MAS: A case study from the industry</article-title>
          .
          <source>In WOA</source>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>M.</given-names>
            <surname>Carbone</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Honda</surname>
          </string-name>
          , and
          <string-name>
            <given-names>N.</given-names>
            <surname>Yoshida</surname>
          </string-name>
          .
          <article-title>Structured communication-centred programming for web services</article-title>
          .
          <source>In ESOP, LNCS</source>
          , pages
          <fpage>2</fpage>
          -
          <lpage>17</lpage>
          . Springer,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>V.</given-names>
            <surname>Mascardi</surname>
          </string-name>
          and
          <string-name>
            <given-names>D.</given-names>
            <surname>Ancona</surname>
          </string-name>
          .
          <article-title>Attribute global types for dynamic checking of protocols in logic-based multiagent systems</article-title>
          .
          <source>TPLP</source>
          ,
          <volume>13</volume>
          (
          <issue>4</issue>
          -5-Online-Supplement),
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>V.</given-names>
            <surname>Mascardi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Briola</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D.</given-names>
            <surname>Ancona</surname>
          </string-name>
          .
          <article-title>On the expressiveness of attribute global types: The formalization of a real multiagent system protocol</article-title>
          .
          <source>In AI*IA</source>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>