2.1 The BDI Agent Architecture
2.1.3 BDI Agent-Oriented Programming Languages
AgentSpeak(L) belongs to a class of formal languages called BDI agent-oriented programming languages. In this section, we will give an overview of the operational semantics of some of the popular BDI agent-oriented programming languages, namely, AgentSpeak(L) and its vari- ants, 3APL (Hindriks et al., 1999), 2APL (Dastani, 2008), GOAL (Hindriks et al., 2000), CAN (Winikoff et al., 2002), and the operational semantics of Wobcke (Wobcke, 2001). Unless other- wise stated, all these approaches use Plotkin’s structural single-step operational semantics (Plotkin, 1981).
AgentSpeak
An AgentSpeak(L) agent is created by the specification of a set of base beliefs, representing what the agent believes, and a set of plan-rules called the plan-library. The set of base beliefs are en- coded as a set of ground atoms. A plan-rule is associated with an event-goal (called an achievement
goal in AgentSpeak(L)) and contains procedural information on how to handle the corresponding
event-goal. This information is made up of entities such as primitive actions, which can be directly executed in the environment, and internal event-goals (non-primitive actions), which require fur- ther refinement before their corresponding primitive actions can be executed. The plan-rule can only be used to solve its associated event-goal if the plan-rule’s context condition is met in the current set of base beliefs, in which case the body of the plan-rule is adopted as an intention. This either amounts to instantiating and adding the body to a set of currently executing intentions (if
the event-goal is external), or updating an existing intention in the set with the new one (if the event-goal is internal).
More formally, an AgentSpeak(L) plan-rule is of the form +!g : ψ← P1; . . . ; Pn, where: +!g, called the triggering event, indicates that event-goal !g is handled by the plan-rule; ψ is the context condition; and each Pi is either (i) an operation +b or−b for respectively adding belief atom b to the agent’s set of base beliefs, or for removing b from the agent’s set of base beliefs, (ii) a primitive action act corresponding to any arbitrary operation, (iii) an event-goal !g′, or (iv) a test goal ?g′, which is used to test whether atom g′holds in the current set of base beliefs.
Because of errors and omissions in the semantics of AgentSpeak(L), many further BDI agent- oriented programming languages were developed, such as (Moreira and Bordini, 2002; d’Inverno and Luck, 1998; Moreira et al., 2003; Bordini et al., 2002; Hindriks et al., 1999; Winikoff et al., 2002; Wobcke, 2001). These either extend AgentSpeak(L), improve it, or are influenced by it in some way. In (d’Inverno and Luck, 1998), a complete syntax and semantics is given for AgentSpeak(L) using the Z specification language (Spivey, 1989). Z is chosen to make more explicit how one could implement AgentSpeak(L) — e.g., to shed some light on the kinds of data structures that could be used to represent an agent’s plan-rules. In addition, the authors also iden- tify and address certain mistakes in AgentSpeak(L) and details that were left out, such as a mistake regarding the situations under which the set of intentions can be executed, and details regarding how variables should be bound during execution.
While Z is useful as a specification language that sheds some light on implementation specific details, it is not well suited as a language for proving properties of agent systems (Moreira and Bordini, 2002). For this purpose, a complete operational semantics is proposed for AgentSpeak(L) in (Moreira and Bordini, 2002). This semantics incorporates certain features that were left out in AgentSpeak(L), such as semantics for how to execute belief operations +b and −b. Further
work on AgentSpeak(L) is done in (H ¨ubner et al., 2006), where, like (Winikoff et al., 2002) had done with the CAN language, the authors extend AgentSpeak(L) with the ability to handle failure (i.e., the ability to try alternative plan-rules to achieve an event-goal on the failure of its other plan-rules) and declarative goals, which capture more closely some of the desirable properties of goals put forth by Bratman, such as the requirement for goals to be persistent, possible and
unachieved. Failure handling is incorporated into AgentSpeak(L) via the triggering event-goal −!g, which the programmer can use to specify an alternative plan-rule for handling event-goal !g
if a standard plan-rule for handling it has failed; such failure handling plan-rules are of the form
−!g : ψ ← P1; . . . ; Pn. Declarative goals are added to AgentSpeak(L) without modifying the syntax or semantics of AgentSpeak(L). Instead, the authors identify different patterns for plan- rules. These patterns are used by the programmer to encode different types of declarative goals.
In (Bordini and Moreira, 2004), the authors prove that the revised version of AgentSpeak(L) proposed in (Moreira and Bordini, 2002) conforms to Bratman’s asymmetry thesis discussed ear- lier (recall that this basically required goals to be consistent with beliefs). Finally, in (Bordini et al., 2003), the authors introduce a restricted version of AgentSpeak(L) — called AgentSpeak(F) — and show how one can perform model checking (Clarke et al., 2000) on AgentSpeak(F). In particular, the authors show how guarantees can be obtained for the behaviour of AgentSpeak(F) agents, with respect to specifications expressed as logical formulae.
For example, it could be determined whether a meeting scheduler agent written in AgentSpeak(F), when given as input some person P and her available time slots for the week, is guaranteed to eventually either schedule the meeting for the per- son and notify her of success, or notify her of the failure to schedule the meet- ing. More specifically, it could be determined whether condition (Scheduled(P)∧ NotifiedOfSuccess(P))∨ NotifyFailure(P) holds at the end of all possible executions
of the agent.
3APL and 2APL
Another popular BDI agent-oriented programming language is 3APL (Hindriks et al., 1999). Like extended versions of AgentSpeak(L), 3APL also gives a clean and complete account of the op- erational semantics of a BDI agent-oriented programming language. In (Hindriks et al., 1998), the authors show that 3APL is more expressive than AgentSpeak(L), i.e., that any AgentSpeak(L) agent can be simulated by a corresponding 3APL agent, but that the converse does not hold. In addition to capturing the functionality of AgentSpeak(L), 3APL allows basic failure handling. Specifically, failure plan-rules (called failure rules in 3APL) can be written to handle failure, which have higher priority than standard plan-rules that handle event-goals. If both a failure plan- rule and a standard plan-rule are applicable in some situation, the failure plan-rule is tried instead of the standard plan-rule. 3APL also allows the specification of plan-rules which can be used to revise and monitor the agent’s existing intentions. For example, a plan-rule can be specified
which replaces all steps within a currently executing intention with the empty plan-body; such plan-rules can be used to drop existing intentions, which is a feature hinted by, but not addressed in AgentSpeak(L). In (van Riemsdijk et al., 2003; Dastani et al., 2003; van Riemsdijk et al., 2005), the authors extend 3APL to handle declarative goals.
2APL (Dastani, 2008) extends 3APL for implementing multi-agent systems. To this end, 2APL includes many new programming constructs, e.g., for implementing external actions and communication actions. Moreover, the semantics of failure rules is different in 2APL in that 2APL failure rules can be applied to revise only failed plan-rules, whereas in 3APL, failure rules can be used to revise any arbitrary plan-rule.
GOAL
While AgentSpeak and 3APL agents do not by default have declarative goals, the main feature of GOAL (Hindriks et al., 2000) agents is that they include declarative goals as part of the language, in the sense that goals describe a state that the agent desires to reach, rather than a task that needs to be performed. Moreover, while AgentSpeak and 3APL agents select predefined plans from a library, GOAL agents only select individual actions from a library. Like other agent-programming languages, actions are selected based on the agent’s current mental state. A GOAL agent, then, is the triplehΠ, σ0, γ0i, where Π is a set of actions, σ0 is a set of initial beliefs, and γ0 is a set of
initial (declarative) goals.
In addition to declarative goals, another key feature in the semantics of GOAL is the inclusion of a default commitment strategy (see Section 2.1.1), namely, the blind commitment strategy. Hence, a GOAL agent drops a goal if and only if it believes that the goal has been achieved. The programmer has the flexibility to use a different strategy if desired.
Operational semantics of Wobcke
In (Wobcke, 2001), Wobcke provides an operational semantics for PRS-like BDI agents, by for- malising the abstract BDI interpreter (Algorithm 2.1), rather than an implemented BDI system as done in AgentSpeak(L). The motivation for starting from the interpreter is to keep the seman- tics as close as possible to the cognitive descriptions of BDI agents in terms of concepts such as beliefs, desires, and goals. The operational semantics of (Wobcke, 2001) allows for convenient constructs within plan-rules such as if statements and while loops, and moreover, the semantics
makes more explicit the steps of the abstract interpreter. For example, theDeliberatefunction in line 4 of Algorithm 2.1 is defined as a function that returns an arbitrary plan-rule from those that have the highest priority amongst those in options, and theExecutefunction in line 6 is defined as one that executes one step of an intention and returns the remaining intention along with the state (beliefs) resulting from the execution. The semantics presented also allows basic failure handling, by forcing a failed action to be retried repeatedly until it succeeds.
CAN
In (Winikoff et al., 2002), the CAN (Conceptual Agent Notation) BDI agent-oriented programming language is introduced. CAN can be thought of as a superset of AgentSpeak(L), providing addi- tional features such as failure handling and declarative goals. To accommodate declarative goals, the plan language of CAN includes the construct Goal(φs, P, φf), which, intuitively, states that (declarative) goal φs should be achieved using (procedural) plan-body P, failing if φf becomes true. The operational semantics provided in (Winikoff et al., 2002) for goal-programs captures some of the desired properties of goals mentioned before, such as persistent, possible and un- achieved. For example, if the program P within goal-program Goal(φs, P, φf) has completed execution, but condition φs is still not true, then P will be re-tried; moreover, if φs becomes true during the execution of P, the goal-program will succeed immediately. While in variants of AgentSpeak(L) and in different versions of 3APL failure has to be explicitly programmed by the user via, respectively, the use of the triggering event-goal −!g and failure plan-rules, CAN has
sophisticated failure handling mechanisms built into the framework. This allows CAN agents to try alternative plan-rules to solve an event-goal when steps within a plan-body fail on execution, or when a plan-rule’s context condition is not met. Finally, unlike the operational semantics dis- cussed so far, CAN includes semantics for concurrency, allowing steps within intentions to be interleaved. For example, an intention to go out for a movie can be interleaved with the intention to buy bread, by buying bread on the way to (or on the way back from) the movie, as opposed to buying bread before leaving for the movie or after reaching home from the movie.