CrewAI is an innovative platform that allows developers to create and manage multiple AI agents working together to solve complex problems. At the heart of this system are individual agents, each with its own role, capabilities, and goals. In this blog post, we'll explore how to create your first basic agent using CrewAI.
Before we dive into creating an agent, make sure you have CrewAI installed. You can install it using pip:
pip install crewai
Also, ensure you have Python 3.7 or higher installed on your system.
Let's start by importing the necessary modules and creating a simple agent:
from crewai import Agent # Create a basic agent basic_agent = Agent( role="Research Assistant", goal="Gather and summarize information on a given topic", backstory="You are an AI research assistant with a keen eye for detail and a passion for learning.", verbose=True )
Let's break down the components of this agent:
To make your agent more capable, you can add specific tools or skills:
from crewai import Agent from langchain.tools import DuckDuckGoSearchRun search_tool = DuckDuckGoSearchRun() enhanced_agent = Agent( role="Web Researcher", goal="Find and analyze the latest trends in artificial intelligence", backstory="You are an AI expert with a knack for identifying emerging trends and technologies.", verbose=True, tools=[search_tool] )
In this example, we've added a DuckDuckGoSearchRun tool, which allows the agent to perform web searches. This significantly expands the agent's capabilities, enabling it to access real-time information from the internet.
CrewAI allows you to fine-tune your agent's behavior by adjusting various parameters:
from crewai import Agent customized_agent = Agent( role="Data Analyst", goal="Analyze and visualize complex datasets", backstory="You are a skilled data scientist with expertise in statistical analysis and data visualization.", verbose=True, allow_delegation=True, max_iterations=5, max_rpm=10 )
Here's what these additional parameters do:
To ensure your agent is functioning correctly, you can give it a simple task:
result = basic_agent.execute_task("Provide a brief summary of machine learning.") print(result)
This will prompt the agent to generate a summary of machine learning based on its knowledge and capabilities.
While individual agents are powerful, the true strength of CrewAI lies in creating teams of agents that work together. Here's a simple example of how you might integrate your agent into a crew:
from crewai import Crew, Task researcher = Agent( role="Researcher", goal="Find the latest information on AI advancements", backstory="You are an AI researcher always on the cutting edge of technology.", verbose=True ) writer = Agent( role="Technical Writer", goal="Explain complex AI concepts in simple terms", backstory="You are a skilled writer with a talent for making difficult topics accessible.", verbose=True ) research_task = Task( description="Research the latest developments in natural language processing", agent=researcher ) writing_task = Task( description="Write a blog post explaining recent NLP advancements to a general audience", agent=writer ) crew = Crew( agents=[researcher, writer], tasks=[research_task, writing_task] ) result = crew.kickoff() print(result)
This example creates a simple crew with two agents: a researcher and a writer. The crew is assigned two tasks, which the agents will work on collaboratively to produce a final result.
Creating your first basic agent in CrewAI is an exciting step into the world of multi-agent AI systems. By defining roles, goals, and capabilities, you can create specialized agents that work together to tackle complex tasks. As you become more familiar with CrewAI, you'll be able to create increasingly sophisticated agents and crews, opening up new possibilities in generative AI applications.
08/11/2024 | Generative AI
25/11/2024 | Generative AI
27/11/2024 | Generative AI
31/08/2024 | Generative AI
27/11/2024 | Generative AI
27/11/2024 | Generative AI
27/11/2024 | Generative AI
08/11/2024 | Generative AI
03/12/2024 | Generative AI
27/11/2024 | Generative AI
28/09/2024 | Generative AI
06/10/2024 | Generative AI