The order of execution (parallel, sequential) of sub-plans, triggered inside their parent plan differs depending on the trigger symbol
!plannamemarks a plan
+!plannameto be executed in the next cycle → postponed execution.
!plannamemultiple times in one cycle will result in
+!plannameto be executed only once in the next cycle because the same trigger gets only added once.
!!plannameexecutes the matching plan in this (read: the same) cycle → immediate execution.
Note: As every plan body is executed sequentially, for each given
+!plannamewill be executed in that sequence.
For advanced users: With the annotation
@parallela plan can be modified to execute all plan-body statements in parallel (see → parallel annotations).
If the plan signature
+!planname contains a variable
+!planname(N), multiple different instances of triggers will be created (one for each unique
Consider the following AgentSpeak(L++) plan
N must be larger than 5 for the plan to succeed:
+!largerThan5(X) : X > 5 <- generic/print(X, "is larger than 5") : X <= 5 <- generic/print(X, "is NOT larger than 5"); fail .
failstatement in the
X <= 5branch, which will result in the plan to fail. This is intended to show different execution behaviour.
For example, having a plan-body containing
with different variables, two individual trigger instances will be created and queued for execution in the next cycle. The result will be two plans (one for
N = 3 and the second for
N = 23) to be run in parallel in the next cycle, yielding
3.0 is NOT larger than 5 23.0 is larger than 5
(The order of output might differ due to concurrency effects.)
Whereas, having a plan-body containing
the two plans will be executed immediately chained in the given order, i.e.
Note: If denoted and executed in opposite order
the output will be just
3.0 is NOT larger than 5
because the plan
+!largerThan5(3) fails (as intended).
Further execution in the current plan-context stops, i.e
+!largerThan5(23) will not be executed and the parent plan will also fail (see → Failing is Intentional on how to handle failing → actions and sub-plans).
Adding the same trigger multiple time yields different results depending on delayed execution
! and immediate execution
will yield (despite plan parameters resulting in succeeding plans)
23.0 is NOT larger than 5
to be printed only once as previously explained.
This could be avoided by defining one or both plans to be executed in the this cycle, e.g.
will execute the plan triggered in the second row in this cycle, or
which will execute both plans in this cycle. In both cases the result will be
23.0 is NOT larger than 5 23.0 is NOT larger than 5