Professional Documents
Culture Documents
DALI Handbook
DALI Handbook
DALI Handbook
Examples
How the DALI Interpreter starts
active_dali.pl/
agent.bat
active_server.pl/
server.bat
...
active_user.pl/
user.bat
active_dali.pl/
agent.bat
In order to start the DALI Multiagent System it’s necessary to activate the server,
next the user module, finally one or several DALI agents.
How the Server starts active_server.pl/
active_server.exe
active_user.pl
DALI
active_server.pl
program
file_dali.txt
active_dali_wi.pl
We can activate the DALI server either by invoking the the executable file
‘server.bat’ or, via the Sicstus Prolog shell, by loading the file ‘active_server.pl’.
This is the command to load the server, that you can fond in the demo directory:
We can activate the DALI user module either by using the ‘user.bat' executable
file or, via the Sicstus Prolog shell, by loading the file ‘active_user.pl’.
This is the command to load the file that you can find in the demo directory:
The user module opens a user window for communicating with DALI agents, as
explained later on.
We can activate the DALI Interpreter either by using the executable file
‘agent.bat’.
If the paths of the initialization file and of the current installation of Sicstus
Prolog set in the batch file are right, the agent will be activated:
Initialization file
help.txt
initialization_files
dali
active_user.pl
active_server.pl
program
DALI logic program
help.txt
In this way it is possible to activate several DALI
agents having different names and logic programs.
active_dali_wi.pl
DALI initialization file
The initialization file <init>.txt must be in the directory
“initialization_dali_files”, and contains the following
informations:
The name of the file that contains the DALI logic program;
The name of the agent;
The adopted ontology ('no' if no ontology is used);
The adopted language (Italian,English,…) in the
communication acts;
The name of the file containing the tell/told communication
constraints;
The name of the communication library;
The agent’s abilities ( kind of work, hobbies,…)
agent('demo/program/italian',gino,
'../onto/gino.onto',italian,
['demo/communication'],
['demo/communication_fipa'],[tourist]).
Precisely:
In the initialization string (see above) we put the initialization file under the
directory 'initialization_dali_files' and the DALI logic program file
file_dali.txt’ in the directory program:
communication.con
DALI
communication_fipa.txt
ONTO
file_dali.onto
program
file_dali.txt
active_dali_wi.pl
How the User Module works active_user.pl/
active_user.exe
The user module allows the user to communicate with an existing DALI
agents, by means of the DALI primitive send_message(Content,Sender) where
Sender=user and Content is an external event we want the agent to perceive.
will ask the following arguments:
If we have for instance, in the DALI logic program, the following reactive rule:
dangerE:>once(ask_for_help).
ask_for_help:-call_policeA.
call_police:<have_a_phoneP.
ask_for_help:-screamA.
If we tell the agent that ‘pericolo’ is equivalent to ‘danger’, we can then send
the message send_message(pericolo,user).
Insert From
|: user.
Insert message
|: send_message(pericolo,user).
Write DALI logic program
A Dali program is a file txt whose content is a DALI program.
Now we shortly recall the main features of this language by writing a DALI
agent:
External events:
alarm_clock_ringsE:>stand_upA
the agent observes the following behavior. We use the user module to
send to the agent the external event alarm_clock_rings.
Write DALI logic program:External Event
Insert name of addressee
|: pippo.
Insert From Nome file: alarm.txt
|: user.
Insert message
|: send_message(alarm_clock_rings,user).
make(stand_up)
Internal events:
i_am_lazy:-alarm_clock_ringsP
not(stand_upP)
i_am_lazyI:> i_take_a_vacation_dayA.
the agent exhibits the following behavior. We use the user module to
send to the agent the past event alarm_clock_ringsP but this past event
could be the past form of the external event as specified in the previous
paragraph, and arrived before.
Write DALI logic program:External Event
Insert name of addressee
|: pippo.
Insert From Nome file: alarm_clock.txt
|: user.
Insert message
|: confirm(alarm_clock_rings,user).
make(i_take_a_vacation_day)
The DALI agent will make the action contained in the reaction
of the internal event.
Write DALI logic program:Present Event
Present events:
When an agent perceives an event from the external world it does not
necessarily react to it immediately: she has the possibility of reasoning on the
event, before (or instead of) triggering a reaction. Reasoning also allows a
proactive behavior. In this situation, the event is called present event and is
indicated by the suffix N.
arrives_someone:-bell_ringsN.
arrives_someoneI:>get_dressedA.
get_dressed:< get_undressedP.
bell_ringsE:>open_the_doorA.
In this case, when we send the external event bell_rings to the agent,
she makes the actions get_dressed and open_the_door if the internal
event has been processed before the external event. Else, she does only
the action open_the_door. In small DALI programs is unlikely to observe
the reaction to the internal event, because the processing of the external
events is faster and the interpreter, after the action open_the_door,
erases the reaction to the internal event.
Write DALI logic program:Present Events
Insert name of addressee
|: pippo.
Insert From Nome file: wear.txt
|: user.
Insert message
|: send_message(bell_rings,user).
make(open_the_door)
make(open_the_door)
make(open_the_door)
make(open_the_door)
make(get_dressed)
make(open_the_door)
make(open_the_door)
make(open_the_door)
make(open_the_door)
Write DALI logic program:Actions
Actions:
Simple actions:
The action in the DALI program is specified as actionA.
For example i_go_to_bedA, i_take_the_busA, …
When the agent does an action, on the prolog shell you can
observe make(action).
Messages as actions:
From a DALI program, a message can be sent by writing:
messageA(To, Content)
o send_message(External_event, Sender)
this primitive is used to call an external event within a reactive
rule;
o confirm(Assertion, Sender)
this primitive is used to assert a fact within a DALI agent;
o disconfirm(Assertion, Sender)
this primitive is used to retract a fact within a DALI agent;
o propose(Action, List_Conditions,Sender)
this primitive is used to propose an agent to do an action
contained within a DALI program. The agent can respond by
accepting to do the action (accept_proposal) or by rejecting the
proposal (reject_proposal) if the conditions in the message are
false. When the agent decides to make the action, she verifies if
the conditions of the action rule are true. In this case, the agent
does the action or else she sends to the other agent a failure
message.
Write DALI logic program:Actions
o execute_proc(Head, Sender)
this primitive is used to invoke the head of a generic rule
(procedure) in the DALI program;
o query_ref(Fact, N, Sender)
this primitive is used to answer an agent on some information
about a not ground Fact. N is the number of the requested
matchings;
o agree(Fact, Sender)
this primitive is used to answer an agent knowing a ground
Fact;
o cancel(Action, Sender)
this primitive is used to communicate to an agent to cancel a
requested action. Also in this case, it is difficult to see the effect
of this primitive because the agent does immediately the action.
To see the effect, the queue of actions must contain several
items.
Write DALI logic program: Goals
A goal is an objective that an agent must reach. In the DALI language, a goal is
a particular internal event that the interpreter begins to attempt when it is
invoked. The goal has a postfix G.
How it works:
Environment State
...,goal1G,...
goal1:- condition11,...,condition1k
Goal Plan to reach a goal
subgoal11G,...,subgoal1NG,
PLANNER
subgoalP11,...,subgoalP1N.
...
goal1:-conditionm1,...,conditionmk
subgoalGm1,...,subgoalGmN,
subgoalP11,...,subgoalP1N.
Actions
goal1I:>action1,...,goal2G,...,actionk.
Write DALI logic program: Goals
We consider a simple example: an agent must wear socks and shoes.
goE:>put_shoesG.
put_shoes:-
put_right_shoeG,put_left_shoeG,right_shoe_onP,
left_shoe_onP.
put_shoesI:>left_and_right_shoes_onA,
retractall(past(_,_,_)).
put_right_shoe:-put_right_sockG,right_sock_onP.
put_right_shoeI:>right_shoe_onA.
put_left_shoe:-put_left_sockG,left_sock_onP.
put_left_shoeI:>left_shoe_onA.
put_right_sock:-have_right_sockP.
put_right_sockI:>right_sock_onA.
put_left_sock:-have_left_sockP.
put_left_sockI:>left_sock_onA.
Write DALI logic program: Goals
Insert name of addressee Insert name of addressee Insert name of addressee
|: pippo. |: pippo. |: pippo.
Insert From Insert From Insert From
|: user. |: user. |: user.
Insert message Insert message Insert message
|: confirm(have_left_sock,user). |:confirm(have_right_sock,user). |: send_message(go,user).
make(right_sock_on)
make(right_shoe_on)
make(left_sock_on)
make(left_shoe_on)
make(left_and_right_shoes_on)
Write DALI logic program: Past events
Past events:
Pre-processing file.txt
Communication
module
Processing
Events
Actions
Goals
Communication
module
The files that the interpreter generates from
DALI txt file
file.ple
file.txt file.plf
file.pl
The DALI interpreter generates some auxiliary files for each agent. These files
are put in the same directory as the txt DALI file.
A simple txt DALI file
We use this txt file to show how the interpreter works creating ple, plf and
pl files. In order to show the ‘naming’ process we use a new example
containing variables.
External event
remain_at_home:-dangerP,call_policeP.
remain_at_homeI:>go_to_bathroomA,
close_the_doorA.
go_out:-dangerP,screamP.
go_outI:>go_to_neighbourA. Action
Internal event
What the Interpreter records in the ple file
[remain_at_home,go_out,external_refused_action_propose(A,Ag),
refused_message(AgM,Con)]. Internal events
[call_police,scream,go_to_bathroom,close_the_door,go_to_neighbour,message(Ag,in
form(query_ref(X,N),values(L),A)),message(Ag,refuse(query_ref(variable),motivatio
n(refused_variables),A)),message(Ag,inform(query_ref(X,N),motivation(no_values),
A)),message(Ag,inform(agree(X),values(yes),A)),message(Ag,inform(agree(X),value
s(no),A))…].
[call_police]. Conditions
Actions
[]. Present events
eve(predator_attacks(var_X)):-
once(try_to_escape(var_X)).
try_to_escape(var_X):- a(fly(var_X)).
try_to_escape(var_X):- a(run(var_X)).
cd(fly(var_X)):- evp(bird(var_X)),
not(evp(abnormal(var_X))).
k
or
w
t er
Dali txt program re
rp
te
predator_attacksE(X):> In
once(try_to_escape(X)).
try_to_escape(X):-flyA(X). The interpreter generates a pl file
try_to_escape(X):-runA(X). where all rules are subjected to
fly(X):<birdP(X),not(abnormalP(X)). ‘naming’ process. All variables has
been transformed to costants using
the suffix ‘var_’.
The directives of plf file
We use this file to set some parameters that determine the behavior of
the agent relatively to external, internal, past events and actions .
past_event(Event,Seconds). external_event(Event,normal).
(the past event is kept in memory some Seconds)
external_event(Event,high).
past_event(Event,forever).
(the past event is kept in memory forever)
past_event(Event,until(Cond)).
(the past event is kept in memory until Condition) Action
Internal event
We can set several parameters for an internal event in order to tune the
Interpreter behaviour:
o the frequency(seconds) with which the interpreter attempts the internal event;
o how many times the agent must react if the internal event is true (1,2,..,forever);
o when the agent must react: this parameter is ‘true’ if the reaction must happen
forever or else we can link the reaction to some past events belonging to body
of the first rule of the internal event; when the past event inside a ‘change list’
is modified the agent will be able to react again.
For example, if we have the internal event:
think:-rainP, go_outP,buy_umbrellaP.
thinkI:>open_the_umbrellaA.
internal_event(remain_at_home,3,forever,true,until_cond(past(remain_at_home))).
internal_event(go_out,3,forever,true,until_cond(past(go_out))).
mod(message(_,inform(_,motivation(refused_message),_)),check).
DALI INTERNAL
INTERPRETER
Outcoming message
The Told Check level
Incoming message
TOLD CHECK
Each DALI agent has a ‘con’ file, specified in the initialization file, that contains the
told/tell rules. These rules, external to interpreter, can be modified by the user.
The structure of a told rule is:
told(Sender,Content):-constraint 1,…,constraintn.
In this example, an agent receives a message, using the primitive send_message, only
if the Sender agent isn’t an enemy:
told(Ag,send_message(_)):-not(enemyP(Ag)).
A message that does not go through the told level is eliminated. The agent
Sender receives an inform message asserted as a past event.
The Meta-Level
META LEVEL
Each DALI agent uses an (optional) meta procedure written in the ‘communication.con’ file that
specifies how the entity can interprete an unknown message. This procedure can be
modified by the user.
In the initialization file the user can specify the ontology file that contains informations about the
ontology that the agent must use. This file contains informations about the location of the
ontology ( remember that ontologies are used by means of Sesame semantic repositories ).
TELL CHECK
Outcoming message
The user can set the mod string in the plf file in order to submit a message to tell check.
In this case, the message is actually sent only if the corresponding tell rule is true.
The tell rules can be modified by the user.
The structure of a tell rule is:
tell(Receiver,Sender,Content):-constraint 1,…,constraintn.
In this example, an agent sends a message, using the primitive send_message, only
if she has a trust greater than 4 in the Receiver agent:
tell(To,_,send_message(_)):-trustP(_,To,N),N>4.
One Agent!
Examples – A dangerous situation…
Initialization file name: help.txt
DALI logic file name: help.txt
initalization_files help.txt
active_user.pl
DALI
active_server.pl
program
help.txt
active_dali.pl
Examples – A dangerous situation…
dangerE:>once(ask_for_help).
ask_for_help:-call_policeA.
call_police:<have_a_phoneP.
ask_for_help:-screamA.
remain_at_home:-dangerP,call_policeP.
remain_at_homeI:>go_to_bathroomA,
close_the_doorA.
go_out:-dangerP,screamP.
go_outI:>go_to_neighbourA.
Examples – A dangerous situation…
make(scream)
make(go_to_neighbour)
Examples – A dangerous situation…
make(call_police)
make(go_to_bathroom)
make(close_the_door)
Examples – Error Recovery planning…
Two Agents!
Examples – Error Recovery planning…
Initialization file name: recovery.txt and sensor.txt
DALI logic file name: recovery.txt and sensor.txt
initalization_files sensor.txt
recovery.txt
active_user.pl
DALI
active_server.pl
sensor.txt
program
recovery.txt
active_dali.pl
Examples – Error Recovery planning…
error_recovery(M,M1):-
go_rightP(_,M),goal(M),informP(reality(M,M1),sensor),M\=M1.
error_recovery(M,M1):-
go_leftP(_,M),goal(M),informP(reality(M,M1),sensor),M\=M1.
error_recovery(M,M1):-
go_forwardP(_,M),goal(M),informP(reality(M,M1),sensor),M\=M1.
error_recoveryI(M,M1):>recovery_errorA(M,M1),drop_pastA(reality(M,M1)).
reached_goal(M):-go_rightP(_,M),goal(M).
reached_goal(M):-go_leftP(_,M),goal(M).
reached_goal(M):-go_forwardP(_,M),goal(M).
reached_goalI(M):>clause(agent(Ag),_),
messageA(sensor,send_message(what_about_my_position(M,Ag),Ag)).
…
right(exit1,bank1).
right(exit2,bank2).
left(bank1,hospital1).
forward(bank2,bank1).
goal(hospital1).
Examples – Error Recovery planning…
what_about_my_positionE(M,Ag):>once(examine_position(M,Ag,_)).
examine_position(M,Ag,M1):-
messageA(Ag,inform(reality(M,M1),sensor)),wrong_positionA(M,Ag).
message(_,inform(reality(M,M1),sensor)):<errorP(M,M1).
examine_position(M,Ag,_):-right_positionA(M,Ag).
Error Recovery planning
The environment…
Hospital
Bank2 Bank1
Exit2 Exit1
STATION
Error Recovery planning
Bank2 Bank1
confirm(i_am_at_exit(exit1),user)
STATION
Examples – Error Recovery planning…
Run the DALI logic programs recovery.txt and sensor.txt
robot pippo
.................. Actived Agent ...................
make(go_right(exit1,bank1))
make(go_left(bank1,hospital1))
send_message_to(sensor,send_message(what_about_my_position(hospital1,pippo),
pippo),italian,[])
Error Recovery planning
Bank2 Bank1
make(go_right(exit2,bank2))
make(go_forward(bank2,bank1))
Exit2 Exit1 make(go_left(bank1,hospital1))
confirm(i_am_at_exit(exit2),user)
STATION
Examples – Error Recovery planning…
Run the DALI logic programs recovery.txt and sensor.txt
robot pippo
.................. Actived Agent ...................
make(go_right(exit2,bank2))
make(go_forward(bank2,bank1))
make(go_left(bank1,hospital1))
send_message_to(sensor,send_message(what_about_my_position(hospital1,pippo),
pippo),italian,[])
Error Recovery planning
Hospital1
Hospital1
?
Bank2 Bank1
Exit2 Exit1
make(go_right(exit1,bank1))
make(go_left(bank1,hospital1))
Third situation: the agent thinks to make(recovery_error(hospital1,bank2))
be at Exit1 while really she is make(go_forward(bank2,bank1))
at Exit2. When she is at Hospital1/Bank2 STATION
make(go_left(bank1,hospital1))
a planner recognizes the error and
modifies the plan.
Examples – Error Recovery planning… (step1)
Run the DALI logic programs recovery.txt and sensor.txt
sensor
robot pippo
.................. Actived Agent ...................
make(go_right(exit1,bank1))
make(go_left(bank1,hospital1))
send_message_to(sensor,send_message(what_about_my_position(hospital1,pippo),pippo),
italian,[])
make(recovery_error(hospital1,bank2))
make(go_forward(bank2,bank1))
make(go_left(bank1,hospital1))
Examples – Informations and Meta-reasoning…
Two Agents!
Examples – Informations and Meta-reasoning…
Initialization file name: agent1.txt and agent2.txt
DALI logic file name: agent1.txt and agent2.txt
agent1.txt
initialization_files
agent2.txt
active_user.pl
DALI
active_server.pl
agent1.txt
program
agent2.txt
active_dali_wi.pl
Examples – Informations and Meta-reasoning…
We will consider two simple agents. We are interested in showing how
the communication primitives query_ref and agree use the meta-level
reasoning.
rainE:-open_the_umbrellaA.
i_am_illE:>go_to_family_doctorA.
Examples – Informations and Meta-reasoning…
We will communicate to agent1 the fact ama(james,julia). In the
ontology that the agent ‘pippo’ adopts there is the fact:
ontology(pippo,ama,love).
New message
Insert name of addressee
|: pippo.
Insert From
|: pino.
Insert message
|: query_ref(ama(julia,Y),1,pino).
New message
Insert name of addressee
|: pippo.
Insert From
|: pino.
Insert message
|: query_ref(love(julia,Y),1,pino).
New message
Insert name of addressee
|: pippo.
Insert From
|: pino.
Insert message
|: agree(love(julia,james),pino).
Three Agents!
Examples – Cooperation and Ontology…
Initialization file name: italian.txt, english.txt and translator.txt
DALI logic file name: italian.txt, english.txt and translator.txt
translator.
initialization_files
english.txt
active_user.pl
translator.txt
progra
m english.txt
active_dali_wi.pl
italian.txt
Examples – Cooperation and Ontology…
questionE(Q,L,M):>agente(A,_,_,_), once(examine_question(Q,L,M,A)).
examine_question(Q,_,M,A):-messageA(M,send_message(know(Q,A),A)).
message(_,send_message(know(Q,A),A)):<clause(know(Q,A),_);knowP(Q,A).
examine_question(Q,L,M,A):-
messageA(translator,send_message(translate(Q,L,M,A),A)).
message(translator,send_message(translate(_,L,_,_),_)):< L=english.
examine_question(Q,L,M,A):-
messageA(M,send_message(not_know(Q,L,A),A)).
message(_,send_message(not_know(_,L,_),_)):< L=italian.
know(io,gino).
know(amo,gino). ITALIAN
know(odio,gino).
Examples – Cooperation and Ontology…
questionE(Q,L,M):>agente(A,_,_,_),
once(examine_question(Q,L,M,A)).
examine_question(Q,_,M,A):-
messageA(M,send_message(know(Q,A),A)).
message(_,send_message(know(Q,A),A)):<clause(know(Q,A),_);k
nowP(Q,A).
examine_question(Q,L,M,A):-
messageA(translator,send_message(translate(Q,L,M,A),A)).
message(translator,send_message(translate(_,L,_,_),_)):<
L=english.
…
ITALIAN
know(io,gino).
know(amo,gino).
know(odio,gino).
Examples – Cooperation and Ontology…
questionE(Q,L,M):>agente(A,_,_,_),
once(examine_question(Q,L,M,A)).
examine_question(Q,_,M,A):-
messageA(M,send_message(know(Q,A),A)).
message(_,send_message(know(Q,A),A)):<clause(know(Q,A),_);k
nowP(Q,A).
examine_question(Q,L,M,A):-
messageA(translator,send_message(translate(Q,L,M,A),A)).
message(translator,send_message(translate(_,L,_,_),_)):<
L=italian.
know(i,susy).
know(love,susy).
know(hate,susy).
know(you,susy).
Examples – Cooperation and Ontology…
translateE(Q,L,M,A):>once(examine_translation(Q,L,M,A)).
examine_translation(Q,_,M,A):-clause(translated(Q,Tr),_),
messageA(A,send_message(question(Tr,italian,M),translator)).
examine_translation(Q,_,M,A):-translatedP(Q,Tr),
messageA(A,send_message(question(Tr,italian,M),translator)).
examine_translation(Q,_,M,A):-clause(translated(Tr,Q),_),
messageA(A,send_message(question(Tr,english,M),translator)).
translated(i,io).
translated(love,amo).
translated(hate,odio).
translated(you,te).
Cooperation and Ontology
The environment…
ITALIAN
questionE(Term,Language,From)
ITALIAN ENGLISH
know(io,gino). know(i,susy).
know(amo,gino). know(love,susy).
know(odio,gino). know(hate,susy).
know(te,gino). know(you,susy).
TRANSLATOR
translated(i,io).
translated(love,amo).
translated(hate,odio).
translated(you,te).
Cooperation and Ontology
ITALIAN
ITALIAN ENGLISH
know(io,_) know(i,_)
know(amo,_) know(love,_)
know(te,_) know(you,_)
evviva_loves_me(susy)
Examples – Cooperation and Ontology…
english/susy
translator
ITALIAN
ITALIAN ENGLISH
know(io,_) know(i,_)
know(odio,_) know(hate,_)
know(te,_) know(you,_)
i_will_not_speak_with(susy)
add_pastA(enemy(susy))
told(Ag,send_message(_)):-not(enemyP(Ag)).
english/susy translator
ITALIAN
ENGLISH ITALIAN
send_message(give_present(A),A)
accept_presentA,
drop_pastA(enemy(A))
recovery_friendship(Ag):-informP(_,motivation(refused_message),Ag).
recovery_friendshipI(Ag):>clause(agent(A),_),
messageA(Ag,send_message(give_present(A),A)).
italian/gino
english/susy