Social Relationships for Designing Agent Interaction in JADE Matteo Baldoni, Cristina Baroglio and Federico Capuzzimati Dipartimento di Informatica Università degli Studi di Torino c.so Svizzera 185, I-10149 Torino (Italy) Email: {matteo.baldoni,cristina.baroglio,federico.capuzzimati}@unito.it Abstract—Current agent platforms do not provide agents corresponding regulations), constructed, e.g., by negotiation, the means for reasoning about expected behaviours during specialized, composed, and so forth. Last but not least, the use interactions. This lack is due to the absence of design primitives to of artifacts enables the implementation of monitoring function- explicitly shape interaction patterns as first-class resources. This alities for verifying that the on-going interactions respect the work presents 2COMM4JADE, a framework based on JADE and commitments and for detecting violations and violators. CArtAgO platforms that allows definition of social relationships among parties, represented by social commitments, decoupled Summarizing, this work proposes to introduce in MAS an from the agent design itself. explicit notion of social relationships, captured as commit- ments (Section II). Social relationships are actual resources, I. I NTRODUCTION AND M OTIVATION implemented through artifacts, that are made available to the agents, and are first-class entities of the model, as well as Multi-Agent Systems (MAS) represent a preferred choice agents. The framework 2COMM4JADE (Section III) realizes for building complex systems, where the autonomy of each the proposal based on an extension of JADE and of CArtAgO. component represent a major requirement. Agent-oriented soft- We show the impact of the proposal on programming by means ware engineers can choose from a substantial number of agent of an example (Section IV). platforms [19], [8], [14], [5]. Platforms and frameworks like JADE [6], TuCSoN [22], DESIRE [9], JIAC [27], all provide II. M ODELING S OCIAL R ELATIONSHIPS coordination mechanisms and communication infrastructures [8]. We claim, however, that none of the current infrastructures We propose to explicitly represent social relationships for MAS is adequate to really preserving autonomy, and do among the agents. By social relationships we mean nor- not fit the high degree of decoupling often required by such matively defined relationships, and the expected patterns of systems. This can be obtained only via a clear separation of interaction, between two or more agents, resulting from the the agent specification from the coordination specification, that enactment of roles, and subject to social control. We envisage avoids any “hard-coding” of the regulations of the system both agents and social relationships as first-class entities that inside the activities of the participants. To this aim, we propose interact in a bi-directional manner. Social relationships are to explicitly represent interaction patterns among agents in created by the execution of interaction protocols and pro- terms of normatively defined social relationships; the nor- vide expectations on the agents’ behaviour. It is, therefore, mative characterization is grounded on commitments, which necessary to provide the agents the means to create and to feature a social and observational semantics [25]; in order to manipulate, and to observe, to monitor, to reason and to represent the coordination requirements we propose to rely on deliberate on social relationships so to take proper decisions commitment-based protocols [29]. about their behaviour. We do so by exploiting properly defined artifacts, that reify both interaction protocols, defined in terms The framework we propose, 2COMM4JADE, uses JADE of social relationships, and the sets of social relationships, as basic agent platform, which provides a FIPA compliant created during protocol execution. Such artifacts are made communication framework and an agent-developing middle- available to agents as resources. ware. JADE does not offer an agent programming language, but it is a sound, well-established and industry-adopted agent The aim of our proposal is to clearly decouple the inter- framework. Although the first release was presented in 2007, a action design from the agent design, using artifacts to encode dynamic community helps developers in updating and evolving the coordination logic. Commitment-based protocols provide the platform, providing new functionalities and capabilities. a means of coordination, based on the notification of social Thus, it supplies a valuable starting ground. events, e.g. the creation of a commitment. Interacting agents use artifacts to coordinate and interact, depending on the In order to reify the social relationships we rely on the roles they play and on their objectives. Such a decoupling Agents & Artifacts meta-model (A&A) [28], [21], which avoids interaction logics hard–coded in agent programs, that provides abstractions for environments and artifacts, that can can lead to an increasing developing effort and a difficult be acted upon, observed, perceived, notified, and so on. When maintenance of the system, especially when it constitutes a embodied inside artifacts, social relationships can be examined society of autonomous entities belonging to different organiza- by the agents (to take decisions about their behavior), as tions. Instead, relying on commitment-based protocols allows advised in [11], used (which entails that agents accept the a modular definition of components of the system and of how they interact, using the notion of commitment to define the social expectations on the stakeholders’ behaviour), to be shape and the evolution of interaction patterns. accepted explicitly by the participants to the interaction, to be inspected so as to allow stakeholders to decide whether A commitment [24] is represented with the notation conforming to them. To this aim, we propose to explicitly C(x, y, r, p), capturing that the agent x commits to the agent y model social relationships as resources, that are made available to bring about the consequent condition p when the antecedent to the interacting peers, in the very same way as other kinds of condition r holds. Antecedent and consequent conditions gen- resources; a resource that has to be inspectable, and therefore erally are conjunctions or disjunctions of events and commit- can not be modeled as an agent. To solve this issue, we adopt ments. When r equals >, we use the short notation C(x, y, p) the Agents and Artifacts (A&A) meta-model [28], [21], that and the commitment is said to be active. Commitments have extends the agent paradigm with another primitive abstraction, a regulative nature, in that debtors are expected to behave so the artifact. An artifact is a computational, programmable sys- as to satisfy the engagements they have taken. This practically tem resource, that can be manipulated by agents, residing at the means that an agent is expected to behave so as to achieve the same abstraction level of the agent abstraction class. For their consequent conditions of the active commitments of which it very nature, artifacts can encode a mediated, programmable is the debtor. and observable means of communication and coordination Agents share a social state that contains commitments, and between agents. update it as a result of performing their activities. Specifically, We interpret the fact that an agent uses an artifact as the the manipulation of commitments is done by means of the explicit acceptance, by the agent, of the regulation encoded standard operations create, cancel, release, discharge, assign, by that artifact, and modeled by the interaction protocol that delegate. As in [24], we postulate that discharge is performed the artifact reifies. This is an important aspect because it concurrently with the actions that lead to the given condi- allows the interacting parties to perform practical reasoning, tion being satisfied and causes the commitment to not hold. based on expectations: participants expect that the debtors Delegate and assign transfer commitments respectively to a of commitments behave so as to satisfy the corresponding different debtor and to a different creditor. For details see [24], consequent conditions; when this does not happen, a violation [29], [10]. is raised. Relying on artifacts allows also other kinds of The next question to answer is how to integrate, inside manipulation, including (but not limited to) an agent playing a the outlined agent and artifact setting, the rules that regulate role in the interaction, and an agent observing the interaction the process by which social relationships are created and that is being carried on. manipulated. In our proposal, this is done by relying on the Summarizing, we claim that an agent-based framework notion of commitment-based interaction protocol. This kind of should satisfy the following requirements: 1) Explicit rep- protocol consists of a set of actions (process activities), whose resentation of the social relationships, created and evolving semantics is shared, and agreed upon, by all of the participants along the interaction. 2) Social relationships should be first- to the interaction [29], [10]. The semantics of the social actions class objects, which can be used for programming the agent is given in terms of the operations which allow the modification behavior. 2COMM4JADE fulfills both. of the social state and that have already been described. From an organizational perspective, a protocol is structured III. 2COMM4JADE: A C OMMITMENT- BASED into a set of roles. Roles and agents are different entities, INFRASTRUCTURE FOR SOCIAL RELATIONSHIPS and we assume that roles cannot live autonomously: they exist in the system in view of the interaction, because agents, for After providing the background, we describe the developed interacting, use artifacts and execute actions on them. We implementation framework, that we named 2COMM4JADE. follow the ontological model for roles proposed in [7], and The focus is to provide adequate support for programming brought inside the object-oriented paradigm in [4], which is social relationships by exploiting a declarative, interaction- characterized by three aspects: (1) Foundation: a role must centric approach and by relying on existing technologies as always be associated with the institution it belongs to and with far as possible. Specifically, the implementation framework its player; (2) Definitional dependence: the definition of the combines two well-known platforms: JADE [6] and CArtAgO role must be given inside the definition of the institution it [23]. JADE agents represent stakeholders, commitment-based belongs to; (3) Institutional empowerment: the actions defined interaction protocols are realized as CArtAgO artifacts. for the role in the definition of the institution have access to the state of the institution and of the other roles, thus, they JADE is a popular and industry-adopted agent frame- are called powers; instead, the actions that a player must offer work. It offers to developers a Java middleware that is for playing a role are called requirements. The agents that will FIPA-compliant [17]. Its robustness and well-proven reliability be the role players become able to perform protocol actions, makes JADE a preferred choice in developing MAS. A JADE- that are powers offered by a specific role and whose execution based system is composed of one or more containers, each affect the social state. On the other hand, they need to satisfy grouping a set of agents in a logical node and representing the related requirements: specifically, in order to play a role a single JADE runtime. The overall set of containers is an agent needs to have the capabilities of satisfying the related called a platform, and can spread across various physical commitments – capabilities which can be internal of the agent hosts. The resulting architecture hides the underlying layer, or supplied as powers as well. allowing support for different low-level frameworks (JEE, JSE, JME, etc.). JADE provides communication and infrastructure Following [12], we need social relationships to be recog- services, allowing agents, that have been deployed in different nized as having a normative force (so that they will provide containers, to discover and interact with each other. CArtAgO is a framework based on the A&A meta-model specific protocol enactment and maintains an own social state [28], [21]. It extends the agent programming paradigm with and an own communication state. the first-class entity of artifact: a resource that an agent can use, and that models working environments. It provides a way Figure 1 reports an excerpt of the 2COMM4JADE UML to define and organize workspaces, that are logical groups class diagram1 . Let us get into the depths of the implementa- of artifacts, that can be joined by agents at runtime. The tion: environment is itself programmable and encapsulates services • CommunicationArtifact (CA for short) provides the and functionalities. CArtAgO provides an API to program arti- basic communication operations in and out for allow- facts that agents can use, regardless of the agent programming ing mediated communication. CA extends an abstract language or the agent framework used. This is possible by version of the TupleSpace CArtAgO artifact: briefly, means of the agent body metaphor: CArtAgO provides a native a blackboard that agents use as a tuple-based coordi- agent entity, which allows using the framework as a complete nation means. In and out are, then, operations on the MAS platform as well as it allows mapping the agents of tuple space. CA also traces who is playing which role some platform onto the CArtAgO agents, which, in this way, by using the property enactedRoles. becomes a kind of “proxy” in the artifacts workspace. The former agent is the mind, that uses the CArtAgO agent as a • Class Role extends the CArtAgO class Agent, and body, interacting with artifacts and sensing the environment. contains the basic manipulation logic of CArtAgO An agent interacts with an artifact by means of public opera- artifacts. Thus, any specific role, extending this super- tions, which can be equipped with guards: conditions that must type, will be able to perform operations on artifacts, hold in order for operations to produce their effects. When whenever its player will decide to do so. Role provides guards do not hold, actions can still be performed but without static methods for creating artifacts and for enact- consequences. ing/deacting roles. This is done by passing a reference to the JADE agent behaviour that will actually play the role. Agent Platform A&A Platform Artifact CArtAgO • The class CARole is an inner class of CA and extends Agent the Role class. It provides the send and receive prim- AbstractTuple ACLMessage Behaviour Space Agent itives, by which agents can exchange messages. Send 1...n and receive are implemented based on the in and out 2COMM4JADE primitives provided by CA. << Artifact >> << Role >> CommunicationArtifact CARole Role Observable Properties enactedRoles: Role [1…*] + + send(message: RoleMessage) # id: RoleId • ProtocolArtifact (PA for short) extends CA and allows tset: TupleSet Artifact Operations + receive(): RoleMessage # agent: AID # artid: ArtifactId modeling the social layer with the help of commit- + in(message: RoleMessage): void + out(): RoleMessage # player: Behaviour + createArtifact (artifactName: String, ments. It maintains the state of the on-going protocol artifactClass: Class) : void #checkRoleRequirements(roleName: String, offeredBehaviour:Behaviour) << Role >> + enact (roleName: String, artifact: ArtifactID, agent: AID, offeredPlayerBehaviour: interaction, via the property socialState, a store of PARole + hasCommitmentInvolving(c: Commitment): boolean Behaviour) : Role + deact (role: RoleId, artifact: ArtifactID, agent: social facts and commitments, that is managed only << Artifact >> + + socialFactExists(f: SocialFact): boolean AID, offeredPlayerBehaviour: Behaviour) : void by its container artifact. This artifact implements the ProtocolArtifact Observable Properties socialState: SocialState ...query operations on operations needed to manage commitments (create, SocialState ... Artifact Operations + << interface >> discharge, cancel, release, assign, delegate). PA re- # create (commit: Commitment) # discharge (commit: Commitment) SocialFact ProtocolObserver + handleEvent (event: alizes the commitment life-cycle and for the asser- # cancel (commit: Commitment) # release (commit: Commitment) predicate: String arguments: Object [0…*] SocialEvent, args: Object[ ]) tion/retraction of facts. Operations on commitments # assign (commit: Commitment, role: Role) # delegate (commit: Commitment, role: Role) # assertFact (fact: LogicalExpression) + getPredicate (): String + setPredicate (pred: String) are realized as internal operations, that is, they are + getArguments (): Object [ ] 0…* + setArguments (list: Object [1…*] ) not invokable directly: the protocol social actions will SocialState use them as primitives to modify the social state. We 1…* commitments: Commitment [0…*] Commitment refer to modifications occurred to the social state as facts: SocialFact [0…*] context: creditor: Role social events. Being an extension of CA, PA maintains CommitmentCommunicationArtifact + getFacts (): SocialFact[ ] + getCommitments(): Commitment [ ] debtor: Role antecedent: SocialFact [1…*] two levels of interaction: the social one (based on consequent: SocialFact [1…*] + addFact (fact: SocialFact) + addCommitment (commit: Commitment) status : enum {created, discharged, ...} + getCreditor(): Role commitments), and the communication one (based on + removeFact (fact: SocialFact) + removeCommitment (commit: Commitment) 0…* + setCreditor (role: Role) + getDebtor (): Role message exchange). + getContext(): + setDebtor (role: Role) CommitmentCommunicationArtifact + getStatus (): Role + setStatus (status: enum) • The class PARole is an inner class of PA and extends the CARole class. It provides the primitives for querying the social state, e.g. for asking the Fig. 1. Excerpt of the UML class diagram of 2COMM4JADE. commitments in which a certain agent is involved, and the primitives that allow an agent to become, through its role, an observer of the events occurring 2COMM4JADE is organized as follows. JADE supplies in the social state. For example, an agent can query standard agent services, i.e. message passing, distributed con- the social state to verify if it contains a commitment tainers, naming and yellow pages services, agent mobility. with a specific condition as consequent, via the When needed, an agent can enact a protocol role, which pro- method existsCommitmentWithConsequent vides a set of operations by means of which agents participate (InteractionStateElement el). in a mediated interaction session. Protocol roles are provided by communication artifacts, that are implemented by means 1 The source files of the system and examples are available at the URL of CArtAgO. Each communication artifact corresponds to a http://di.unito.it/2COMM. Alternatively, an agent can be notified about the <> ProtocolObserver Protocol Artifact occurrence of a social event, provided that it + handleEvent(SocialEvent e, Object … args) implements the inner interface ProtocolObserver. JADE Agent Afterwards, it can start observing the social state. RoleBehaviour 1. sense the social state + handleEvent(SocialEvent e, PARole also inherits the communication primitives Object … args) Social Communication defined in CARole. 2. activate behaviors according State State to social events 3. schedule behavior execution • The class SocialFact represents a fact of some rele- <> vance for the ongoing interaction, that holds in the + action() current state of interaction. A social fact is asserted <> + action() for tracking the execution of a protocol action. Actions .... Behaviour Repository <> can have additional effects on the social state; in this + action() case, corresponding social facts are added to it. In order to specify a commitment-based interaction pro- tocol, it is necessary to extend PA by defining the proper Fig. 2. 2COMM4JADE event handling schema. social and communicative actions as operations on the artifact itself. Actions can have guards that correspond to context preconditions: each such condition specifies the context in will simply implement the logic for handling that event, adding which the respective action produces the described social proper behaviour(s) to the agent’s behaviour repository. When effect. Since we want agents to act on artifacts only through scheduled, the behaviour will be executed, and the event their respective roles, when defining a protocol it is also handled. A methodological schema for handling a social event necessary to create the roles. We do so by creating as many follows. extensions of PARole as protocol roles. These extensions are realized as inner classes of the protocol: each such class will Algorithm 1: Methodological Schema for Handling So- specify, as methods, the powers of a role. Powers allow agents cial Events. who play roles to actually execute artifact operations. The Data: Social event se notified to agent a typical schema will be: Data: Set S of social events of interest Result: Add a behaviour to the behaviour set of a 1 public class MyProtocolArtifact 2 extends ProtocolArtifact { Check whether se involves a commitment c which has 3 // ... a as debtor or creditor; 4 static { if se ∈ S then 5 a d d E n a b l e d R o l e ( "Role1" , R o l e 1 . c l a s s ) ; b = behaviour that handles the occurred 6 a d d E n a b l e d R o l e ( "Role2" , R o l e 2 . c l a s s ) ; modification of c; 7 // ... 8 } add b to the set of behaviours of a; 9 / / MY PROTOCOL ARTIFACT OPERATIONS end 10 @OPERATION 11 p u b l i c v o i d op1 ( . . . ) { 12 / / p r e p a r e a message , i f n e e d e d ; i n t h a t c a s e , The proposed algorithm explains how to use the notifica- 13 send ( message ) ; tions performed by the protocol artifact to the agent. Depend- 14 / / modify t h e s o c i a l s t a t e , 15 / / e . g . c r e a t e commitment , u p d a t e commitment ing on which social event occurs, i.e. on which commitment is 16 } modified and how (e.g. added, discharged, detached), a specific 17 // ... behaviour is added and scheduled for execution, competing 18 / / INNER CLASSES f o r ROLES with others already present in the behaviour set. The agent 19 p u b l i c c l a s s R o l e 1 e x t e n d s PARole { 20 p u b l i c R o l e 1 ( B e h a v i o u r p l a y e r , AID a g e n t ) { designer can choose which social events are to be tackled by 21 s u p e r ( "Role1" , p l a y e r , a g e n t ) ; the agent. The following is the pseudo-code of an example 22 } implementation that agrees with the schema: 23 / / d e f i n e s o c i a l a c t i o n s f o r Role1 24 public void action1 ( . . . ) { 1 p u b l i c c l a s s MyBehaviour e x t e n d s 25 doAction ( t h i s . g e t A r t i f a c t I d ( ) , 2 SomeJadeBehaviour implements P r o t o c o l O b s e r v e r { 26 new Op( "op1" , . . . , g e t R o l e I d ( ) ) ) ; 3 [ ... ] 27 } 4 public void a c t i o n ( ) { 28 // ... 5 A r t i f a c t I d a r t = Role . c r e a t e A r t i f a c t 29 } 6 ( myArtifactName , M y A r t i f a c t . c l a s s ) ; 30 p u b l i c c l a s s R o l e 2 e x t e n d s PARole { 7 myRole = ( SomeRole ) ( R o l e . e n a c t 31 // ... 8 ( M y A r t i f a c t . ROLE NAME, a r t , t h i s , 32 } 9 myAgent . getAID ( ) ) ) ; 33 // ... 10 myRole . s t a r t O b s e r v i n g ( t h i s ) ; 34 } 11 / / add t h e i n i t i a l b e h a v i o u r o f t h e a g e n t 12 } 13 public void handleEvent ( SocialEvent e , Let us, now, consider Figure 2, which sketches how the 14 Object . . . args ) { agent model reacts to a new social event occurrence. For 15 SETemplate t = new SETemplate ( 16 myRole . g e t R o l e I d ( ) ) ; a JADE agent to play a role, one of its behaviours must 17 SETemplate t 2 = new SETemplate ( implement the method handleEvent, which receives the 18 myRole . g e t R o l e I d ( ) ) ; event just occurred in the social state. The agent programmer 19 t . iAmDebtor ( ) . c o m m i t I s D e t a c h e d ( ) 20 . consequentMatch ( . . . ) ; when the former looks for some investment. We adopt the 21 t2 . iAmCreditor ( ) . commitIsConditional ( ) following CNP formulation: 22 . antecedentMatch ( . . . ) ; 23 i f ( t . match ( e ) { 24 myAgent . a d d B e h a v i o u r ( . . . ) ; cfp causes create(C(i, p, propose, accept ∨ reject)) / / a behaviour to handle the case accept causes none 25 } e l s e i f ( t 2 . match ( e ) ) { reject causes release(C(p, i, accept, done ∨ failure)) 26 myAgent . a d d B e h a v i o u r ( . . . ) ; / / a behaviour to handle another case propose causes create(C(p, i, accept, done ∨ failure)) 27 } else refuse causes release(C(i, p, propose, accept ∨ reject)) 28 // ... done causes none / / behaviours for d i f f e r e n t cases failure causes none 29 } 30 31 } where i stands for the role Initiator and p for Participant. 32 } The instance used by FinancialMAS will tie the Investor to the i and the Financial Promoter to p. Initiator supplies its The agent behaviour implements ProtocolObserver, thus al- player the powers cfp (call for proposal), accept, and reject. lowing the agent to be notified about social events. This will be The first allows the initiator to ask participants for proposals done after the agent executes the method startObserving, spec- for solving a task of interest. If a proposal is chosen, action ifying which artifact it requires to observe. The implementation accept notifies the winner and all other proposals are rejected. of ProtocolObserver requires, in turn, the implementation The role participant supplies its player the powers propose, of the method handleEvent. Here, it is possible to test the refuse, done, and failure. Action propose allows a participant kind of event that was notified. If it is a commitment, it is to supply a solution for a task, action refuse allows declining possible to further check specific conditions of interest on it, the invitation to send a proposal. If a proposal is accepted, the including its state, the identity of its debtor and/or creditor, the winning participant is expected to execute the task and either antecedent or consequent condition (lines 19-22). The agent provide the result by means of the action done or communicate will, then, add appropriate behaviours to handle the detected its failure. Powers allow agents to affect the social state. For situation. A template-based matching mechanism for social instance, when an agent playing the role Initiator executes cfp, events is provided (class SETemplate, lines 15–18) used the social state is modified by creating the commitment C(i, by programmer in order to specify matching conditions. Each p, propose, accept ∨ reject). This addition binds i to either template class method returns this, thus compacting the accept or reject a proposal, if one is received. The agent is code for construction of complex conditions simply using the free to decide not only which course of action to take but also standard method dot notation. how to realize acceptance or rejection. The handler represents the classical agent sense-plan-act Let us see how CNP is realized in 2COMM4JADE. The cycle, rephrased into “sense the social state”, “activate behav- class CNP extends ProtocolArtifact and implements as artifact iors according to social events”, “schedule behavior execu- operations all the protocol actions. In the sketch below we tion”. Notice that this mechanism represents an agent-oriented detail, for the sake of brevity, only the action cfp. Lines 6–10 declination of callbacks. The agent paradigm forbids to make represent the construction and sending of a call for proposals, use of pure method invocation on the agent, that is autonomous which will be inserted in the blackboard and made available by definition. Instead, the agent designer provides a collection to participants. The recipient of the message is left generic of behaviours in charge for handling the different, possible because the Initiator may not know its peers, who may join evolutions of the social state, that are scheduled for execution even later in the future. Lines 15–19 modify the social state when the corresponding condition happens. For example, a by adding commitments and by stating that the event cfp has specific behaviour can be added when a new commitment is occurred. Lines 27–42 defines the role in terms of its powers. added, and the creditor of that commitment is the agent; or Here (lines 30–33), in fact, the power cfp is defined in terms when a social event is added to the social state. This way, an of the homonym artifact operation. intuitive and social-based programming schema is provided to 1 p u b l i c c l a s s CNP e x t e n d s P r o t o c o l A r t i f a c t { agent developers. 2 // ... 3 @OPERATION IV. P ROGRAMMING S OCIAL R ELATIONSHIPS : AN 4 p u b l i c v o i d c f p ( Task t a s k , R o l e I d i n i t i a t o r ) { EXAMPLE 5 / / send message with t h e t a s k 6 R o l e M e s s a g e c f p = new R o l e M e s s a g e ( ) ; FinancialMAS is an example application of 7 R o l e I d d e s t = new R o l e I d ( PARTICIPANT ROLE , 2COMM4JADE. Inspired by [13], it allows financial 8 R o l e I d . GENERIC ROLE ) ; 9 cfp . setContent ( task ) ; interactions between three categories of stakeholders: (1) 10 cfp . setRoleSender ( i n i t i a t o r ) ; investors, (2) financial promoters and (3) banks. Investors 11 cfp . setRoleReceiver ( dest ) ; have the goal to place investments; promoters to propose and 12 c f p . s e t P e r f o r m a t i v e ( ACLMessage . CFP ) ; finalize investment contracts, on behalf of a bank and on the 13 send ( cfp ) ; 14 / / update the s o c i a l s t a t e basis of current investor’s profile; banks to finalize contracts 15 c r e a t e A l l C o m m i t m e n t s ( new Commitment placed by promoters. 16 ( i n i t i a t o r , d e s t , "propose" , 17 new C o m p o s i t e E x p r e s s i o n ( L o g i c a l O p e r a t o r T y p e .OR, Let us focus on the Contract Net Protocol (CNP for 18 new F a c t ( "accept" ) , new F a c t ( "reject" ) ) ) ) ; short) [17], which is used inside FinancialMAS to manage the 19 a s s e r t F a c t ( new F a c t ( "cfp" , i n i t i a t o r , t a s k ) ) ; interaction between the Investor and the Financial Promoter 20 } 21 @OPERATION jade.core.Agent JADE jade.core.Behaviour JADE 2COMM4JADE 22 p u b l i c v o i d p r o p o s e ( P r o p o s a l prop , << Role >> PARole << Artifact >> ProtocolArtifact + hasCommitmentInvolving(c: Observable Properties 23 RoleId p a r t i c i p a n t , RoleId i n i t i a t o r ) { Commitment): boolean + socialFactExists(f: socialState: SocialState Artifact Operations 24 // ... SocialFact): boolean ...query operations on # create (commit: Commitment) # discharge (commit: Commitment) 25 } SocialState ... # cancel (commit: Commitment) # release (commit: Commitment) # assign (commit: Commitment, role: Role) 26 // ... Agent1 Agent2 # delegate (commit: Commitment, role: Role) # assertFact (fact: LogicalExpression) 27 / / Role c l a s s e s + <> << interface >> 28 p u b l i c c l a s s I n i t i a t o r e x t e n d s PARole { ProtocolObserver + handleEvent (event: 29 // ... InitiatorBehaviour +commitToAcceptOrRejectIf ParticipantBehaviour +commitToDoneOrFailure SocialEvent, args: Object[ ]) 30 p u b l i c v o i d c f p ( Task t a s k ) { Propose(): Behaviour +satisfyCommitToAccept IfAccept(): Behaviour +fulfilledCommitToAcceptOr OrReject(): Behaviour Reject(): Behaviour Contract Net Protocol 31 doAction ( t h i s . g e t A r t i f a c t I d ( ) , +fulfilledCommitToDoneOr Failure(): Behaviour +handleEvent(event: 32 new Op( "cfp" , t a s k , g e t R o l e I d ( ) ) ) ; +handleEvent(event: SocialEvent, args: Object[ ]) SocialEvent, args: Object[ ]) 33 } Initiator <> 34 // ... <> + cfp(task: Task): void + accept(): void + << Artifact >> + rejecet(): void 35 } CommitToAcceptOr RejectIfPropose CommitToDoneOr Failure Artifact Operations CNP + cfp (proposal: Proposal) : void +action(): void +action(): void Participant 36 p u b l i c c l a s s P a r t i c i p a n t e x t e n d s PARole { + propose(proposal: Proposal): void + accept () : void + reject (): void SatisfyCommitTo FulfilledCommitTo + propose(proposal: Proposal): void 37 public void propose ( Proposal proposal , AcceptOrReject +action(): void AcceptOrReject +action(): void + refuse(task: Task): void + done(): void + failure(): void + + refuse(task: Task): void + done(): void 38 RoleId proposalSender ) { FulfilledCommitTo + failure(): void DoneOrFailure 39 // ... +action(): void 40 } Agent1 Behaviours Agent2 Behaviours 41 // ... 42 } 43 } Fig. 3. CNP with 2COMM4JADE and support for event handling. The following, instead, is a sketch of the definition of a JADE agent, playing the role Initiator by using 2COMM4JADE. In 10 public a b s t r a c t Behaviour this example, the artifact is created by the agent which, then, 11 fulfilledCommitToDoneOrFailure ( ) ; enacts the role of interest. At line 12, the agent uses the power 12 p u b l i c I n i t i a t o r B e h a v i o u r ( S t r i n g a r t i f a c t N a m e ){ 13 this . artifactName = artifactName ; cfp through the role it plays. Finally, at line 14, it inspects 14 } if someone committed to accomplish the task, and reads the 15 public void a c t i o n ( ) { proposals in the tuple space in order to make a choice. 16 A r t i f a c t I d a r t = Role . c r e a t e A r t i f a c t ( a r t i f a c t N a m e , 17 CNPArtifact . c l a s s ) ; 1 p u b l i c c l a s s I n i t i a t o r A g e n t e x t e n d s Agent { 18 i n i t i a t o r = ( I n i t i a t o r ) ( Role . e n a c t ( 2 // ... 19 C N P A r t i f a c t . INITIATOR ROLE , a r t , t h i s , 3 public class InitiatorBehaviour 20 myAgent . getAID ( ) ) ) ; 4 extends OneShotBehaviour { 21 i n i t i a t o r . startObserving ( this ); 5 // ... 22 myAgent . a d d B e h a v i o u r ( 6 public void a c t i o n ( ) { 23 t h i s . commitToAcceptOrRejectIfPropose ( ) ) ; 7 A r t i f a c t I d a r t = Role . c r e a t e A r t i f a c t 24 } 8 (ARTIFACT NAME , C N P A r t i f a c t . c l a s s ) ; 25 public void handleEvent ( SocialEvent e , 9 i n i t i a t o r = ( I n i t i a t o r ) ( Role . e n a c t 26 Object . . . args ) { 10 ( C N P A r t i f a c t . INITIATOR ROLE , a r t , t h i s , 27 SETemplate t = new SETemplate ( i n i t i a t o r . g e t R o l e I d ( ) ) ; 11 myAgent . getAID ( ) ) ) ; 28 t . iAmDebtor ( ) . c o m m i t I s D e t a c h e d ( ) ; 12 i n i t i a t o r . cfp ( t ) ; 29 t . m a t c h C r e d i t o r ( C N P A r t i f a c t . PARTICIPANT ROLE ) ; 13 // ... 30 t . m a t c h C o n s e q u e n t ( "accept OR reject" ) ; 14 boolean proposalPerformed = 31 i f ( t . match ( e ) ) { 15 i n i t i a t o r . existsCommitmentWithConsequent ( 32 myAgent . a d d B e h a v i o u r ( 16 new C o m p o s i t e E x p r e s s i o n ( 33 satisfyCommitToAcceptOrReject ( ) ) ; 17 L o g i c a l O p e r a t o r T y p e . OR, 34 } else { 18 new F a c t ( "done" ) , new F a c t ( "failure" ) ) ; 35 t . m a t c h C o n s e q u e n t ( "done OR failure" ) ; 19 // ... 36 i f ( t . match ( e ) ) 20 } 37 myAgent . a d d B e h a v i o u r ( 21 } 38 fulfilledCommitToDoneOrFailure ( ) ) ; 22 } 39 } 40 } More interesting is to exploit the feature of 41 } 2COMM4JADE, which allows roles to register for the notification of social events. Thanks to the event handler, After line 21, all events occurring in the social state are notified modifications to the social state will add specific behaviours to to the role Initiator, which will handle them by executing the agents, aimed at tackling the case. The code is organized handleEvent after a callback. The above abstract behaviour by following the schema described in Algorithm 1. Figure 3 is extended by the concrete behaviour of the agent that plays contains the UML diagram for this solution. the role Initiator. In particular, here we find the methods that create the actual behaviours for managing the social events. 1 public abstract class InitiatorBehaviour 2 extends OneShotBehaviour 1 p u b l i c c l a s s I n i t i a t o r A g e n t e x t e n d s Agent { 3 implements ProtocolObserver { 2 // ... 4 public String artifactName ; 3 public class InitiatorBehaviourImpl 5 protected I n it i a t or i n i t i a t o r ; 4 extends InitiatorBehaviour { 6 public a b s t r a c t Behaviour 5 p u b l i c f i n a l S t r i n g ARTIFACT NAME = "CNP-1" ; 7 commitToAcceptOrRejectIfPropose ( ) ; 6 public InitiatorBehaviourImpl () { 8 public a b s t r a c t Behaviour 7 s u p e r (ARTIFACT NAME ) ; 9 satisfyCommitToAcceptOrReject ( ) ; 8 } 9 public Behaviour commitToAcceptOrRejectIfPropose (){ The proposal is characterized, on the one hand, by the 10 r e t u r n new C o m m i t T o A c c e p t O r R e j e c t I f P r o p o s e ( flexibility and the openness that are typical of MAS, and, 11 initiator ); on the other, by the modularity and the compositionality that 12 } 13 p u b l i c B e h a v i o u r s a t i s f y C o m m i t T o A c c e p t O r R e j e c t ( ) { are typical requirements of the methodologies for design and 14 r e t u r n new S a t i s f y C o m m i t T o A c c e p t O r R e j e c t ( development. One of the strong points of the proposal is the 15 initiator ); decoupling between the design of the agents and the design 16 } of the interaction, that builds on the decoupling between com- 17 public Behaviour fulfilledCommitToDoneOrFailure (){ 18 r e t u r n new F u l f i l l e d C o m m i t T o D o n e O r F a i l u r e ( putation and coordination done by coordination models, like 19 initiator ); tuple spaces. This is a difference with respect to JADE where 20 } no decoupling occurs: a pattern of interaction is projected into 21 } a set of JADE behaviours, one for each role. Binding the 22 } interaction to ad-hoc behaviours does not allow having a global view of the protocol and complicates its maintenance. As an example, we describe the behaviour SatisfyCommitToAc- ceptOrReject, which gathers proposals and selects the one to Decoupling is an effect of explicitly representing social accept. relationships as resources: agent behaviour is, thus, defined 1 public c l a s s SatisfyCommitToAcceptOrReject based on the existing social relationships and not on the 2 extends OneShotBehaviour { process by which they are created. For instance, in CNP the 3 Initiator i n i t i a t o r = null ; initiator becomes active when the commitments that involve it 4 A r r a y L i s t

p r o p o s a l s = as a debtor, and which bind it to accept or reject the proposals, 5 new A r r a y L i s t

( ) ; are detached. It is not necessary to specify nor to manage, 6 public SatisfyCommitToAcceptOrReject ( 7 Initiator initiator ) { inside the agent, such things as deadlines or counting the 8 super ( ) ; received proposals: the artifact is in charge of these aspects. 9 this . initiator = initiator ; 10 } The difference with tuple spaces and CArtAgO itself 11 public void a c t i o n ( ) { is that 2COMM4JADE artifacts reify social relationships as 12 A r r a y L i s t p r o p o s = commitments, giving them that normative value that, jointly 13 i n i t i a t o r . r e c e i v e A l l ( ACLMessage . PROPOSE ) ; with the fact that by using an artifact an agent explicitly 14 f o r ( RoleMessage p : propos ) { 15 p r o p o s a l s . add ( ( P r o p o s a l ) ( p . g e t C o n t e n t s ( ) ) ) ; accepts the regulations encoded by it, enables the generation of 16 } expectations about the agents behaviour (as advised in [11]). 17 i n i t i a t o r . accept ( proposals . get ( 0 ) ) ; As such, it allows agents to reason and take decision also based 18 f o r ( i n t i = 1 ; i < p r o p o s a l s . s i z e ( ) ; i ++) { on the others’ expected behaviour. For instance, the presence 19 i n i t i a t o r . r e j e c t ( proposals . get ( i ) ) ; 20 } of a commitment C(i, p, propose, accept ∨ reject) grants the 21 } participant that its proposal will receive a feedback (it will 22 } either be accepted or rejected); if not, the initiator will be liable of a violation. In a tuple space, instead, agents can just read In 2COMM4JADE, an agent consists of a set of behaviours or write the shared blackboard but cannot have expectations aimed at accomplishing given social relationships: such be- on the behaviour of their parties. haviours depend neither on when nor on how the social This work has also relationships with works concerning relationships of interest are created inside the social state. e-institutions, like [15], [16], [20]. E-institutions introduce a These aspects are, in fact, encoded in the protocol artifact that normative aspect that lies on a different level with respect creates them based on the actions the agents perform. As a to the one we capture with commitments. Indeed, in our consequence, modifying how or when a social relationship is proposal the normative layer stands in the observational se- created does not have any impact on the agent implementation. mantics of the social actions. We mean to extend the regulative aspects, as a first step, by enriching commitment protocols V. C ONCLUSIONS AND D ISCUSSION as proposed in [18], [3]. More in general, we mean to move In this work, we have proposed 2COMM4JADE, an infras- towards a representation of business processes as suggested tructure for allowing actors to behave following an accepted set in the Comma methodology [26], where commitment patterns of regulations, in a self-governance context. 2COMM4JADE regulate activities instead of being used for giving the action is based on JADE, for what concerns the support to the semantics. Another advantage is that artifacts are an actual realization of interacting agents, and integrates self-governance system for implementing mediated interaction, they supply mechanisms by relying on the reification of commitments and efficient, simple, and direct means for checking the powers of commitment-based protocols. These are, at all respects, for performing institutional actions, and they offer runtime resources that are made available to stakeholders and that mechanisms for letting the agents perceive the state of the are realized by means of artifacts. We are working on an interaction. extension for Jason too, called 2COMM4Jason; details in [1]. Recently, we developed on top of 2COMM4JADE a R EFERENCES commitment-based typing system [2]. Such typing includes a notion of compatibility, based on subtyping, which allows for [1] Matteo Baldoni, Cristina Baroglio, and Federico Capuzzimati. Social computing in JaCaMo. In Torsten Schaub, Gerhard Friedrich, and Barry the safe substitution of agents to roles along an interaction that O’Sullivan, editors, ECAI 2014 - 21st European Conference on Artificial is ruled by a commitment-based protocol. Type checking can Intelligence, 18-22 August 2014, Prague, Czech Republic - Including be done dynamically when an agent enacts a role. Prestigious Applications of Intelligent Systems (PAIS 2014), volume 263 of Frontiers in Artificial Intelligence and Applications, pages 959–960. P. Yolum, L. Sonenberg, and P. Stone, editors, Proceedings of the IOS Press, 2014. 10th International Conference on Autonomous Agents and Multiagent [2] Matteo Baldoni, Cristina Baroglio, and Federico Capuzzimati. Typing Systems, AAMAS 2011, volume 2, pages 467–474, Taipei, Taiwan, May Multi-Agent Systems via Commitments. In M. B. van Riemsdijk, 2011. IFAAMAS. F. Dalpiaz, and J. Dix, editors, Proc. of the 2nd International Workshop [19] Viviana Mascardi, Maurizio Martelli, and Leon Sterling. Logic-Based on Engineering Multi-Agent Systems, EMAS 2014, held in conjuction Specification Languages for Intelligent Software Agents. Theory and with AAMAS 2014, pages 341–359, Paris, France, May 2014. IFAA- Practice of Logic Programming, 4(4):429–494, 2004. MAS. [20] Daniel Okouya, Nicoletta Fornara, and Marco Colombetti. An Infras- [3] Matteo Baldoni, Cristina Baroglio, Elisa Marengo, and Viviana Patti. tructure for the Design and Development of Open Interaction Systems. Constitutive and Regulative Specifications of Commitment Protocols: In M. Cossentino, A. El Fallah-Seghrouchni, and M. Winikoff, editors, a Decoupled Approach. ACM Transactions on Intelligent Systems and Engineering Multi-Agent Systems - 1st Int. Workshop, EMAS 2013, Technology, 4(2):22:1–22:25, March 2013. Revised Selected Papers, volume 8245 of Lecture Notes in Computer [4] Matteo Baldoni, Guido Boella, and Leendert van der Torre. Interaction Science, pages 215–234, St. Paul, Minnesota, USA, 2013. Springer. between Objects in powerjava. Journal of Object Technology, Special [21] Andrea Omicini, Alessandro Ricci, and Mirko Viroli. Artifacts in the Issue OOPS Track at SAC 2006, 6(2):5–30, 2007. A&A meta-model for multi-agent systems. Autonomous Agents and Multi-Agent Systems, 17(3):432–456, 2008. [5] Matteo Baldoni, Andrea Omicini, Cristina Baroglio, Viviana Mascardi, and Paolo Torroni. Agents, Multi-Agent Systems and Declarative [22] Andrea Omicini and Franco Zambonelli. TuCSoN: a coordination Programming: What, When, Where, Why, Who, How? In A. Dovier and model for mobile information agents. In D. G. Schwartz, M. Divitini, E. Pontelli, editors, Twenty-five Years of Logic Programming in Italy, and T. Brasethvik, editors, Proc. of the 1st Int. Workshop on Innovative volume 6125 of Lecture Notes in Computer Science, pages 204–230. Internet Information Systems (IIIS’98), pages 177–187, Pisa, Italy, 8–9 Springer, Berlin Heidelberg, 2010. June 1998. IDI – NTNU, Trondheim (Norway). [6] Fabio Bellifemine, Federico Bergenti, Giovanni Caire, and Agostino [23] Alessandro Ricci, Michele Piunti, and Mirko Viroli. Environment Poggi. JADE - A Java Agent Development Framework. In R. H. programming in multi-agent systems: an artifact-based perspective. Bordini, M. Dastani, J. JDix, and A. El Fallah-Seghrouchni, editors, Autonomous Agents and Multi-Agent Systems, 23(2):158–192, 2011. Multi-Agent Programming: Languages, Platforms and Applications, [24] Munindar P. Singh. An Ontology for Commitments in Multiagent volume 15 of Multiagent Systems, Artificial Societies, and Simulated Systems. Artificial Intelligence and Law, 7(1):97–113, 1999. Organizations, pages 125–147. Springer, Berlin Heidelberg, 2005. [25] Munindar P. Singh. A Social Semantics for Agent Communication [7] Guido Boella and Leendert W. N. van der Torre. The ontological Languages. In F. Dignum and M. Greaves, editors, Issues in Agent properties of social roles in multi-agent systems: definitional depen- Communication, volume 1916 of Lecture Notes in Computer Science, dence, powers and roles playing roles. Artificial Intelligence and Law, pages 31–45, Berlin Heidelberg, 2000. Springer. 15(3):201–221, 2007. [26] Pankaj R. Telang and Munindar P. Singh. Comma: a commitment- [8] Rafael H. Bordini, Lars Braubach, Mehdi Dastani, Amal El Fallah- based business modeling methodology and its empirical evaluation. In Seghrouchni, Jorge J. Gómez-Sanz, João Leite, Gregory M. P. O’Hare, W. van der Hoek, L. Padgham, V. Conitzer, and M. Winikoff, editors, In- Alexander Pokahr, and Alessandro Ricci. A Survey of Programming ternational Conference on Autonomous Agents and Multiagent Systems, Languages and Platforms for Multi-Agent Systems. Informatica (Slove- AAMAS 2012, pages 1073–1080, Valencia, Spain, 2012. IFAAMAS. nia), 30(1):33–44, 2006. [27] Alexander Thiele, Thomas Konnerth, Silvan Kaiser, Jan Keiser, and [9] Frances M. T. Brazier, Barbara Dunin-Keplicz, Nicholas R. Jennings, Benjamin Hirsch. Applying JIAC V to Real World Problems: The and Jan Treur. DESIRE: Modelling Multi-Agent Systems in a Compo- MAMS Case. In L. Braubach, W. van der Hoek, P. Petta, and sitional Formal Framework. Int. J. Cooperative Inf. Syst., 6(1):67–94, A. Pokahr, editors, Multiagent System Technologies, 7th German Con- 1997. ference, MATES 2009, volume 5774 of Lecture Notes in Computer [10] Amit K. Chopra. Commitment Alignment: Semantics, Patterns, and Science, pages 268–277, Hamburg, Germany, 2009. Springer. Decision Procedures for Distributed Computing. PhD thesis, North [28] Danny Weyns, Andrea Omicini, and James Odell. Environment as a Carolina State University, Raleigh, NC, 2009. first class abstraction in multiagent systems. Autonomous Agents and Multi-Agent Systems, 14(1):5–30, 2007. [11] Amit K. Chopra and Munindar P. Singh. An Architecture for Multiagent Systems: An Approach Based on Commitments. In Proc. of the AAMAS [29] Pinar Yolum and Munindar P. Singh. Commitment Machines. In Workshop on Programming Multiagent Systems (ProMAS), pages 184– J.-J. Ch. Meyer and M. Tambe, editors, Intelligent Agents VIII, 8th 202, Budapest, Hungary, May 2009. IFAAMAS. International Workshop, ATAL 2001, Revised Papers, volume 2333 of Lecture Notes in Computer Science, pages 235–247, Seattle, WA, USA, [12] Rosaria Conte, Cristiano Castelfranchi, and Frank Dignum. Au- 2002. Springer. tonomous Norm Acceptance. In J. P. Müller, M. P. Singh, and A. S. Rao, editors, Intelligent Agents V, Agent Theories, Architectures, and Languages, 5th Int. Workshop, ATAL ’98, volume 1555 of Lecture Notes in Computer Science, pages 99–112, Paris, France, 1999. Springer. [13] European Parliament. Directive 2004/39/EC of the European Parliament and of the Council of 21 April 2004 on markets in financial instruments. Official Journal of the European Union, L145:1–44, 2004. [14] Michael Fisher, Rafael H. Bordini, Benjamin Hirsch, and Paolo Torroni. Computational Logics and Agents: A Road Map of Current Technolo- gies and Future Trends. Computational Intelligence, 23(1):61–91, 2007. [15] Nicoletta Fornara, Francesco Viganò, and Marco Colombetti. Agent communication and artificial institutions. Autonomous Agents and Multi-Agent Systems, 14(2):121–142, 2007. [16] Nicoletta Fornara, Francesco Viganò, Mario Verdicchio, and Marco Colombetti. Artificial institutions: a model of institutional reality for open multiagent systems. Artificial Intelligence and Law, 16(1):89–105, 2008. [17] Foundation for Intelligent Physical Agents. FIPA Specifications, 2002. http://www.fipa.org. [18] Elisa Marengo, Matteo Baldoni, Cristina Baroglio, Amit K. Chopra, Viviana Patti, and Munindar P. Singh. Commitments with Regulations: Reasoning about Safety and Control in REGULA. In K. Tumer,