Introduction
With each iteration of the LLM growth, we’re nearing the age of AI brokers. An age the place AI brokers are deeply built-in into software program workflows, dealing with nearly all of duties, from automating private productiveness duties like scheduling conferences and managing emails to offering personalised reminders and organizing each day to-do lists. On an enterprise degree, AI brokers can streamline operations by automating buyer help, optimizing provide chain logistics, enhancing knowledge evaluation, and enhancing decision-making processes. This enables companies to function extra effectively, cut back prices, and focus human efforts on extra inventive duties. However to construct brokers that work isn’t a straightforward process, particularly in manufacturing. A lot effort is being spent to construct the tooling ecosystem to make brokers helpful and dependable. This text will discover two such instruments, CrewAI and Composio, for constructing helpful AI brokers utilizing Claude Sonet.
Studying Goal
- Perceive AI brokers.
- Study CrewAI – a device for orchestrating AI brokers.
- Discover Compoiso – a platform for integrating instruments with Brokers.
- Construct an AI analysis assistant with Slack and Notion integration.
This text was printed as part of the Information Science Blogathon.
What are AI Brokers?
The time period AI brokers is being utilized in each fashionable AI discourse these days. So, what are AI brokers? The brokers are items of software program that may dynamically work together with their setting through a set of instruments, and the “AI” in “AI brokers” seek advice from the Giant Language Fashions or Giant Multi-modal Fashions.
As we all know, LLMs possess a condensed type of human data of their weights, which permits them to research and motive a posh process step-by-step. When the LLMs have entry to the best instruments, they will break down an issue assertion and use the best instruments to execute duties as and when wanted. The most effective instance of this is able to be Chatgpt app itself. It has entry to the code interpreter, the Web, and Dalle. Based mostly on the given immediate, it decides what to make use of and when. So, AI brokers are LLMs augmented with instruments and targets.
Nonetheless, straightforwardly utilizing instruments with LLMs is probably not sufficient for performing complicated duties. We have to orchestrate a number of brokers with particular instruments and targets.
What’s CrewAI?
CrewAI is an open-source device for orchestrating a number of AI brokers to perform complicated duties. It offers a collaborative strategy the place brokers can assume roles, delegate duties, and share targets, akin to a real-world crew. These are the core options of CrewAI.
- Brokers: Brokers are autonomous items accountable for reasoning, process delegation, and speaking with different brokers akin to the staff members in a real-world staff.
- Duties: Duties are particular assignments given to brokers. It particulars all of the steps and actions an agent must take to carry out a required goal.
- Instruments: Instruments are essential to carry out duties which can be past the LLMs, similar to net scraping, responding to emails, process scheduling, and so on.
- Course of: The processes in CrewAI orchestrate the execution of duties by brokers. This ensures duties are distributed and executed effectively by brokers in a predefined method. The method is both sequential, the place duties are accomplished sequentially, or hierarchical, the place duties are executed based mostly on a managerial hierarchy.
- Crews: The Crews in CrewAI are collaborative brokers with duties and instruments working in the direction of undertaking complicated duties.
Here’s a thoughts map for CrewAI.
What’s Composio?
Composio is a platform that gives 100+ instruments, similar to Slack, GitHub, Discord, and so on, with actions and triggers to combine with the AI workflows. It may be built-in with LangChain, Autogen, and CrewAI to make brokers helpful and dependable. This makes it a lot simpler for brokers to work with exterior apps. On this article, we’ll use the Slack and Notion instruments from Composio to construct an AI assistant that listens to a Slack channel and writes a full report on the subject to a Notion file. So, let’s hop on to the coding half.
Constructing an AI Analysis Assistant
Let’s outline the objective of our AI analysis assistant. So, our AI analysis assistant consists of a set of brokers working in collaboration to perform the duty. The assistant listens to a particular Slack channel through a Slack bot, and when a message is distributed to the channel, the AI crew springs into motion. It takes the Slack message as the primary process, sequentially distributes the duties to the analysis agent to offer urgent factors, an analyst to explain and broaden on these factors, a Notion agent to create and write the contents to a textual content file, and eventually, the Slack agent to reply in a Slack channel with the textual content doc.
Right here’s the visible illustration of the workflow.
So, right here’s how we shall be constructing.
- Arrange a growth setting utilizing Venv or Poetry.
- Arrange the Composio toolset for Notion and Slack.
- Construct brokers utilizing CrewAI, Composio toolsets, and Anthropic’s Claude Sonnet (can use different fashions).
- Construct a Flask server with Ngrok tunneling that listens to the Slack bot.
Step 1: Set-Up Setting
To start out, create a digital setting and set up the dependencies listed under.
crewai[tools]==0.*
composio-crewai==0.2.*
composio-langchain==0.2.*
composio-core==0.2.*
flask==3.0.3
python-dotenv==1.0.1
langchain-anthropic
For those who use Poetry, then clone the repository and run
poetry set up
poetry shell
We additionally want a safe Ngrok tunnel for the native Flask server to obtain triggers from the Slack bot. Ngrok is a safe tunneling service that exposes the native server to the web for growth and testing actions. So, set up Ngrok, relying in your system OS. Chances are you’ll must create an account with them. As soon as downloaded, join port 2000 to Ngrok, the place we’ll host our Flask server.
ngrok http 2000
This could begin a ngrok tunnel to port 2000.
Additionally, we have to outline a couple of setting variables, an Anthropic API key, a Slack Channel ID, and a set off ID. So, create these variables in a .env file.
ANTHROPIC_API_KEY=
CHANNEL_ID=
TRIGGER_ID=
Add your API key and Slack channel ID. Yow will discover the Slack channel ID from its URL, which often begins with “C*”; for instance, C074RUF0UQ5 is the channel ID of the channel https://app.slack.com/consumer/T074SRB4FGS/C073RUF0UQ5. We’ll set the TRIGGER_ID within the subsequent part.
Now, we have to arrange our Notion and Slack toolset from Composio. To take action, use the Composio CLI so as to add instruments.
poetry run composio-cli add notion
poetry run composio-cli add slack
Now, set the set off callback to the Ngrok URL. This may join the Slack bot to the Flask server through the Ngrok tunnel.
poetry run composio-cli set global-trigger-callback "<ngrok-url>"
Substitute <ngrok-url> with the .app URL from Ngrok proven within the terminal.
Now, allow the Slack obtain set off. This may allow the Slack bot to obtain messages from the Slack channel and ship them to the tunneled server.
poetry run composio-cli enable-trigger slack_receive_message
It’s going to output a TRIGGER_ID. Now, replace the identical in .env.
Construct Brokers with CrewAI
Now, let’s construct the brokers. On this setup, we outline 4 completely different brokers: a researcher to interrupt down the duties, an analyst to research the duties, a notion agent to write down content material to a textual content file, and a Slack agent to ship affirmation of the duty together with the textual content file to the Slack channel.
Outline Agent roles and Duties
First, we have to outline Agent roles and duties. We will outline these in two completely different Yaml recordsdata: the Yaml config recordsdata for Brokers.
researcher:
position: >
{subject} Senior Information Researcher
objective: >
Uncover cutting-edge developments in {subject}
backstory: >
You are a seasoned researcher with a knack for uncovering the newest
developments in {subject}. Identified to your capability to search out probably the most related
data and current it clearly and concisely.
reporting_analyst:
position: >
{subject} Reporting Analyst
objective: >
Create detailed experiences based mostly on {subject} knowledge evaluation and analysis findings
backstory: >
You are a meticulous analyst with a eager eye for element. You are identified for
your capability to show complicated knowledge into clear and concise experiences, making
it simple for others to know and act on the data you present.
notion_agent:
position: >
Notion Updater
objective: >
You're taking motion on Notion utilizing the Notion API
backstory: >
You're AI agent that's accountable for taking actions on Notion on
customers behalf. It is advisable to take motion on Notion utilizing Notion APIs
slack_agent:
position: >
Slack Updater
objective: >
You're taking motion on Slack utilizing the Notion API
backstory: >
You're an AI agent that's accountable for taking actions on Slack on
customers behalf. It is advisable to take motion on Slack utilizing Slack APIs
Outline an analogous file for duties.
research_task:
description: >
Conduct a radical analysis about {subject}
Be sure you discover any attention-grabbing and related data given
the present yr is 2024.
expected_output: >
A listing with 10 bullet factors of probably the most related details about {subject}.
reporting_task:
description: >
Evaluate the context you bought and broaden every subject right into a full part for a report.
Be certain that the report is detailed and incorporates any and all related data.
expected_output: >
A totally fledge report with the primary matters, every with a full part of data.
Formated as markdown with out lacking something.
notion_task:
description: >
Write a doc on the Notion of the abstract of the given content material.
expected_output: >
A Notion doc with a title and contents.
slack_task:
description: >
Write a message on slack channel 'random' that summarizes the entire Crewai
analysis exercise.
Write a abstract
of your findings and fasten the report.
expected_output: >
A Slack message with a abstract of complete actions achieved and last output.
Construct Brokers
Create a brand new file and import libraries and env variables.
import os
from composio_crewai import App, ComposioToolset
from crewai import Agent, Crew, Course of, Activity
from crewai.venture import CrewBase, agent, crew, process
from langchain_anthropic import ChatAnthropic
ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY")
if ANTHROPIC_API_KEY is None:
print("Please set ANTHROPIC_API_KEY setting variable within the .env file")
exit(1)
Outline LLM and Composio toolset.
llm = ChatAnthropic(
model_name="claude-3-sonnet-20240229",
api_key=ANTHROPIC_API_KEY
)
notion_composio_toolset = ComposioToolset(apps=[App.NOTION])
slack_composio_toolset = ComposioToolset(apps=[App.SLACK])
CrewAI offers decorators for brokers, duties, and crew to outline them conveniently.
@CrewBase
class ClientCrew:
"""Class representing the Consumer crew"""
agents_config = "config/brokers.yaml"
tasks_config = "config/duties.yaml"
@agent
def researcher(self) -> Agent:
"""Create a researcher agent"""
return Agent(
config=self.agents_config["researcher"],
verbose=True,
llm=llm,
)
@agent
def reporting_analyst(self) -> Agent:
"""Create a reporting analyst agent"""
return Agent(
config=self.agents_config["reporting_analyst"], verbose=True, llm=llm
)
@agent
def notion_agent(self) -> Agent:
"""Create a notion agent"""
return Agent(
config=self.agents_config["notion_agent"],
verbose=True,
instruments=notion_composio_toolset,
llm=llm,
)
@agent
def slack_agent(self) -> Agent:
"""Create a slack agent"""
return Agent(
config=self.agents_config["slack_agent"],
verbose=True,
instruments=slack_composio_toolset,
llm=llm,
)
@process
def research_task(self) -> Activity:
"""Create a analysis process"""
return Activity(config=self.tasks_config["research_task"], agent=self.researcher())
@process
def reporting_task(self) -> Activity:
"""Create a reporting process"""
return Activity(
config=self.tasks_config["reporting_task"],
agent=self.reporting_analyst(),
output_file="report.md",
)
@process
def notion_task(self) -> Activity:
"""Create a notion process"""
return Activity(
config=self.tasks_config["notion_task"],
agent=self.notion_agent(),
instruments=notion_composio_toolset,
)
@process
def slack_task(self) -> Activity:
"""Create a slack process"""
return Activity(
config=self.tasks_config["slack_task"],
agent=self.slack_agent(),
instruments=slack_composio_toolset,
)
@crew
def crew(self) -> Crew:
"""Create the Consumer crew"""
return Crew(
brokers=self.brokers, duties=self.duties, course of=Course of.sequential, verbose=2
)
That is achieved. We’ve outlined the required Brokers, Duties, the Course of, and Crew.
Create Flask Server
Now, we have to outline a Flask server. The server API has solely a single endpoint that receives the message from the bot and kicks off the Crew into motion.
# fundamental.py
import os
from dotenv import load_dotenv
from flask import Flask, request
load_dotenv()
from consumer import ClientCrew
app = Flask(__name__)
TRIGGER_ID = os.environ.get("TRIGGER_ID", None)
CHANNEL_ID = os.environ.get("CHANNEL_ID", None)
if TRIGGER_ID is None or CHANNEL_ID is None:
print("Please set TRIGGER_ID and CHANNEL_ID setting variables within the .env file")
exit(1)
def run_crew(subject: str):
inputs = {"subject": subject}
ClientCrew().crew().kickoff(inputs=inputs)
async def async_run_crew(channel, textual content, consumer):
if channel == CHANNEL_ID:
run_crew(textual content)
return "Crew run initiated", 200
@app.route("https://www.analyticsvidhya.com/", strategies=["POST"])
async def webhook():
payload = request.json
message_payload = payload.get("payload", {})
channel = message_payload.get("channel", "")
if channel == CHANNEL_ID:
print("Payload acquired", payload)
textual content = message_payload.get("textual content", "")
consumer = message_payload.get("consumer", "")
return await async_run_crew(channel, textual content=textual content, consumer=consumer)
if __name__ == "__main__":
app.run(port=2000, debug=True)
Now run the primary.py to fireside up the Flask server on the localhost 2000 port the place the Ngrok has been configured.
python fundamental.py
Go to the Slack channel that you just chosen and ship a message. The server will immediately decide this up, and the Crew workflow will begin. The success of the duty relies on the standard of the mannequin. Greater and higher fashions like GPT-4/GPT-4o and Claude Opus are likely to carry out higher. Sonnet does an excellent job.
The AI agent wrote this when requested to write down SRS for a React, NodeJs, and SQLite Chat App.
Right here is the repository of the codes: sunilkumardash9/CrewAIxComposio-Analysis-Assistant
Method Ahead
We created an AI analysis assistant that may create a pleasant report of duties and replace it to a Notion file. You’ll be able to add brokers with web entry through SERP instruments to make the assistant extra versatile. The Composio helps 100+ instruments with actions and triggers to let the brokers freely work together with third-party providers. You should utilize the instruments to make the brokers higher and extra helpful.
Conclusion
The event of AI brokers is occurring in full swing and is now the most popular subject within the AI house. And because the tooling and LLM infrastructure improves, it may be anticipated the following technology of software program programs could have AI brokers constructed into them. Many mundane workflows shall be dealt with by AI brokers geared up with dependable and helpful instruments. We noticed a small glimpse whereas constructing our AI analysis assistant with Slack and Notion instruments integration.
Key Takeaways
- AI brokers are LLMs or Giant Multi-modal Fashions enhanced with instruments and targets, enabling them to work together dynamically with their setting and carry out duties.
- CrewAI is an open-source device that orchestrates a number of AI brokers to collaboratively accomplish complicated duties by assigning roles, delegating duties, and sharing targets.
- Composio is a platform providing over 100 instruments, similar to Slack and GitHub, with actions and triggers for AI workflows. It seamlessly integrates with LangChain, Autogen, and CrewAI.
- Combine Composio toolsets with AI agent frameworks like CrewAI to automate workflows that require planning and decision-making.
The media proven on this article isn’t owned by Analytics Vidhya and is used on the Creator’s discretion.
Incessantly Requested Questions
A. AI brokers are LLMs or Giant Multi-modal Fashions enhanced with instruments and targets, enabling them to work together dynamically with their setting and carry out duties.
A. CrewAI is an open-source agent orchestration framework for constructing role-playing and collaborative brokers.
A. Composio is a platform that integrates environment friendly instruments with an agent framework for interacting with third-party providers like Discord, Slack, GitHub, and so on for undertaking complicated duties.
A. CrewAI can create collaborative brokers that may plan, motive, and delegate duties to different brokers akin to a real-world crew for undertaking duties.
A. In Autogen, orchestrating brokers’ interactions requires extra programming, which might grow to be complicated and cumbersome as the dimensions of duties grows.