Skip to content

aea.skills.behaviours

This module contains the classes for specific behaviours.

SimpleBehaviour Objects

class SimpleBehaviour(Behaviour,  ABC)

This class implements a simple behaviour.

__init__

 | __init__(act: Optional[Callable[[], None]] = None, **kwargs)

Initialize a simple behaviour.

Arguments:

  • act: the act callable.
  • kwargs: the keyword arguments to be passed to the parent class.

setup

 | setup() -> None

Set the behaviour up.

act

 | act() -> None

Do the action.

teardown

 | teardown() -> None

Tear the behaviour down.

CompositeBehaviour Objects

class CompositeBehaviour(Behaviour,  ABC)

This class implements a composite behaviour.

CyclicBehaviour Objects

class CyclicBehaviour(SimpleBehaviour,  ABC)

This behaviour is executed until the agent is stopped.

__init__

 | __init__(**kwargs)

Initialize the cyclic behaviour.

number_of_executions

 | @property
 | number_of_executions() -> int

Get the number of executions.

act_wrapper

 | act_wrapper() -> None

Wrap the call of the action. This method must be called only by the framework.

is_done

 | is_done() -> bool

Return True if the behaviour is terminated, False otherwise.

The user should implement it properly to determine the stopping condition.

OneShotBehaviour Objects

class OneShotBehaviour(SimpleBehaviour,  ABC)

This behaviour is executed only once.

__init__

 | __init__(**kwargs)

Initialize the cyclic behaviour.

is_done

 | is_done() -> bool

Return True if the behaviour is terminated, False otherwise.

act_wrapper

 | act_wrapper() -> None

Wrap the call of the action. This method must be called only by the framework.

TickerBehaviour Objects

class TickerBehaviour(SimpleBehaviour,  ABC)

This behaviour is executed periodically with an interval.

__init__

 | __init__(tick_interval: float = 1.0, start_at: Optional[datetime.datetime] = None, **kwargs)

Initialize the ticker behaviour.

Arguments:

  • tick_interval: interval of the behaviour in seconds.
  • start_at: whether to start the behaviour with an offset.

tick_interval

 | @property
 | tick_interval() -> float

Get the tick_interval in seconds.

start_at

 | @property
 | start_at() -> datetime.datetime

Get the start time.

last_act_time

 | @property
 | last_act_time() -> datetime.datetime

Get the last time the act method has been called.

act_wrapper

 | act_wrapper() -> None

Wrap the call of the action. This method must be called only by the framework.

is_time_to_act

 | is_time_to_act() -> bool

Check whether it is time to act, according to the tick_interval constraint and the 'start at' constraint.

Returns:

True if it is time to act, false otherwise.

SequenceBehaviour Objects

class SequenceBehaviour(CompositeBehaviour,  ABC)

This behaviour executes sub-behaviour serially.

__init__

 | __init__(behaviour_sequence: List[Behaviour], **kwargs)

Initialize the sequence behaviour.

Arguments:

  • behaviour_sequence: the sequence of behaviour.
  • kwargs:

current_behaviour

 | @property
 | current_behaviour() -> Optional[Behaviour]

Get the current behaviour.

If None, the sequence behaviour can be considered done.

act

 | act() -> None

Implement the behaviour.

is_done

 | is_done() -> bool

Return True if the behaviour is terminated, False otherwise.

State Objects

class State(SimpleBehaviour,  ABC)

A state of a FSMBehaviour.

A State behaviour is a simple behaviour with a special property 'event' that is opportunely set by the implementer. The event is read by the framework when the behaviour is done in order to pick the transition to trigger.

__init__

 | __init__(**kwargs)

Initialize a state of the state machine.

event

 | @property
 | event() -> Optional[str]

Get the event to be triggered at the end of the behaviour.

is_done

 | @abstractmethod
 | is_done() -> bool

Return True if the behaviour is terminated, False otherwise.

reset

 | reset() -> None

Reset initial conditions.

FSMBehaviour Objects

class FSMBehaviour(CompositeBehaviour,  ABC)

This class implements a finite-state machine behaviour.

__init__

 | __init__(**kwargs)

Initialize the finite-state machine behaviour.

is_started

 | @property
 | is_started() -> bool

Check if the behaviour is started.

register_state

 | register_state(name: str, state: State, initial: bool = False) -> None

Register a state.

Arguments:

  • name: the name of the state.
  • state: the behaviour in that state.
  • initial: whether the state is an initial state.

Returns:

None

Raises:

  • ValueError: if a state with the provided name already exists.

register_final_state

 | register_final_state(name: str, state: State) -> None

Register a final state.

Arguments:

  • name: the name of the state.
  • state: the state.

Returns:

None

Raises:

  • ValueError: if a state with the provided name already exists.

unregister_state

 | unregister_state(name: str) -> None

Unregister a state.

Arguments:

  • name: the state name to unregister.

Returns:

None

Raises:

  • ValueError: if the state is not registered.

states

 | @property
 | states() -> Set[str]

Get all the state names.

initial_state

 | @property
 | initial_state() -> Optional[str]

Get the initial state name.

initial_state

 | @initial_state.setter
 | initial_state(name: str)

Set the initial state.

final_states

 | @property
 | final_states() -> Set[str]

Get the final state names.

get_state

 | get_state(name) -> Optional[State]

Get a state from its name.

act

 | act()

Implement the behaviour.

is_done

 | is_done() -> bool

Return True if the behaviour is terminated, False otherwise.

register_transition

 | register_transition(source: str, destination: str, event: Optional[str] = None)

Register a transition.

No sanity check is done.

Arguments:

  • source: the source state name.
  • destination: the destination state name.
  • event: the event.

Returns:

None

Raises:

  • ValueError: if a transition from source with event is already present.

unregister_transition

 | unregister_transition(source: str, destination: str, event: Optional[str] = None)

Unregister a transition.

Arguments:

  • source: the source state name.
  • destination: the destination state name.
  • event: the event.

Returns:

None

Raises:

  • ValueError: if a transition from source with event is not present.