- Breakdown a task into smaller ones for multiple agents to execute
- A crew of agents can optimize existing prompting by one central agent
- Task from human > Agents with tools and processes > Response by LLMs
- Role playing
- Each agent has a specific title and context that focus on specific task
- Focus
- Each agent focuses to execute its task only
- Tool
- Each agent has a set of specific tools
- Property 1 - Versatile
- Multi-function, can manage all types of inputs and respond with strong outputs
- Property 2 - Fault-tolerant
- Continue to execute and send error messages back to agent for correction
- Property 3 - Caching
- Store the same previous task requests, avoid hitting API rate limit, and save time to execute
- e.g. Cross caching layer
- Collaboration
- All agents can talk to each other to collaborate, delegate tasks, and execute the main task as a whole
- Guardrail
- Default in crewAI framework
- Prevent AI hallucination
- Ensure agents achieve their tasks
- Memory
- Type 1 - Short term memory
- During crew execution
- Type 2 - Long term memory
- After crew execution, for self-improvement and reuse
- Type 3 - Entity memory
- During crew execution
- Divided by categories, e.g. person name, org name, etc
- Type 1 - Short term memory
- Step 1: Defining tools
- Agent level tools
- Agent-specific and can be used when an agent execute its tasks
- Task level tools
- Task-specific and can only be used when that task is executed
- Agent level tools
- Step 2: Defining agents
- Role
- A role that the agent plays
- Goal
- A goal that the agent should achieve
- Agent level tools (depend on use cases)
- A set of tools that can help the agent to work
- Backstory
- Detailed description of the background of agent and its role playing
- Delegation (depend on use cases)
- Decide if the agent can delegate tasks to other agents or not
- Role
- Step 3: Defining tasks
- Description
- A description of the task
- Expected_output
- Expected output that the agent should achieve in task
- Task level tools (depend on use cases)
- A set of tools that can help the task being executed
- Can be assigned to multiple agents
- Agent
- Agent that is assigned with the task
- Description
- Step 4: Defining crew
- Agent list
- Order agents by list
- Ordering is not applicable if the process is in hierarchical
- Task list
- Order tasks by list
- Ordering is not applicable if the process is in hierarchical
- Process type
- Decide which process to run a crew of agents
- In parallel
- All agents execute their own tasks at the same time, tasks are not dependently executed
- In series/ sequential
- Each agent execute its own task one by one before passing to next agent
- In hierarchical
- Crew manager agent can delegate tasks to different agents to execute
- Remark: hierarchical + series/ parallel can happen at the same time
- Memory (depend on use cases)
- Decide if storing the memory of the agentic process in terms of short term, long term, entity memory
- Agent list
- Step 5: Run crew
- Define input
- Provide an input that meets the variables defined in the Agent and Task
- Kickoff crew
- Run the crew with input
- Output can be different even the agentic process is run each time with the same input
- Define input
- crewAI installation: Installing crewAI
- Install crewAI
!pip install crewai==0.28.8 crewai_tools==0.1.6 langchain_community==0.0.29
- Control warning
import warnings warnings.filterwarnings('ignore')
- Import crewAI libraries
from crewai import Agent, Task, Crew, Process
- Import LLM for building agents, e.g. Openai, Llama
import os from utils import get_openai_api_key openai_api_key = get_openai_api_key() os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'
- crewAI tool package: crewAI tool
- Defined tools
- Tools provided by crewAI
- Custom tool
- A tool that is defined with name and description by user
- OpenAI: OpenAI API
- Llama: Llama API
- Ollama: Ollama framework
- Mistral AI: Mistral AI API
- Cohere: Cohere API
- Hugging Face: Hugging Face models
- Serper: Google Search API
- Remark: Some regions are restricted in using particular models. Please check the model availability in related providers.