Skip to content

BaseWorkflow

swarms.modules.structs

Class Name: BaseWorkflow

Base class for workflows.

Attributes - Task_pool (list): A list to store tasks.

Methods - Add(task: Task = None, tasks: List[Task] = None, args, *kwargs): Adds a task or a list of tasks to the task pool. - Run(): Abstract method to run the workflow.

Source Code:

class BaseWorkflow(BaseStructure):
"""
Base class for workflows.

 Attributes:
     task_pool (list): A list to store tasks.

 Methods:
     add(task: Task = None, tasks: List[Task] = None, *args, **kwargs):
         Adds a task or a list of tasks to the task pool.
     run():
         Abstract method to run the workflow.
"""

For the usage examples and additional in-depth documentation please visit BaseWorkflow

Explanation:

Initially, the BaseWorkflow class is a class designed to handle workflows. It contains a list within the task pool to handle various tasks and run methods. In the current structure, there are a few in-built methods such as add, run, __sequential_loop, __log, reset, get_task_results, remove_task, update_task, delete_task, save_workflow_state, add_objective_to_workflow, and load_workflow_state, each serving a unique purpose.

The add method functions to add tasks or a list of tasks to the task pool while the run method is left as an abstract method for initializing the workflow. Considering the need to run the workflow, __sequential_loop is another abstract method. In cases where the user desires to log messages, __log can be utilized. For resetting the workflow, there is a reset method, complemented by get_task_results that returns the results of each task in the workflow. To remove a task from the workflow, remove_task can be employed.

In cases where an update is required for the tasks in the workflow, update_task comes in handy. Deleting a task from the workflow can be achieved using the delete_task method. The method saves the workflow’s state to a JSON file, and the user can fix the path where the file resides. For adding objectives to the workflow, add_objective_to_workflow can be employed, and there is an abstract method of load_workflow_state for loading the workflow state from a JSON file providing the freedom to revert the workflow to a specific state.

The class also has a method __str__ and __repr__ to represent the text and instantiate an object of the class, respectively. The object can be reset, task results obtained, tasks removed, tasks updated, tasks deleted, or workflow state saved. The structure provides detailed methods for altering the workflow at every level.