Introduction
AI agent growth is likely one of the hottest frontiers of Software program innovation. As the standard of Massive Language Fashions evolves, we’ll witness a surge in AI agent integration with present software program methods. With AI brokers, it is going to be attainable to perform duties with voice or gesture instructions as an alternative of manually navigating by means of purposes. However proper now, agent growth is in its nascent stage. We’re nonetheless going by means of the preliminary part of infrastructure, instruments, and framework growth, much like the Web of the Nineties. So, on this article, we’ll talk about one other framework for agent growth referred to as CrewAI.

Studying Aims
- Find out about AI brokers.
- Discover CrewAI – an open-source software for constructing brokers.
- Construct a collaborative AI crew for writing content material.
- Discover real-life use instances of AI brokers.
This text was revealed as part of the Information Science Blogathon.
What are AI Brokers?
The language fashions excel at translation, summarizing, and reasoning. Nonetheless, you are able to do a lot with them. One of many methods to totally notice the reasoning potential is to make LLMs agentic. The AI brokers are LLMs augmented with the proper instruments and prompts. These brokers can automate looking, internet scrapping, SQL question execution, file operations, and extra. The brokers use the reasoning capability of LLMs to pick out a software primarily based on present necessities. However as an alternative of utilizing a single agent for a activity, we are able to ensemble lots of them to perform complicated duties.
Langchain is the default software that involves thoughts when discussing AI brokers. Nonetheless, manually orchestrating AI brokers to carry out collaborative duties can be difficult with Langchain. That is the place CrewAI comes into the image.
What’s CrewAI?
CrewAI is an open-source framework for orchestrating role-playing and autonomous AI brokers. It helps create collaborative AI brokers to perform complicated targets with ease. The framework is designed to allow AI brokers to imagine roles, delegate duties, and share targets, very like a real-world crew. These are a few of the distinctive options of the CrewAI:
- Function-based Brokers: We will outline brokers with particular roles, targets, and backstories to offer extra context to LLMs earlier than reply technology.
- Process administration: Outline duties with instruments and dynamically assign them to brokers.
- Inter-agent delegation: The brokers can delegate duties to different brokers to collaborate successfully.
Under is a illustration of the CrewAI thoughts map.

