[FEAT][SequentialWorkflow handling]

pull/245/head
Kye 1 year ago
parent 61a06d0edd
commit d295cc44fd

@ -157,8 +157,16 @@ class SequentialWorkflow:
def reset_workflow(self) -> None:
"""Resets the workflow by clearing the results of each task."""
try:
for task in self.tasks:
task.result = None
except Exception as error:
print(
colored(
f"Error resetting workflow: {error}", "red"
),
)
def get_task_results(self) -> Dict[str, Any]:
"""
@ -167,13 +175,29 @@ class SequentialWorkflow:
Returns:
Dict[str, Any]: The results of each task in the workflow
"""
return {task.description: task.result for task in self.tasks}
try:
return {
task.description: task.result for task in self.tasks
}
except Exception as error:
print(
colored(
f"Error getting task results: {error}", "red"
),
)
def remove_task(self, task: str) -> None:
"""Remove tasks from sequential workflow"""
try:
self.tasks = [
task for task in self.tasks if task.description != task
]
except Exception as error:
print(
colored(
f"Error removing task from workflow: {error}", "red"
),
)
def update_task(self, task: str, **updates) -> None:
"""
@ -359,6 +383,8 @@ class SequentialWorkflow:
def add_objective_to_workflow(self, task: str, **kwargs) -> None:
"""Adds an objective to the workflow."""
try:
print(
colored(
"""
@ -375,6 +401,13 @@ class SequentialWorkflow:
kwargs=kwargs["kwargs"],
)
self.tasks.append(task)
except Exception as error:
print(
colored(
f"Error adding objective to workflow: {error}",
"red",
)
)
def load_workflow_state(
self, filepath: str = None, **kwargs
@ -396,6 +429,8 @@ class SequentialWorkflow:
>>> workflow.load_workflow_state("sequential_workflow_state.json")
"""
try:
filepath = filepath or self.restore_state_filepath
with open(filepath, "r") as f:
@ -412,6 +447,13 @@ class SequentialWorkflow:
history=task_state["history"],
)
self.tasks.append(task)
except Exception as error:
print(
colored(
f"Error loading workflow state: {error}",
"red",
)
)
def run(self) -> None:
"""
@ -486,6 +528,7 @@ class SequentialWorkflow:
ValueError: If a Agent instance is used as a task and the 'task' argument is not provided.
"""
try:
for _ in range(self.max_loops):
for task in self.tasks:
# Check if the current task can be executed
@ -526,3 +569,15 @@ class SequentialWorkflow:
self.save_workflow_state(
"sequential_workflow_state.json"
)
except Exception as e:
print(
colored(
(
"Error initializing the Sequential workflow:"
f" {e} try optimizing your inputs like the"
" agent class and task description"
),
"red",
attrs=["bold", "underline"],
)
)
Loading…
Cancel
Save