Article

Termination Status for Behaviors

Alex J. Champandard on June 16, 2007

When assembling modular behaviors into hierarchies, it’s important to work out how they communicate together. You can think about custom 1-to-1 interactions between behaviors later on, but it’s crucial to specify the common interface for all behaviors upfront.

A termination status is a known code that each behavior returns once it has completed. Termination status codes are typically exposed in the common interfaces, as they are used everywhere. Indeed, dealing and reasoning with success or failure is the number #1 purpose of any decision making or control system.

There are three well-defined termination codes that are useful for AI engines.

Completed successfully
The behavior accomplished its purpose and terminated without any problems. The actor’s state was modified as intended.
Failed cleanly
The behavior did not accomplish its purpose, but still terminated cleanly. All problems were anticipated by the programmer, and none of the starting assumptions were broken. This typically means that there were no side effects on the actor’s state.
Unexpected error
The behavior could not accomplish its purpose, and while trying to do so, it broke the starting assumptions. There were side effects on the actor’s state, and this should be taken into account by higher-level logic.

Those of you familiar with multiple programming languages used for AI will notice that these termination status codes cover two useful categories of languages:

  1. Declarative languages like Prolog use success and failure codes to search a tree of logic statements. Failure simply causes the reasoning engine to backtrack one level in the tree (only), and find another branch to search. There are never any unexpected side effects.

  2. Procedural languages like Python or Lua use exceptions as errors. This indicates that the code encountered a problem, probably modifying the state in the process. Such exceptions expect parent blocks to deal with the error and restart somewhere else, otherwise the whole program terminates.

If your AI engine only supports two of the three termination status codes, then it’s designed either for procedural execution/control, or logical search/planning — but not both. Is that what you intended?

Discussion 0 Comments

If you'd like to add a comment or question on this page, simply log-in to the site. You can create an account from the sign-up page if necessary... It takes less than a minute!