CrewAI is a multi-agent framework with a more humanized development concept. You act as a project manager, define various employees (agents), assign them different tasks, and finally define a team (crew). This team consists of various agents and subtasks, and the final task of the team is to fulfill the client's requirements.
To quickly understand CrewAI, you only need to grasp its three basic elements: Agent, Task, and Crew.
An agent is the basic operational unit in CrewAI, similar to a virtual role with specific duties and capabilities. In CrewAI, an agent is defined by the following four basic elements, which are described in natural language in the code.
1. Role
The role is the identity and duty description of the agent. It defines the agent's position and function within the system, determining the agent's behavior and interaction with other agents.
2. Goal
The goal is the specific task or result that the agent needs to achieve. Each agent has a clear goal that guides its behavior and decision-making.
3. Backstory
The backstory provides context and background for the agent, helping to define its behavior and decision-making style. It may include the agent's hypothetical experiences, knowledge areas, and working style.
4. Tools
Tools are the specific resources or methods used by the agent to perform tasks. These can include external APIs, data processing libraries, search engines, etc. Agents can work without tools, but tools are not mandatory.
Suppose we create a Research Specialist Agent.
1. Role
Research Specialist
2. Goal
Collect and organize detailed information about conference participants, including their background, company, and recent activities.
3. Backstory
An experienced researcher with extensive data analysis and information gathering experience, capable of efficiently mining and organizing relevant information to provide strong support for conference preparation.
4.Tools
Web scraping tool (ScrapeWebsiteTool), PDF reading tool (PDFSearchTool)
A task is the specific work that an agent needs to complete. CrewAI defines a task through the following four elements:
1. Description
A detailed description of the task, clearly stating its purpose and content.
2. Expected Output
The specific results or products required upon task completion. This sets a clear standard for task completion, ensuring the agent knows what kind of result to deliver.
3. Tools
The specific resources or methods used by the agent in task execution. These tools are the same as those defined for the agent and can be temporarily relied upon for the task.
4. Agent
The specific role that will execute the task.
Suppose we create a "Collect Conference Participants Information" task.
1. Description
Collect detailed background information on all conference participants, including their educational background, career experience, current job position, and responsibilities.
2. Expected Output
An Excel sheet containing detailed information for each participant, with columns for name, educational background, career experience, current position, and current company.
3. Tools
ExcelTool, a tool for creating Excel sheets.
4. Agent
Research Specialist Agent
A crew is a team composed of multiple agents working together to complete more complex tasks. Defining a crew mainly involves defining a team of agents, a list of tasks, and a process, which can be understood as the project execution process.
1. Agents
Define which members (agents) are in the crew.
2. Tasks
Define the specific tasks the crew needs to complete.
3. Process
The key to defining a crew is defining the process. Generally, this is a sequential structure where the next task starts after the previous one is completed, and the final task represents the crew's ultimate output. For advanced operations such as defining parallel and sequential tasks, CrewAI has a dedicated Process class, which is beyond the scope of this introductory chapter.
Suppose we define a crew to send product quotations.
1. Agents
list itemProductInfoCollectorAgent: Responsible for collecting product information. CustomerInfoCollectorAgent: Responsible for collecting customer information. PricingCalculatorAgent: Responsible for calculating product prices. QuoteDocumentGeneratorAgent: Responsible for generating the quotation document. EmailSenderAgent: Responsible for sending the quotation via email.2. Tasks
CollectProductInformationTask: Collect detailed product information. CollectCustomerInformationTask: Collect detailed customer information. CalculatePricingTask: Calculate prices based on product and customer information. GenerateQuoteDocumentTask: Generate the product quotation document. SendQuoteEmailTask: Send the quotation to the customer via email.3. Process
Sequential structure.