# Programming Agents by Their Social Relationships: A Commitment-Based Approach
## 4 A Conceptual Schema for Programming Agents with Social Relationships
### Programming Schema for Help-Seeking Agents  
The need for cooperation justifies a general programming schema for agents that use social relationships (i.e., commitments), for having their goals satisfied by other agents. The aim of the schema is, thus, to implement one (or more) social behaviors that allows an agent \(ag\) to achieve a goal \(G\) by cooperating with other agents. The schema consists of the following cases:  
1. _Entice_: * _Intent_: Finding the cooperation of another agent by making an offer. * _Applicability_: When, by inspecting the workspace, the agent does not discover cooperation offers by other agents that support the achievement of its goal adequately, then the agent creates an offer itself. * _Implementation_: Implement a behavior that creates a commitment \(C(ag,other,G,q)\), where \(ag\) is the help-seeking agent, \(other\) is another agent in the system, and \(q\) is a condition that \(ag\) can bring about, either directly or via the cooperation with others. 2. _Cooperate_: * _Intent_: contributing to a collaboration by making a commitment progress towards satisfaction. * _Applicability_: when the agent is either the debtor or the creditor of an active commitment. * _Implementation_: * _When \(ag\) is the creditor: implement a behavior that is triggered by the creation of a commitment \(c:C(other,ag,p,G)\) and that brings about \(p\), so as to detach \(c\). * When \(ag\) is the debtor: implement a behavior that is triggered by the detachment of a commitment \(c:C(ag,other,G,q)\) and that brings about \(q\) so as to satisfy \(c\). Note that the _Cooperate_ schema could be generalized to capture the whole standard lifecycle of a commitment. For instance, a creditor agent could also implement a behavior for releasing a commitment or when a commitment is violated, but these are choices that are driven by a local decision strategy of the agent. Example 2: A Logistics Scenario (Continued)  
Let us explain how the schema is applied to the previously-introduced logistic scenario. For the purpose of generality, we use an abstract language based on ECA rules (Event, Condition, Action), for expressing the agents' behaviors. Intuitively, an ECA rule has the following syntax: \(event:condition\gets action\). The event denotes the trigger for activating such a rule; in general, it is a goal that the agent wants to achieve or an event that must be properly treated by the agent. The condition is a contextual circumstance that must hold for the rule to be actually fired. Finally, the action is a course of operations that modify the environment so as to obtain a desired effect. In Section 4, we will show how these abstract behaviors can be implemented in the JADE and JaCaMo platforms. Let us take the \(seller\)'s perspective, who wants to get some money by selling goods. It can do so by exploiting the \(Entice\) schema, in such a way to create a commitment \(c_{1}:C(seller,\)\(customer,\)\(pay(500,\)\(seller),\)\(at(goods,\)\(D))\) to make an offer to a potential customer. This could be captured by the ECA rule: \(ON\)\(need\_money\)\(IF\)\(have\_goods\_to\_sell\)\(DO\)create\((c_{1}:C(seller,customer,pay(500,seller),at(goods,D)))\)  
The use of the entice schema is strictly connected to the use of the _Cooperate_ one, which allows tackling the relevant commitment state changes. Let us assume that \(seller\) is only interested in a change from conditional to detached. The ECA rule would be:\(ON\)\(\mathtt{detached}(c_{1})\)\(IF\)\(true\)\(DO\)\(bring\_goods\_at\_D\). The triggering event is the detachment of commitment \(c_{1}\), that is _customer_ has paid for the goods. The contextual condition is true, meaning that the agent is always eager to react to such an event (but domain-dependent conditions could be specified). The action \(bring\_goods\_at\_D\) stands for a plan for delivering the goods to the customer. That is, the effect of the plan would be \(at(goods,D)\), which satisfies the commitment.