SequentialWorkflow
The SequentialWorkflow
class is designed to manage and execute a sequence of tasks through a dynamic arrangement of agents. This class allows for the orchestration of multiple agents in a predefined order, facilitating complex workflows where tasks are processed sequentially by different agents.
Attributes
agents
List[Agent]
The list of agents in the workflow.
flow
str
A string representing the order of agents.
agent_rearrange
AgentRearrange
Manages the dynamic execution of agents.
Methods
__init__(self, agents: List[Agent] = None, max_loops: int = 1, *args, **kwargs)
__init__(self, agents: List[Agent] = None, max_loops: int = 1, *args, **kwargs)
The constructor initializes the SequentialWorkflow
object.
Parameters:
agents
(List[Agent]
, optional): The list of agents in the workflow. Defaults toNone
.max_loops
(int
, optional): The maximum number of loops to execute the workflow. Defaults to1
.*args
: Variable length argument list.**kwargs
: Arbitrary keyword arguments.
run(self, task: str) -> str
run(self, task: str) -> str
Runs the specified task through the agents in the dynamically constructed flow.
Parameters:
task
(str
): The task for the agents to execute.Returns:
str
: The final result after processing through all agents.Usage Example: ```python from zytron import Agent, SequentialWorkflow
from zytron_models import Anthropic
```
This example initializes a SequentialWorkflow
with three agents and executes a task, printing the final result.
Notes
Logs the task execution process and handles any exceptions that occur during the task execution.
Logging and Error Handling
The run
method includes logging to track the execution flow and captures errors to provide detailed information in case of failures. This is crucial for debugging and ensuring smooth operation of the workflow.
Additional Tips
Ensure that the agents provided to the
SequentialWorkflow
are properly initialized and configured to handle the tasks they will receive.The
max_loops
parameter can be used to control how many times the workflow should be executed, which is useful for iterative processes.Utilize the logging information to monitor and debug the task execution process.
Last updated