Coding with CrewAI: AI Orchestration Simplified
Welcome to an exploration of CrewAI, a state-of-the-art framework designed to orchestrate autonomous AI agents. In this post, we’ll dive into the practical aspects of CrewAI, discovering its functionalities and potential applications.
Getting Started
To dive into the world of AI-driven creativity, let’s start by setting up our environment. We’ll create a dedicated Conda environment to ensure seamless integration with CrewAI:
# Create a new Conda environment
conda create -n crewai python=3.10
# Active the environment
conda activate crewai
Now, let’s install CrewAI along with its powerful tools:
pip install crewai
pip install 'crewai[tools]'
Exploring Jan and LM Studio
Before we jump into the coding adventure, let’s indulge in some AI magic with Jan and LM Studio. We’ll harness the power of the remarkable google/gemma-2b-it model:
Unlocking the Potential with Serper
Next, let’s unlock the vast possibilities with Serper, the Google Search API. By leveraging Serper’s capabilities, we can access an ocean of information for our AI agents:
Crafting Brilliance with CrewAI and Jan
Now, let’s delve into the heart of the matter – coding with CrewAI. With a powerful combination of roles and tasks, CrewAI empowers us to unleash our creativity:
import os
os.environ["SERPER_API_KEY"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
os.environ["OPENAI_API_BASE"] = "http://192.168.68.117:1337/v1"
os.environ["OPENAI_MODEL_NAME"] = "NA"
os.environ["OPENAI_API_KEY"] = "NA"
from crewai import Agent
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
# Creating a senior researcher agent with memory and verbose mode
researcher = Agent(
role='Senior Researcher',
goal='Uncover groundbreaking technologies in {topic}',
verbose=True,
memory=True,
backstory=(
"Driven by curiosity, you're at the forefront of"
"innovation, eager to explore and share knowledge that could change"
"the world."
),
tools=[search_tool],
allow_delegation=True
)
# Creating a writer agent with custom tools and delegation capability
writer = Agent(
role='Writer',
goal='Narrate compelling tech stories about {topic}',
verbose=True,
memory=True,
backstory=(
"With a flair for simplifying complex topics, you craft"
"engaging narratives that captivate and educate, bringing new"
"discoveries to light in an accessible manner."
),
tools=[search_tool],
allow_delegation=False
)
from crewai import Task
# Research task
research_task = Task(
description=(
"Identify the next big trend in {topic}."
"Focus on identifying pros and cons and the overall narrative."
"Your final report should clearly articulate the key points"
"its market opportunities, and potential risks."
),
expected_output='A comprehensive 3 paragraphs long report on the latest AI trends.',
tools=[search_tool],
agent=researcher,
)
# Writing task with language model configuration
write_task = Task(
description=(
"Compose an insightful article on {topic}."
"Focus on the latest trends and how it's impacting the industry."
"This article should be easy to understand, engaging, and positive."
),
expected_output='A 4 paragraph article on {topic} advancements formatted as markdown.',
tools=[search_tool],
agent=writer,
async_execution=False,
output_file='new-blog-post.md' # Example of output customization
)
from crewai import Crew, Process
# Forming the tech-focused crew with enhanced configurations
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential # Optional: Sequential task execution is default
)
# Starting the task execution process with enhanced feedback
result = crew.kickoff(inputs={'topic': 'AI in healthcare'})
print(result)
Witness the AI prowess in action as we uncover the latest trends in AI healthcare. Brace yourself for groundbreaking insights!
Another sample topic for AI in proptech. This is the contents of new-blog-post.md:
**
## The Future of PropTech: AI Trends and Challenges
PropTech, the intersection of artificial intelligence and property market, is rapidly evolving. As AI capabilities expand, proptech companies leverage AI to drive growth and improve customer experiences. However, challenges such as data privacy and algorithmic bias need attention to ensure the responsible and inclusive implementation of AI in the proptech industry.
One of the most significant AI trends in proptech is the development of AI-powered property search tools. These tools leverage machine learning algorithms to analyze data and provide users with more relevant and efficient search results. By incorporating AI-powered virtual assistants, property managers can automate tasks, manage maintenance, and respond to customer queries, reducing the workload and improving tenant satisfaction.
Another key AI trend in proptech is predictive analytics. Proptech companies leverage AI algorithms to predict market trends, enabling landlords, property managers, and investors to make informed investment decisions. AI-powered chatbots and virtual assistants provide customers with instant answers to their inquiries, further enhancing the customer experience.
However, despite the immense potential of AI in proptech, challenges remain. One major concern is data privacy and security. Proptech companies require access to vast amounts of data to train AI models, raising significant concerns about data privacy and potential misuse. To address this challenge, proptech companies must prioritize data security, implement robust data governance practices, and comply with stringent data privacy regulations.
Another challenge is algorithmic bias. AI algorithms trained on biased data can perpetuate these biases, leading to discriminatory outcomes in property rental and management. Proptech companies must be mindful of the potential for algorithmic bias and take steps to mitigate it through data cleaning, bias detection, and transparent decision-making practices.
Creating an Impressive Resume with LM Studio
Let’s embark on a journey to enhance our professional presence with CrewAI. We’ll harness its capabilities to craft a captivating resume tailored to our unique experiences:
import os
os.environ["SERPER_API_KEY"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
os.environ["OPENAI_API_BASE"] = "http://192.168.68.117:1234/v1"
os.environ["OPENAI_MODEL_NAME"] = "NA"
os.environ["OPENAI_API_KEY"] = "NA"
from crewai import Agent
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
# Creating a researcher agent to search for relevant resume information
researcher = Agent(
role='Researcher',
goal='Find relevant resume information based on user {experience}',
verbose=True,
memory=True,
backstory=(
"With a background in information retrieval, you excel at finding"
"the most suitable resources to create a tailored resume."
),
tools=[search_tool],
allow_delegation=True
)
# Creating a writer agent to compose a stunning resume
writer = Agent(
role='Writer',
goal='Craft a compelling and professional resume based on gathered information',
verbose=True,
memory=True,
backstory=(
"With expertise in crafting narratives, you transform raw data"
"into an impactful resume that showcases the user's strengths."
),
tools=[search_tool],
allow_delegation=False
)
from crewai import Task
# Research task to find relevant resume information
research_task = Task(
description=(
"Search for resume templates and examples based on user input"
"experience in {experience}. Gather information on formatting, sections, and"
"content that can be used to create a personalized resume."
),
expected_output='A collection of relevant resume templates and examples.',
tools=[search_tool],
agent=researcher,
)
# Writing task to compose the final resume
write_task = Task(
description=(
"Compose a professional resume tailored to the user's input experience."
"Organize the information obtained from the research task into appropriate"
"sections and format the resume to make it attractive and easy to read."
),
expected_output='A polished resume formatted as a markdown.',
tools=[search_tool],
agent=writer,
async_execution=False,
output_file='final_resume.md' # Example of output customization
)
from crewai import Crew, Process
# Forming the crew for resume creation
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential # Optional: Sequential task execution is default
)
# Starting the task execution process
result = crew.kickoff(inputs={'experience': 'I graduated with a degree in Computer Science, having full stack experience in Angular and C++'})
print(result)
Behold the masterpiece – a meticulously crafted resume that showcases our skills and accomplishments - final_resume.md:
**
```markdown
# My Name
---
## Header
* Full Stack Developer
* Angular & C++ Expert
* Strong Problem-Solver & Team Player
## Introduction
I am a highly motivated and experienced full-stack developer with a deep understanding of both the front-end and back-end of software development. I am passionate about solving complex problems and building robust, scalable solutions that meet user requirements.
## Skills
* Front-End Technologies: HTML5, CSS3, JavaScript, React, Angular, Vue.js
* Back-End Technologies: NodeJS, Python, SQL, MongoDB, AWS, Azure
* Tools & Frameworks: Bootstrap, MaterializeCSS, JQuery, Git, Docker, Firebase
## Experience
**Software Engineer (2019 - Present)**
* Developed and maintained a complex web application using Angular and NodeJS.
* Implemented new features and functionalities that improved the user experience.
* Collaborated effectively with a team of developers to ensure project deadlines were met.
**Freelance Developer (2017 - 2019)**
* Built a wide range of web applications using various technologies, including HTML5, CSS3, JavaScript, and jQuery.
* Developed a strong understanding of front-end and back-end development principles.
* Successfully completed multiple projects on time and within budget.
## Education
**University of Technology (2017)**
* Bachelor's Degree in Computer Science
## Certifications
* Angular Certified Developer
* NodeJS Certification
* AWS Certified Solutions Architect
## References
Available upon request.
With CrewAI by our side, the possibilities are limitless. Let’s continue pushing the boundaries of creativity and innovation!