Jason_tutorial_01_helloWorldAndfactorial

Jason Tutorial 01
Hello World
Professor Fuhua Lin
AgentSpeak Programming Style
--- defining an agent
• Definition of a single agent, two parts:
– The agent’s initial beliefs and
possibly initial goals
– The agent’s plans
• Save in a single file: hello.asl
• AgentSpeak does not have variables,
the constructs are specific agent
notions, such as beliefs, goals, plans.
• Beliefs --- represent the information
that the agent has currently been able
to obtain about its environment.
• The full stop, ‘.’, is a syntactic
separator, much as a semi-colon in
Java and C.
•
•
•
•
•
+started <- .print(“Hello World!”).
– Whenever you come to believe ‘started’,
print the text ‘Hello World’. In logic, we say
“when the proposition ‘started’ is true”.
A plan is triggered when events occur which
match its trigger condition, and when this
happens, the plan becomes “active”; it becomes
something that the agent ‘considers doing’.
However, before an agent selects a plan to
become active, it checks that the context of the
plan is appropriate.
In this case, there is just one plan that can be
triggered by the event, and since the context is
empty, it is always applicable. So the
AgentSpeak interpreter directly execute the
body of that plan.
.print(…) --- internal action
Summary
• Do not think that plan bodies are just like subroutines, methods, or procedures from
conventional programming language: they are
in fact very much more than that!
• The program does not terminate! It is not a
bad thing. Agents are aware of and respond to
their environment.
• How to contrast AgentSpeak to Prolog?
– A Prolog program never does anything until a user
asks a query, and the behavior that the program
then generates is a side-effect of trying to prove a
theorem.
Hello.mas2j
Factorial Agent (1)
Trigger Conditions
• Different contexts can respond to
events in different ways.
Problems in the last
example
• Messy in terms of AgentSpeak
programming style
• Not efficient, does not use recursion
Factorial Agent (2)
Comments on the 2nd
example for factorial
computation
• Goal-oriented , used 4 ‘!’s
• Using recursion in plans, more
efficient