pull/393/head
Kye 11 months ago
parent 1a363be083
commit f331f6eb29

@ -44,5 +44,5 @@ workflow.add(tasks=[task1, task2])
workflow.run() workflow.run()
# # Output the results # # Output the results
# for task in workflow.tasks: for task in workflow.tasks:
# print(f"Task: {task.description}, Result: {task.result}") print(f"Task: {task.description}, Result: {task.result}")

@ -1,12 +1,15 @@
import json import json
from dataclasses import dataclass, field from dataclasses import dataclass
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from termcolor import colored from termcolor import colored
from swarms.structs.task import Task from swarms.structs.task import Task
from swarms.utils.logger import logger
# from swarms.utils.logger import logger
from swarms.structs.agent import Agent from swarms.structs.agent import Agent
from swarms.structs.conversation import Conversation
from swarms.utils.loguru_logger import logger
# SequentialWorkflow class definition using dataclasses # SequentialWorkflow class definition using dataclasses
@ -40,7 +43,7 @@ class SequentialWorkflow:
name: str = None name: str = None
description: str = None description: str = None
task_pool: List[Task] = field(default_factory=list) task_pool: List[Task] = None
max_loops: int = 1 max_loops: int = 1
autosave: bool = False autosave: bool = False
saved_state_filepath: Optional[str] = ( saved_state_filepath: Optional[str] = (
@ -50,6 +53,17 @@ class SequentialWorkflow:
dashboard: bool = False dashboard: bool = False
agents: List[Agent] = None agents: List[Agent] = None
def __post_init__(self):
self.conversation = Conversation(
system_prompt=f"Objective: {self.description}",
time_enabled=True,
autosave=True,
)
# Logging
logger.info(f"Number of agents activated: {len(self.agents)}")
logger.info(f"Task Pool Size: {self.task_pool}")
def add( def add(
self, self,
task: Optional[Task] = None, task: Optional[Task] = None,
@ -67,35 +81,44 @@ class SequentialWorkflow:
*args: Additional arguments to pass to the task execution. *args: Additional arguments to pass to the task execution.
**kwargs: Additional keyword arguments to pass to the task execution. **kwargs: Additional keyword arguments to pass to the task execution.
""" """
try: logger.info("A")
# If the agent is a Task instance, we include the task in kwargs for Agent.run() for agent in self.agents:
# Append the task to the task_pool list out = agent(str(self.description))
if task: self.conversation.add(agent.agent_name, out)
self.task_pool.append(task) prompt = self.conversation.return_history_as_string()
logger.info( out = agent(prompt)
f"[INFO][SequentialWorkflow] Added task {task} to"
" workflow" return out
)
elif tasks: # try:
for task in tasks: # # If the agent is a Task instance, we include the task in kwargs for Agent.run()
self.task_pool.append(task) # # Append the task to the task_pool list
logger.info( # if task:
"[INFO][SequentialWorkflow] Added task" # self.task_pool.append(task)
f" {task} to workflow" # logger.info(
) # f"[INFO][SequentialWorkflow] Added task {task} to"
else: # " workflow"
if task and tasks is not None: # )
# Add the task and list of tasks to the task_pool at the same time # elif tasks:
self.task_pool.append(task) # for task in tasks:
for task in tasks: # self.task_pool.append(task)
self.task_pool.append(task) # logger.info(
# "[INFO][SequentialWorkflow] Added task"
except Exception as error: # f" {task} to workflow"
logger.error( # )
colored( # else:
f"Error adding task to workflow: {error}", "red" # if task and tasks is not None:
), # # Add the task and list of tasks to the task_pool at the same time
) # self.task_pool.append(task)
# for task in tasks:
# self.task_pool.append(task)
# except Exception as error:
# logger.error(
# colored(
# f"Error adding task to workflow: {error}", "red"
# ),
# )
def reset_workflow(self) -> None: def reset_workflow(self) -> None:
"""Resets the workflow by clearing the results of each task.""" """Resets the workflow by clearing the results of each task."""

Loading…
Cancel
Save