The CrewAI seamlessly integrates with the Langchain ecosystem. This implies we are able to use the Langchain instruments and LLM integrations with CrewAI.Â
Constructing a Collaborative AI Crew
To grasp CrewAI higher, let’s construct collaborative AI brokers for artistic content material writing. For this, we’ll outline brokers, instruments, and the respective duties for every agent. As it’s a staff for content material writing, we’ll outline three separate brokers, like an concept analyst, a author, and an editor. Every agent will probably be assigned a activity.
The analyst agent will probably be accountable for analyzing the concept and getting ready a complete blueprint for writing the content material. The Author agent will put together the draft for the article, and eventually, the editor will probably be accountable for formatting, enhancing, and correcting the draft. As we all know, CrewAI lets us increase brokers with customized instruments. We are going to increase the editor with a software to reserve it to the native disk. However to perform all these items, we want an LLM. Right here, we’ll use Google’s Gemini mannequin.
Let’s delve into the coding
As with every Python undertaking, create a digital setting and set up the dependencies. We are going to want the Crewai library and Langchain’s implementation of Google GenAI. You should utilize different LLMs, like open-access fashions from Collectively, Any scale, or OpenAI fashions.
pip set up crewai langchain-google-genai
The following step is to outline our LLM and collaborative Brokers. Create a separate file named brokers.py to outline brokers.
import os
from crewai import Agent
from langchain.instruments import software
from langchain_google_genai import GoogleGenerativeAI
GOOGLE_API_KEY = "Your Key"
llm = GoogleGenerativeAI(
mannequin="gemini-pro",
google_api_key=GOOGLE_API_KEY
)
Let’s outline the file-saving software.
class FileTools:
@software("Write File with content material")
def write_file(information: str):
"""Helpful to jot down a file to a given path with a given content material.
The enter to this software must be a pipe (|) separated textual content
of size two, representing the complete path of the file,
together with the ./lore/, and the written content material you need to write to it.
"""
attempt:
path, content material = information.cut up("|")
path = path.change("n", "").change(" ", "").change("`", "")
if not path.startswith("./lore"):
path = f"./lore/{path}"
with open(path, "w") as f:
f.write(content material)
return f"File written to {path}."
besides Exception:
return "Error with the enter format for the software."
The above write_file methodology is adorned with Langchain’s software perform. Because the CrewAI makes use of Langchain beneath the hood, the instruments should adjust to Langchain’s conventions. The perform expects a single string with two components, a file path, and content material separated by a pipe (|). The tactic doc strings are additionally used as added context for the perform. So, be sure you give detailed details about the tactic.
Let’s outline the brokers
idea_analyst = Agent(
position = "Concept Analyst",
objective = "Comprehensively analyse an concept to organize blueprints for the article to be written",
backstory="""You're an skilled content material analyst, effectively versed in analyzing
an concept and getting ready a blueprint for it.""",
llm = llm,
verbose=True
)
author = Agent(
position = "Fiction Author",
objective = "Write compelling fantasy and sci-fi fictions from the concepts given by the analyst",
backstory="""A famend fiction-writer with 2 instances NYT
a best-selling creator within the fiction and sci-fi class.""",
llm=llm,
verbose=True
)
editor = Agent(
position= "Content material Editor",
objective = "Edit contents written by author",
backstory="""You're an skilled editor with years of
expertise in enhancing books and tales.""",
llm = llm,
instruments=[FileTools.write_file],
verbose=True
)
Now we have three brokers, every with a special position, objective, and backstory. This data is used as a immediate for the LLM to offer extra context. The editor agent has a writing software related to it.
The following factor is to outline duties. For this, create a special file duties.py.
from textwrap import dedent
class CreateTasks:
def expand_idea():
return dedent(""" Analyse the given activity {concept}. Put together complete pin-points
for carrying out the given activity.
Ensure that the concepts are to the purpose, coherent, and compelling.
Be sure you abide by the principles. Do not use any instruments.
RULES:
- Write concepts in bullet factors.
- Keep away from grownup concepts.
""")
def write():
return dedent("""Write a compelling story in 1200 phrases primarily based on the blueprint
concepts given by the Concept
analyst.
Ensure that the contents are coherent, simply communicable, and charming.
Do not use any instruments.
Be sure you abide by the principles.
RULES:
- Writing should be grammatically appropriate.
- Use as little jargon as attainable
""")
def edit():
return dedent("""
Search for any grammatical errors, edit, and format if wanted.
Add title and subtitles to the textual content when wanted.
Don't shorten the content material or add feedback.
Create an acceptable filename for the content material with the .txt extension.
You MUST use the software to reserve it to the trail ./lore/(your title.txt).
""")
The duties listed here are detailed motion plans you count on the brokers to carry out.
Lastly, create the primary.py file the place we assemble the Brokers and Duties to create a purposeful crew.
from textwrap import dedent
from crewai import Crew, Process
from brokers import editor, idea_analyst, author
from duties import CreateTasks
class ContentWritingCrew():
def __init__(self, concept):
self.concept = concept
def __call__(self):
duties = self._create_tasks()
crew = Crew(
duties=duties,
brokers=[idea_analyst, writer, editor],
verbose=True
)
outcome = crew.kickoff()
return outcome
def _create_tasks(self):
concept = CreateTasks.expand_idea().format(concept=self.concept)
expand_idea_task = Process(
description=concept,
agent = idea_analyst
)
write_task = Process(
description=CreateTasks.write(),
agent=author
)
edit_task = Process(
description=CreateTasks.edit(),
agent=editor
)
return [expand_idea_task, write_task, edit_task]
if __name__ == "__main__":
dir = "./lore"
if not os.path.exists(dir):
os.mkdir(dir)
concept = enter("concept: ")
my_crew = ContentWritingCrew(concept=concept)
outcome = my_crew()
print(dedent(outcome))
Within the above code, we outlined a ContentWritingCrew class that accepts an concept string from the person. The _create_tasks methodology creates duties. The __call__ methodology initializes and kicks off the crew. When you run the script, you may observe the chain of actions on the terminal or pocket book. The duties will probably be executed within the order they’re outlined by the crew. Here’s a snapshot of the execution log.

