3APL: A Goal-Oriented Multi-Agent Programming Language
Programming Language for Cognitive Agents Data Structures to represent agent state 3APL Mental State Beliefs : General and specific Information about environment Goals : Objectives that agent want to reach Capabilities : Actions that agent can perform Plans : Procedures to achieve objectives Reasoning rules : Reason about goals and plans Planning goal rules: how to achieve goals Plan revision rules: how to modify plans
Programming Language for Cognitive Agents Programming Instructions to manipulate Data Structures 3APL Programming Constructs to process mental states Select Goals Plan Goals Select Plans Execute Plans Select Rules Apply Rules Agent Interpreter or Agent Deliberation Cycle is a loop consisting of such instructions. The loop determines the behavior of the agent.
3APL Architecture Belief Base Goal Planning Rule Base Goal Base Deliberation Process Plan Base Action Base Plan Revision Rule Base
3APL Deliberation Cycle Start Applying Goal Planning Rules Find PGrules matching goals Rules found? yes Select PGrules matching beliefs Rule selected? yes Apply PGrule no no Sleep until a message arrives no yes Find PRrules matching plans Rules found? yes Select PRrules matching beliefs Applying Plan Revision Rules Rule selected? yes Apply PRrule Rules applied or plans executed? Select plan no Plan selected? Executing Plans yes Execute plan no no
Part I Syntax and Examples
Syntax: belief base BB and goal base GB languages L is the set of first-order literals ψ L + ground (positive literals) ψ 1,..., ψ m L ground (ground literals) φ L + φ 1,..., φ n L BB: GB: ψ x1,...,x n (φ 1... φ n φ) BB ψ 1... ψ m GB x1,...,x n (ϕ) denotes the universal closure of the formula ϕ for every variable x 1,..., x n occurring in ϕ.
Belief Base: An Example c a fl b BB Prolog on(a, fl) on(b, fl) on(a,fl). on(b,fl). on(c, a) clear(b) on(c,a). clear(b). clear(c) clear(fl) clear(c). clear(fl). x, y : on(x, y) y = fl clear(y) clear(y) :- Not on(x,y), Not same(y,fl).
Syntax: Query Language belief query B: if φ 1,..., φ n L +, then B(φ 1... φ n ), B(φ 1... φ n ) Disjunction, Disjunction, if δ, δ Disjunction, then δ δ Disjunction, if δ Disjunction, then δ L B, if β, β L B, then β β L B goal query G: if φ 1,..., φ n L +, then G(φ 1... φ n ) L G, L G, if κ,κ L G, then κ κ L G.
Belief Query: An Example BB: on(a, b) on(b, fl) on(c, fl) x, y : on(x, y) y = fl clear(y) BELIEFBASE: on(a,b). on(b,fl). on(c,fl). clear(y) :- Not on(x,y), Not same(y,fl). B(clear(b)) B(on(a, fl) on(b, fl)) clear(b) on(a,fl) and on(b,fl)
Goal Query: An Example GB: on(a, b) on(b, c), on(d, b) GOALBASE: on(a,b) and on(b,c), on(d,b) G(on(a, b)) on(b, c)) G(on(a, b)) G(on(d, b)) on(a,b) and on(b,c) on(a,b), on(d,b)
Syntax: Actions Mental actions: L ma = { β, α(t 1,..., t n ), (β 1,..., β n ) β L B, β 1,..., β n L, α MentActName, t 1,..., t n Terms} CAPABILITIES: { on(block,from) and clear(to) } Move(Block,From,To) {not on(block,from), on(block,to), clear(from), not clear(to) }
Syntax: Actions External actions: L ea = {Ext(t 1,..., t n ) Ext ExtActName, t 1,..., t n Terms} Java(blockworld,move to(x,y),result) Communication actions: L ca = {Send(r, p, φ) r Aname, p P, φ L + } Send(a,inform,computer(500)) Actions = L ma L ea L ca
Communication Actions: An Example Agent a BELIEFBASE: at time t GOALBASE: Send(b,inform,computer(500)) Agent a BELIEFBASE: sent(b,inform,computer(500)) at time t+1 GOALBASE: Agent b BELIEFBASE: received(a,inform,computer(500)) at time t+1 GOALBASE:
Syntax: Plans empty plan: basic action: test: abstract plan: composite plans: E Plans, Actions Plans, if β L B, then β? Plans, if ρ is a plan name, t 1,..., t n Terms, then ρ(t 1,..., t n ) Plans, if π 1, π 2 Plans and β L B, then π 1 ; π 2, if β then π 1 else π 2 fi, while β do π 1 od Plans PLANBASE: {on(c, A)?; Move(C, A, Fl); Move(A, Fl, B)} {if on(c, A) then Move(C, A, Fl); Move(A, Fl, B) else Move(A, Fl, B)}
Syntax: Planning Goal Rules If β L B, κ L G, and π Plans, then planning goal rules have the following form: κ β π PlanningRules G(on(x, z)) B(on(x, y)) Move(x, y, z) PG-RULES: pos(0,0) <- true { While NOT pos(0,y) Do {GoLeft()}; While NOT pos(x,0) Do {GoUp()} }
Syntax: Plan Revision Rules If β L B and π h, π b Plans, then rules to reason with plans have the following form: π h β π b PlanRevisionRules Move(x, y, z) B(clear(z)) on(u, z)?; Move(u, z, Fl); Move(x, y, z) PR-RULES: GoLeft();X <- pos(0,y) {X} While NOT pos(0,0) Do {GoLeft();GoUp} <- true { While NOT pos(0,0) Do {GoUp;GoLeft()} }
Part II Formal Semantics
Semantics : Agent Configuration Agent Configuration: ι,σ, γ, Π,θ,ξ ι Agents σ L (grounded and consistent) γ {φ i... φ j φ i, φ j,... Atomic} (grounded) such that φ γ : φ = & σ = φ Π Plans θ { [x i /t i ] x i Var, t i Terms, x i Free(t i ) i = j x i = x j } ξ {q(t 1,..., t n ) q R ξ, t 1,..., t n Terms} where R ξ is a set of relations specifying the environment ξ
Semantics : Transition System Transitions between System Configuration ι,σ, γ, Π,θ,ξ ι,σ, γ, Π,θ,ξ Transitions are derived by Transition Rules ι,σ 1, γ 1, Π 1,θ 1,ξ 1 ι,σ 1, γ 1, Π 1,θ 1,ξ 1 ι,σ, γ, Π,θ,ξ ι,σ, γ, Π,θ,ξ Condition ι,σ, γ, Π,θ,ξ ι,σ, γ, Π,θ,ξ
Semantics: Beliefs and Goals (B and G) ι,σ, γ, Π,θ,ξ = ι,σ, γ, Π,θ,ξ = τ Bφ σ = φτ where Var f (φ) dom(τ) ι,σ, γ, Π,θ,ξ = Bφ τ : ι,σ, γ, Π,θ,ξ = τ Bφ ι,σ, γ, Π,θ,ξ = τ δ δ ι,σ, γ, Π,θ,ξ = τ δ or ι,σ, γ, Π,θ,ξ = τ δ ι,σ, γ, Π,θ,ξ = τ β β ι,σ, γ, Π,θ,ξ = τ β and ι,σ, γ, Π,θ,ξ = τ β ι,σ, γ, Π,θ,ξ = Gφ γ = φτ and σ = φτ where Var f (φ) dom(τ) ι,σ, γ, Π,θ,ξ = κ κ ι,σ, γ, Π,θ,ξ = κ and ι,σ, γ, Π,θ,ξ = κ
Example ι, {on(a, b), on(c, fl)}, γ, Π,θ,ξ = B on(a, b) {on(a, b), on(c, fl)} = on(a, b) ι, {on(b, fl)}, {on(a, b) on(b, c), on(c, fl)}, Π,θ,ξ = G on(a, b) {on(a, b) on(b, c)} = on(a, b) and {on(b, fl)} = on(a, b)
Semantics: Mental Actions (α) ι,σ, γ, {(α,κ)},θ,ξ = τ β & T (αθτ,σ) = σ ι,σ, γ, {(α,κ)},θ,ξ ι,σ, γ, {(E,κ)},θ,ξ where γ = γ\{φ γ σ = φ}
Semantics: Mental Actions (α) where ι,σ, γ, {(α,κ)},θ,ξ = τ β ι,σ, γ, {(α,κ)},θ,ξ ι,σ, γ, {(E,κ)},θ,ξ T (αθτ,σ) = σ & γ = γ\{φ γ σ = φ} Example: Assume update function T to be specified by: {pos(x, Y)} Left() {NOT pos(x, Y), pos(x 1, Y)} Then, ι, {pos(2, 3)}, γ, {(Left(),κ)},θ,ξ
Semantics: Mental Actions (α) where ι,σ, γ, {(α,κ)},θ,ξ = τ β ι,σ, γ, {(α,κ)},θ,ξ ι,σ, γ, {(E,κ)},θ,ξ T (αθτ,σ) = σ & γ = γ\{φ γ σ = φ} Example: Assume update function T to be specified by: {pos(x, Y)} Left() {NOT pos(x, Y), pos(x 1, Y)} Then, ι, {pos(2, 3)}, γ, {(Left(),κ)},θ,ξ ι, {pos(1, 3)}, γ, {(E,κ)},θ,ξ
Semantics: Communication Actions (Send) The transition rule for the Send action: ϕ =< s, r, p, ψ > & σ = {sent(r, p, ψ)} ι,σ, γ, {(Send(r, p, ψ),κ)},θ,ξ The transition rule for receiving messages: ϕ =< s, r, p, ψ > & ι = r ϕ! ι,σ σ, γ, {(E,κ)},θ,ξ ι,σ, γ, Π,θ,ξ ϕτ? ι,σ {received(sτ, pτ, ψτ)}, γ, Π,θ,ξ The transition rule for synchronization: A i,ξ ψτ? A i,ξ, A j,ξ ϕ! A j,ξ, ψτ = ϕ {A 1,..., A i,..., A j,..., A n },ξ {A 1,..., A i,..., A j,..., A n},ξ
Semantics: Test Plans (β?) Example: σ = βθτ ι,σ, γ, {(β?,κ)},θ,ξ ι,σ, γ, {(E,κ)},θτ,ξ ι, {pos(1, 2)}, γ, {(pos(x, Y )?,κ)},{[x /1]},ξ
Semantics: Test Plans (β?) Example: σ = βθτ ι,σ, γ, {(β?,κ)},θ,ξ ι,σ, γ, {(E,κ)},θτ,ξ ι, {pos(1, 2)}, γ, {(pos(x, Y )?,κ)},{[x /1]},ξ ι, {pos(1, 2)}, γ, {(E,κ)},{[X /1], [Y /2]},ξ
Semantics: Planning Goal Rule Let the rule κ β π be a variant of a goal rule Example: ι,σ, γ, Π,θ,ξ = τ1 κ & ι,σ, γ, Π,θ,ξ = τ2 βτ 1 ι,σ, γ, Π,θ,ξ ι,σ, γ, Π {(πτ 1 τ 2,κτ 1 )},θ,ξ goto(r) pos(r ) AND door(r, R) Go(R) ι, {pos(r1), door(r1, r2)}, {goto(r2)}, Π,θ,ξ
Semantics: Planning Goal Rule Let the rule κ β π be a variant of a goal rule Example: ι,σ, γ, Π,θ,ξ = τ1 κ & ι,σ, γ, Π,θ,ξ = τ2 βτ 1 ι,σ, γ, Π,θ,ξ ι,σ, γ, Π {(πτ 1 τ 2,κτ 1 )},θ,ξ goto(r) pos(r ) AND door(r, R) Go(R) ι, {pos(r1), door(r1, r2)}, {goto(r2)}, Π,θ,ξ ι, {pos(r1), door(r1, r2)}, {goto(r2)}, Π {(Go(r2), goto(r2))},θ,ξ
Example of a 3APL Program Execution PROGRAM "agent name" CAPABILITIES: { p } α 1 { p } { q } α 2 { q } { q } α 3 { q } BELIEFBASE: p q GOALBASE: g 1, g 2 PLANBASE: α 1 ;α 2 PG-RULEBASE: g 1 p q α 1 ;α 2 g 2 p α 3 PR-RULEBASE: α 2 q α 3 ;α 2
Example of a 3APL Program Execution Actions Beliefs Goals Plans PG-Rules PR-Rules {p}α 1 { p} p q g 1, g 2 α 1 ;α 2 g 1 p q α 1 ;α 2 α 2 q α 3 ;α 2 {q}α 2 { q} g 2 p α 3 { q}α 3 {q} p q p, q p, q p, q p, q p, q α 1 ;α 2 α 2 ɛ α 3 ɛ α 1 ;α 2... g 1, g 2 g 1, g 2 g 1, g 2 g 1, g 2 g 1, g 2 g 1, g 2 p q p, q p, q p, q p, q α 1 ;α 2 α 2 α 2,α 3 α 3 ɛ g 1, g 2 g 1, g 2 g 1, g 2 g 1, g 2 g 1, g 2