docs/en/learn/sequential-process.mdx
CrewAI offers a flexible framework for executing tasks in a structured manner, supporting both sequential and hierarchical processes. This guide outlines how to effectively implement these processes to ensure efficient task execution and project completion.
The sequential process ensures tasks are executed one after the other, following a linear progression. This approach is ideal for projects requiring tasks to be completed in a specific order.
To use the sequential process, assemble your crew and define tasks in the order they need to be executed.
from crewai import Crew, Process, Agent, Task, TaskOutput, CrewOutput
# Define your agents
researcher = Agent(
role='Researcher',
goal='Conduct foundational research',
backstory='An experienced researcher with a passion for uncovering insights'
)
analyst = Agent(
role='Data Analyst',
goal='Analyze research findings',
backstory='A meticulous analyst with a knack for uncovering patterns'
)
writer = Agent(
role='Writer',
goal='Draft the final report',
backstory='A skilled writer with a talent for crafting compelling narratives'
)
# Define your tasks
research_task = Task(
description='Gather relevant data...',
agent=researcher,
expected_output='Raw Data'
)
analysis_task = Task(
description='Analyze the data...',
agent=analyst,
expected_output='Data Insights'
)
writing_task = Task(
description='Compose the report...',
agent=writer,
expected_output='Final Report'
)
# Form the crew with a sequential process
report_crew = Crew(
agents=[researcher, analyst, writer],
tasks=[research_task, analysis_task, writing_task],
process=Process.sequential
)
# Execute the crew
result = report_crew.kickoff()
# Accessing the type-safe output
task_output: TaskOutput = result.tasks[0].output
crew_output: CrewOutput = result.output
Each task in a sequential process must have an agent assigned. Ensure that every Task includes an agent parameter.
In sequential processes, if an agent has allow_delegation set to True, they can delegate tasks to other agents in the crew.
This feature is automatically set up when there are multiple agents in the crew.
Tasks can be executed asynchronously, allowing for parallel processing when appropriate.
To create an asynchronous task, set async_execution=True when defining the task.
CrewAI supports both memory and caching features:
memory=True when creating the Crew. This allows agents to retain information across tasks.cache=False to disable it.You can set callbacks at both the task and step level:
task_callback: Executed after each task completion.step_callback: Executed after each step in an agent's execution.CrewAI tracks token usage across all tasks and agents. You can access these metrics after execution.
This updated documentation ensures that details accurately reflect the latest changes in the codebase and clearly describes how to leverage new features and configurations. The content is kept simple and direct to ensure easy understanding.