The Team: Orchestrating Crews and Processes
The Team: Orchestrating Crews and Processes
Section titled “The Team: Orchestrating Crews and Processes”We have Agents (the workers) and Tasks (the work). The Crew is the entity that brings them together and manages the execution flow.
Assembling the Crew
Section titled “Assembling the Crew”A Crew is initialized with a list of agents and a list of tasks. It acts as the container for the entire operation.
from crewai import Crew, Process
my_crew = Crew( agents=[researcher, writer], tasks=[research_task, write_task], verbose=True)Processes: The Workflow Styles
Section titled “Processes: The Workflow Styles”How should the tasks be executed? CrewAI supports different Process types.
1. Sequential (Default)
Section titled “1. Sequential (Default)”This is the “Waterfall” method. Tasks are executed in the order they are listed in the tasks list. The output of the first task is automatically passed as context to the second task, and so on. This is ideal for linear workflows.
[Task A] -> Output -> [Task B] -> Output -> [Task C]2. Hierarchical
Section titled “2. Hierarchical”This simulates a managerial structure. You define a list of tasks, but instead of assigning them manually, a “Manager” agent (which CrewAI creates for you) analyzes the tasks and delegates them to the available agents based on their roles. To use this, you must specify a manager_llm.
my_crew = Crew( agents=[researcher, writer], tasks=[task1, task2], process=Process.hierarchical, manager_llm=gpt4_llm)Kickoff: Starting the Engine
Section titled “Kickoff: Starting the Engine”To start the process, you call the kickoff() method. This is where you pass inputs for any variables defined in your tasks/agents.
inputs = {'topic': 'Quantum Computing'}result = my_crew.kickoff(inputs=inputs)
print(result)The result is a CrewOutput object, containing the final answer, token usage statistics, and individual task outputs.
Memory and Caching
Section titled “Memory and Caching”By setting memory=True in the Crew config, you enable agents to remember past interactions (Short-term memory) and recall information across different runs (Long-term memory). We will cover this in depth in a later chapter, but know that the Crew class handles this persistence layer.