If you’re into AI and automation, then CrewAI is a tool you need to check out. With just a few lines of code, you can install CrewAI and its tools, and with one script, you can get some pretty impressive results. I recently used CrewAI to create an inventory POS and backend dashboard. Let’s get into the process and explore the code that made it happen. Oh yeah, ChatGPT was used too.
Setting Up CrewAI
Getting started with CrewAI is incredibly simple. Once you have it installed along with its tools, you can start creating powerful scripts that automate tasks and deliver impressive outcomes.
Here’s a glimpse of what you can do with CrewAI. I had it create an inventory POS and backend dashboard for me, and the process was seamless.
The Code
With CrewAI, you can define agents and tasks in a Python script to achieve your goals. Here’s an example script that showcases how I set up a team of web developers to build an inventory backend dashboard using a Python Flask app connected to an SQLite database.
import os
from crewai import Agent, Task, Crew
from crewai_tools import SerperDevTool
os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY"
os.environ["SERPER_API_KEY"] = "Your Key" # serper.dev API key
# Define the search tool using SerperDevTool
search_tool = SerperDevTool()
# Define agents with roles and goals
researcher = Agent(
role='Tech Researcher',
goal='Research the best practices and technologies for building a Flask app with SQLite',
backstory="""You are a proficient tech researcher with a keen eye for the latest developments in web development.
You specialize in finding relevant information and summarizing it for development teams.""",
verbose=True,
allow_delegation=False,
tools=[search_tool]
)
backend_developer = Agent(
role='Backend Developer',
goal='Develop the backend for the inventory dashboard using Flask and SQLite',
backstory="""You are an experienced backend developer with expertise in building robust applications using Flask and SQLite.
You excel at designing efficient database schemas and writing server-side logic.""",
verbose=True,
allow_delegation=True
)
frontend_developer = Agent(
role='Frontend Developer',
goal='Develop the frontend for the inventory dashboard using HTML, CSS, and JavaScript',
backstory="""You are a creative frontend developer with a knack for designing intuitive and user-friendly interfaces.
You specialize in HTML, CSS, and JavaScript to bring backend functionalities to life.""",
verbose=True,
allow_delegation=True
)
# Create tasks for your agents
task1 = Task(
description="""Research the best practices and technologies for building an inventory backend dashboard using Flask and SQLite.
Summarize key findings and recommendations.""",
expected_output="Summary of best practices and recommended technologies",
agent=researcher
)
task2 = Task(
description="""Using the research summary, develop the backend for the inventory dashboard using Flask and SQLite.
Implement CRUD operations for inventory items.""",
expected_output="Fully functional backend with Flask and SQLite",
agent=backend_developer
)
task3 = Task(
description="""Using the backend, develop the frontend for the inventory dashboard.
Create an intuitive user interface for adding, viewing, and managing inventory items.""",
expected_output="User-friendly frontend with HTML, CSS, and JavaScript",
agent=frontend_developer
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[researcher, backend_developer, frontend_developer],
tasks=[task1, task2, task3],
verbose=2, # You can set it to 1 or 2 for different logging levels
)
# Get your crew to work!
result = crew.kickoff()
print("######################")
print(result)
# Function to save the result to a file (for demonstration purposes)
def save_result(content, filename="result.txt"):
with open(filename, "w") as file:
file.write(content)
# Save the generated result
result_content = str(result) # Assuming result is string-convertible
save_result(result_content)
print("Result has been saved as result.txt")
Creating a New Team with New Goals
One of the coolest features of CrewAI is its flexibility. You can feed the script into ChatGPT or Claude to generate a brand new team with different goals or tasks. This script serves as a template that you can customize to suit your needs.
Easy to Use
I’m not an AI expert, but I figured this out, and you can too. It’s just one Python file, and when you run it, you get back some impressive stuff. You can even see CrewAI working in real-time in your terminal, which is quite impressive.
Conclusion
CrewAI is an incredible tool that makes automation and AI-driven development accessible to everyone. Whether you’re a seasoned developer or just starting out, CrewAI offers powerful capabilities that can help you achieve your goals. Give it a try, and you’ll see how rad it is for yourself!