yasmin.state module

class yasmin.state.State(outcomes: Set[str])

Bases: ABC

Abstract base class representing a state in a state machine.

This class provides a framework for creating specific states with defined outcomes. Subclasses must implement the execute method to define the state-specific behavior.

Attributes:

_outcomes (Set[str]): A set of valid outcomes for this state. _running (bool): A flag indicating whether the state is currently running. _canceled (bool): A flag indicating whether the state has been canceled.

cancel_state() None

Cancels the execution of the state.

Sets the _canceled flag to True and logs the cancellation.

abstract execute(blackboard: Blackboard) str

Executes the specific behavior of the state.

This method must be implemented by subclasses to define what happens when the state is executed.

Parameters:

blackboard – An instance of Blackboard that provides the context for execution.

Returns:

The outcome of the execution as a string.

Raises:

NotImplementedError – If not implemented in a subclass.

get_outcomes() Set[str]

Gets the valid outcomes for this state.

Returns:

A set of valid outcomes as strings.

is_canceled() bool

Checks if the state has been canceled.

Returns:

True if the state is canceled, False otherwise.

is_running() bool

Checks if the state is currently running.

Returns:

True if the state is running, False otherwise.