Crew.ai framework for autonomous AI agents

KARTHIK
5 min readJul 19, 2024

--

In this knowledge article, I will handhold and walk you through the secret paths that LLM Agents and Multi-Agents follow — a simple introduction to get started with Crew.ai

Synopsis

  1. What is Crew.ai?
  2. Core Components of Crew.ai
  3. Senarion to understand Crew.ai
  4. Agents
  5. Tasks
  6. Tools
  7. Process
  8. Crew
  9. Benefits of using Crew.ai
  10. Crew.ai Hands-On

What is Crew.ai?

Crew.ai is a Pythonic framework that allows us to work with Agents. Crew.ai will enable us to build and orchestrate one or multiple Agents to solve a real-world or complex task. This framework uses Langchain to allow and use agents.

Core components of Crew.ai :

  1. Agents
  2. Tasks
  3. Tools
  4. Process
  5. Crew

Before getting a deep dive into what Crew.ai's core components or architecture are, allow me to walk through a scenario that will help you understand what Crew.ai is all about.

Scenario:

Let's say there is a XYZ company that has a project to take over and complete. As in the corporate architecture, the project will be taken under the control of your manager and the manager needs to co-ordinate among things.

  1. The first requirement is to find/hire skillful resources/people.
  2. Assign the task/work to the selected associate.
  3. Provide them with adequate resources to complete the work assigned to them.
  4. As a Manager collectively co-ordinate the needs and necessity of the project requirements and deliver the project.

Keeping this into consideration now let's get started with the core components of the Crew.ai

Agents

Agents to Crew.ai are the skilful person that can be assigned with the task. Agents are programmed to perform a task. It is like a skilled person who can do a job if a task is assigned to it.

What are all the attributes present in the Agents?

Role => Role is the designation of the agents in the Crew

Goal => Goal is the aim/objective of the agent to achieve

Backstory => Backstory is the brief context about the agent's role

Tools => Tools are the set of functions that the agents can use to perform tasks

#Importing the necesssary library
from crew import Agent

#Defining a Agent
agent = Agent(
role = "Internet Article Reader",
goal = "Analyze the user query, read and gather knowlege about the articles",
backstory = "This agent is specialized in reading and gathering about the articles given to it.",
)

Tasks

Tasks are the works assigned to an Agent. Once the Agent/Multiple agents are defined, each agent should be assigned a task, such as an associate being assigned work to do in the company.

Attributes present in the tasks

Description => The statement or the set of instructions on how to perform a task.

Expected output=> Description of how the output of the task should look like.

Agents => The variable name of the agent to which this task is assigned to.

#Importing the necesssary library
from crew import Agent,Task

#Defining a Agent
agent = Agent(
role = "Internet Article Reader",
goal = "Analyze the user query, read and gather knowlege about the articles",
backstory = "This agent is specialized in reading and gathering about the articles given to it.",
)

#Defining a Task to the agent
task = Task(
description:"Based on the user query and advice,provide a comprhensive answer/summary",
expected_output = "summary or the answer to the user question from the article skimmed through",
agent=agent
)

Tools

Tools are the set of functions used by the agents to complete a task. Such as a skilful person uses their laptops/internet to complete a required task assigned to them.

If you want to know about the multiple tools available, you can walk through Crew.ai and Langchain tools.

You can also add your own tools as per your requirements and if you want to explore this, feel free to go through the documentation.

#Importing the necesssary library
from crewai import Agent, Task
from crewai_tools import ScrapeWebsiteTool, SerperDevTool

#define the tools require to scrape and collect data from the internet
#if you want to use these tools please know how to set up this endpoint in a video or by skimming in internet
search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()

#defining the llm required
llm = Ollama(model = 'llama3',temperature=0.5)

#Defining a Agent
agent = Agent(
role = "Internet Article Reader",
goal = "Analyze the user query, read and gather knowlege about the articles",
backstory = "This agent is specialized in reading and gathering about the articles given to it.",
tools = [serper,scrape],
verbose = True,
llm = llm)

#Defining a Task to the agent
task = Task(
description:"Based on the user query and advice,provide a comprhensive answer/summary",
expected_output = "summary or the answer to the user question from the article skimmed through",
agent=agent)

Process

The process is a component that manages and orchestrates all the tasks executed by the agents with the defined tools.

The process is defined in these ways

  1. Sequential => Executes the tasks handled by the agents in sequentially (specified ordered)
  2. Hierarchical => Executes the tasks handled by the agents in a parallel way (simultaneously)

Crew

The crew is the representative of the collaborative agents. Consider the crew as the manager of the project and the manager will kick start the project and manage all the requirements the project requires.

#Importing the necesssary library
from crewai import Agent, Task, Crew, Process
from crewai_tools import ScrapeWebsiteTool, SerperDevTool

#define the tools require to scrape and collect data from the internet
search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()

#defining the llm required
llm = Ollama(model = 'llama3',temperature=0.5)

#Defining a Agent
agent = Agent(
role = "Internet Article Reader",
goal = "Analyze the user query, read and gather knowlege about the articles",
backstory = "This agent is specialized in reading and gathering about the articles given to it.",
tools = [serper,scrape],
verbose = True,
llm = llm)

#Defining a Task to the agent
task = Task(
description:"Based on the user query and advice,provide a comprhensive answer/summary",
expected_output = "summary or the answer to the user question from the article skimmed through",
agent=agent)

#Defining the process and the crew
crew = Crew(agents = ['agent'],
tasks = ['task'],
process.sequential)

#Kick off the tasks using crew
crew = crew.kickoff(inputs = {'input':'tell me why should i buy stocks from stock market'})

Benefits of using Crew.ai

  • Enhanced Collaboration: This breaks down communication barriers and fosters a collaborative environment, even for remote and hybrid teams.
  • Increased Efficiency: Automates routine tasks and optimizes workflows, freeing up time for more critical activities.
  • Improved Decision Making: Leverages data and analytics to support informed decision-making processes.
  • Scalable Solutions: Adapts to the needs of teams of various sizes and industries, providing tailored solutions.
  • Continuous Improvement: Facilitates a culture of continuous improvement by providing ongoing feedback and performance insights.

Crew.ai Hands-On

If you want to learn more about Crew.ai by doing hands-on please try and visit the Crew.ai platform for more real-world examples.

--

--

KARTHIK
KARTHIK

Written by KARTHIK

“I do not fear this new challenge. Rather like a true warrior I will rise to meet it.”

No responses yet