Component#

The Component module defines a PipelineComponent class.

This is a base class for pipeline processing and is responsible for performing a specific task.

class PipelineComponent(**data)[source]#

Bases: ABC, BaseModel

Base class for a single task processed by Pipeline.

before_handler: BeforeHandler#

BeforeHandler, associated with this component.

after_handler: AfterHandler#

AfterHandler, associated with this component.

timeout: Optional[float]#

Maximum component execution time (in seconds), if it exceeds this time, it is interrupted.

concurrent: bool#

Optional flag that indicates whether this component should be executed concurrently with adjacent concurrent components.

start_condition: AnyCondition#

AnyCondition that is invoked before each component execution; component is executed only if it returns True.

name: Optional[str]#

Name of the component. Defaults to computed_name potentially modified by rename_component_incrementing().

See validate_name() for rules.

path: Optional[str]#

Separated by dots path to component, is universally unique.

classmethod validate_name(name)[source]#

Validate this component’s name:

Name cannot be empty or contain “.” or “#”.

Raises:

ValueError – If name failed validation.

_set_state(ctx, value)[source]#

Method for component runtime state setting, state is preserved in Context.framework_data.

Parameters:
get_state(ctx)[source]#

Method for component runtime state getting, state is preserved in Context.framework_data.

Parameters:

ctx (Context) – Context to get state from.

Return type:

ComponentExecutionState

Returns:

ComponentExecutionState of this service.

abstract async run_component(ctx)[source]#

Run this component.

Parameters:

ctx (Context) – Current dialog Context.

Return type:

Optional[ComponentExecutionState]

property computed_name: str#

Default name that is used if name is not defined.

In case two components in a ServiceGroup have the same computed_name an incrementing number is appended to the name.

async _run(ctx)[source]#

A method for running a pipeline component. Executes extra handlers before and after execution, launches run_component() method. This method is run after the component’s timeout is set (if needed).

Parameters:

ctx (Context) – Current dialog Context.

Return type:

None

async __call__(ctx)[source]#

A method for calling pipeline components. It sets up timeout and executes it using _run() method.

Parameters:

ctx (Context) – Current dialog Context.

Return type:

None

Returns:

None

add_extra_handler(extra_handler_type, extra_handler)[source]#

Add extra handler to this component.

Parameters: