AbstractIntentModel
The AbstractIntentModel
, holds the intended actions of the capability, defining a finite set of methods,
encapsulating that capability, that can be selected and set, through parameterization, to create a component
task. This combination of finite methods, or actions, and parameter fine tuning is called parameterised intent
or just Intent
Abstract AI Single Task Application Component (AI-STAC) Class for Parameterised Intent containing parameterised
intent registration methods _intent_builder(...)
and _set_intend_signature(...)
.
it is creating a construct initialisation to allow for the control and definition of an intent_param_exclude
list, default_save_intent
boolean and a default_intent_level
value.
As an example of an initialisation method
# TODO: Replace <<capability_name>> with your component class name. This assumes the PropertyManager
# follow the recommended prefix naming convention
def __init__(self, property_manager: <<capability_name>>PropertyManager, default_save_intent: bool=None,
default_intent_level: bool=None, order_next_available: bool=None, default_replace_intent: bool=None):
# set all the defaults
default_save_intent = default_save_intent if isinstance(default_save_intent, bool) else True
default_replace_intent = default_replace_intent if isinstance(default_replace_intent, bool) else True
default_intent_level = default_intent_level if isinstance(default_intent_level, (str, int, float)) else 0
default_intent_order = -1 if isinstance(order_next_available, bool) and order_next_available else 0
intent_param_exclude = ['data', 'inplace']
intent_type_additions = []
super().__init__(property_manager=property_manager, default_save_intent=default_save_intent,
intent_param_exclude=intent_param_exclude, default_intent_level=default_intent_level,
default_intent_order=default_intent_order, default_replace_intent=default_replace_intent,
intent_type_additions=intent_type_additions)
in order to define the run pattern for the component task run_intent_pipeline(...)
is an abstracted method
that defines the run pipeline of the intent.
As an example of a run_pipeline that iteratively updates a canonical with each intent
def run_intent_pipeline(self, canonical, intent_levels: [int, str, list]=None, **kwargs):
# test if there is any intent to run
if self._pm.has_intent():
# get the list of levels to run
if isinstance(intent_levels, (int, str, list)):
intent_levels = Commons.list_formatter(intent_levels)
else:
intent_levels = sorted(self._pm.get_intent().keys())
for level in intent_levels:
level_key = self._pm.join(self._pm.KEY.intent_key, level)
for order in sorted(self._pm.get(level_key, {})):
for method, params in self._pm.get(self._pm.join(level_key, order), {}).items():
if method in self.__dir__():
# add method kwargs to the params
if isinstance(kwargs, dict):
params.update(kwargs)
# add excluded parameters to the params
params.update({'inplace': False, 'save_intent': False})
canonical = eval(f"self.{method}(canonical, **{params})", globals(), locals())
return canonical
When writing the intent, it must include a code signature and at the top of the method a code snippet which allows the intent action to be registered. The below represents a template method starter where <method> and <params>… are the method name and method parameters for this intent.
def <method>(self, <params>..., save_intent: bool=None, intent_level: [int, str]=None, intent_order: int=None,
replace_intent: bool=None, remove_duplicates: bool=None):
# resolve intent persist options
self._set_intend_signature(self._intent_builder(method=inspect.currentframe().f_code.co_name, params=locals()),
intent_level=intent_level, intent_order=intent_order, replace_intent=replace_intent,
remove_duplicates=remove_duplicates, save_intent=save_intent)
# intend code block on the canonical
...