fabricatio_core.models.action
Module that contains the classes for defining and executing task workflows.
This module provides the Action and WorkFlow classes for creating structured task execution pipelines. Actions represent atomic operations, while WorkFlows orchestrate sequences of actions with shared context and error handling.
- Classes:
Action: Base class for defining executable actions with context management. WorkFlow: Manages action sequences, context propagation, and task lifecycle.
Attributes
Classes
Class that represents an action to be executed in a workflow. |
|
Manages sequences of actions to fulfill tasks. |
Module Contents
- fabricatio_core.models.action.OUTPUT_KEY = 'task_output'
- fabricatio_core.models.action.INPUT_KEY = 'task_input'
- class fabricatio_core.models.action.Action(/, **data: Any)[source]
Bases:
fabricatio_core.models.generic.WithBriefing,abc.ABCClass that represents an action to be executed in a workflow.
Actions are the atomic units of work in a workflow. Each action performs a specific operation and can modify the shared context data.
- ctx_override: ClassVar[bool] = False
Whether to override the instance attr by the context variable.
- model_post_init(__context: Any) None[source]
Initialize the action by setting default name and description if not provided.
- Parameters:
__context – The context to be used for initialization.
- class fabricatio_core.models.action.WorkFlow(/, **data: Any)[source]
Bases:
fabricatio_core.models.generic.WithBriefingManages sequences of actions to fulfill tasks.
Handles context propagation between actions, error handling, and task lifecycle events like cancellation and completion.
- name: str = 'WorkFlow'
The name of the workflow, which is used to identify and describe the workflow.
- description: str = ''
The description of the workflow, which describes the workflow’s purpose and requirements.
- steps: Sequence[Type[Action] | Action] = None
The sequence of actions to be executed, can be action classes or instances.
- task_input_key: ClassVar[str] = 'task_input'
Key used to store the input task in the context dictionary.
- task_output_key: ClassVar[str] = 'task_output'
Key used to extract the final result from the context dictionary.
- extra_init_context: Dict[str, Any] = None
Additional initial context values to be included at workflow start.
- classmethod set_task_input_key(input_key: str) Type[Self][source]
Set the task input key for the workflow.
- classmethod set_task_output_key(output_key: str) Type[Self][source]
Set the task output key for the workflow.
- model_post_init(__context: Any) None[source]
Initialize the workflow by instantiating any action classes.
- Parameters:
__context – The context to be used for initialization.
- override_action_variable(action: Action, ctx: Dict[str, Any]) Self[source]
Override action variable with context values.
- async serve(task: fabricatio_core.models.task.Task) None[source]
Execute workflow to complete given task.
- Parameters:
task (Task) – Task instance to be processed.
- Steps:
Initialize context with task instance and extra data
Execute each action sequentially
Handle task cancellation and exceptions
Extract final result from context