That is the execution log for the ultimate agent. i.e. Editor. It edits the draft obtained from the author’s agent and makes use of the file-writing software to save lots of the file with an acceptable filename.
That is the final workflow for creating collaborative AI brokers with CrewAI. You may pair different Langchain instruments or create customized instruments with environment friendly prompting to perform extra complicated duties.
Right here is the GitHub repository for the codes: sunilkumardash9/ContentWritingAgents.
Replit repository: Sunil-KumarKu17/CollborativeAIAgent
Actual-world Use Instances
Autonomous AI brokers can have a number of use instances. From private assistants to digital instructors. Listed below are just a few use instances of AI brokers.
- Private AI Assistant: Private Assistants will probably be an integral a part of us quickly. A Jarvis-like assistant that processes all of your information offers perception as you go and handles trivial duties by itself.
- Code interpreters: OpenAI’s code interpreter is a superb instance of an AI agent. The interpreter can run any Python script and output the ends in response to a textual content immediate. That is arguably essentially the most profitable agent thus far.
- Digital Instructors: Because the AI tech evolves, we are able to count on digital instructors in lots of fields like training, coaching, and many others.
- Agent First Software program: An enormous potential use case of AI brokers is in agent first software program growth. As a substitute of manually looking and clicking buttons to get issues accomplished, AI brokers will mechanically accomplish them primarily based on voice instructions.
- Spatial Computing: Because the AR/VR tech evolves, AI brokers will play a vital position in bridging the hole between the digital and actual world.
Conclusion
We’re nonetheless within the early levels of AI agent growth. Presently, for the absolute best consequence from AI brokers, we have to depend on GPT-4, and it’s costly. However because the open-source fashions catch as much as GPT-4, we’ll get higher choices for operating AI brokers effectively at an inexpensive value. Alternatively, the frameworks for agent growth are progressing quickly. As we transfer ahead, the frameworks will allow brokers to carry out much more complicated duties.
 Key Takeaways
- AI brokers leverage the reasoning capability of LLMs to pick out acceptable instruments to perform complicated duties.
- CrewAI is an open-source framework for constructing collaborative AI brokers.
- The distinctive characteristic of CrewAI contains role-based Brokers, autonomous inter-agent delegation, and versatile activity administration.
- CrewAI seamlessly integrates with the prevailing Langchain ecosystem. We will use Langchain instruments and LLM integrations with CrewAI.
Ceaselessly Requested Questions
A. AI brokers are software program applications that work together with their setting, make selections, and act to realize an finish objective.
A. This relies on your use instances and funds. GPT 4 is essentially the most succesful however costly, whereas GPT 3.5, Mixtral, and Gemini Professional fashions are much less certified however quick and low-cost.
A. CrewAI is an open-source framework for orchestrating role-playing and autonomous AI brokers. It helps create collaborative AI brokers to perform complicated targets with ease.
A. CrewAI offers a high-level abstraction for constructing collaborative AI brokers for complicated workflows.
A. In Autogen, orchestrating brokers’ interactions requires extra programming, which might change into complicated and cumbersome as the size of duties grows.
The media proven on this article shouldn’t be owned by Analytics Vidhya and is used on the Creator’s discretion.


