unaiverse.hsm¶
This package implements the behaviors of UNaIVERSE agents. A behavior is a hybrid state machine whose transitions are labeled by the @action methods of an agent. At each clock cycle an agent runs its public behavior on the public network. While it is in a world, it first runs the behavior of its role inside that world. A world ships one behavior per role as a JSON file.
The package has three modules and re-exports their main class. from unaiverse.hsm import HybridStateMachine, Action, State is therefore equivalent to importing each class from its own module.
| Name | Defined in | Role |
|---|---|---|
HybridStateMachine |
unaiverse.hsm.hsm |
The machine. It holds the states and the transitions, reads and writes the JSON format, applies the wildcards and runs one cycle with act(). |
State |
unaiverse.hsm.state |
A node of the machine with its blocking flag, its waiting time, its message and an optional inner action. |
Action |
unaiverse.hsm.action |
The binding of one @action method to a transition with its arguments, its readiness, its timing and its queue of requests. It also defines ActionInteractionList, the queue. |
The modules hsm, state and action are also attributes of the package (unaiverse.hsm.hsm, unaiverse.hsm.state, unaiverse.hsm.action). The decorator @action that marks the methods usable as actions is defined in unaiverse.agent and its contract is summarized in The @action decorator.
A typical program never builds a machine: the agent loads its public behavior by itself and receives the world behavior from the world. A world that builds its role behaviors in code uses the package directly:
from unaiverse.hsm import HybridStateMachine
from .teacher import WAgent as Teacher
behav = HybridStateMachine(Teacher(proc=None))
behav.add_transit("init", "lesson", action="send_engage")
behav.add_transit("lesson", "init", action="disengage_all", timeout=30.)
behav.set_role("teacher")
behav.save("teacher.json")