AI

Leveraging Composio for Advanced Multi-Agent AI Applications

A visual representation of AI agents working together using Composio framework.

Leveraging Composio for Advanced Multi-Agent AI Applications

Hello! I'm Tommy, and today we're diving into the fascinating world of AI-driven automation using the Composio framework. Composio supercharges AI agents by allowing them to interact seamlessly with over 150 tools, making it a powerful solution for automating complex tasks with minimal effort.

In this guide, we'll explore how to harness the power of Composio and the AutoGen framework to create a multi-agent system that reads customer feedback from a CSV file, analyzes the data, and generates a detailed summary report in a Google Doc. Stick around to see it all come together with hands-on examples and practical insights, with hands-on implementation in Google Colab at the end!

Prerequisites

Before diving into this tutorial, ensure you have the following:

  • Python (3.8 or higher): Ensure Python is installed on your system. You can download it from the official Python website.
  • Conda: We'll use a Conda environment to manage dependencies. If you don't have Conda installed, follow the installation guide here.
  • VS Code: We'll be working in Visual Studio Code for managing our project files and code. You can download it here.
  • Composio account: Sign up for a free account at Composio's official website and gain access to the 150+ external tools it integrates.
  • Groq API Key: You can access the API key from here after signing up.
  • Google account: We'll interact with Google Docs.

Setting Up the Environment

Let's get started with setting up our environment. Here’s how to do it step by step:

Step 1: Create a Directory and Open in VS Code

First, open your terminal and create a new directory for your project. You can name the directory anything you like, but for this tutorial, we'll use composio-test. Then, navigate into the directory. Once inside the directory, open it in Visual Studio Code by running the following command:

code .

Step 2: Create and Activate a Conda Environment

Next, you’ll need to create a new Conda environment. This environment will house all the dependencies needed for this project. To do this, run the command below in your VSCode terminal:

conda create --name composio-test python=3.8

After the environment is created, activate it:

conda activate composio-test

Step 3: Create a Python File

In the VS Code directory, create a new file called app.py. This will serve as the main file where you’ll write the logic for your multi-agent system.

Step 4: Select the Correct Interpreter in VS Code

Make sure your VS Code is using the interpreter from the composio-test Conda environment. To do this:

  1. Open the Command Palette in VS Code (Cmd/Ctrl + Shift + P).
  2. Search for "Python: Select Interpreter."
  3. Select the interpreter that corresponds to your new Conda environment (e.g., composio-test).

It should show a path like /opt/anaconda3/envs/composio-test/bin/python.

Step 5: Install Required Packages

Now that your environment is set up, let’s install the necessary dependencies using pip. In this case, we'll install composio-autogen and python-dotenv:

pip install composio-autogen python-dotenv

Step 6: Log in to Composio

Once your packages are installed, you need to log in to Composio. Run the following command:

composio login

This will prompt you to follow the login steps, including entering a generated key.

Step 7: Add Google Docs Tool

With Composio set up, it’s time to add the Google Docs tool since we'll be using it to generate a report later. Run the command below:

composio add google-docs

Building the Multi-Agent System

Now, we'll build the multi-agent system using Composio and AutoGen. The system will be split into two parts to fully showcase Composio in action and ensure proper communication between the agents.

Step 1: Create the CSV File

First, create a CSV file named dummy_customer_feedback.csv that contains customer feedback data, ratings, names, and more. Here’s an example, but feel free to modify or add more rows to suit your use case:

name,rating,feedback
John Doe,5,Excellent service!
Jane Doe,4,Good but could be faster.

Step 2: Set Up Environment Variables

Create a .env file to store your API keys. You’ll need a Groq API key for the LLaMA3-70B model and a Composio API key, which can be found in your Composio account settings. The .env file should look like this:

GROQ_API_KEY=your_groq_api_key
COMPOSIO_API_KEY=your_composio_api_key

Step 3: Import Required Packages

Now, let's import the necessary packages in your app.py:

import os
import pandas as pd
from dotenv import load_dotenv
from composio import ComposioToolset

Step 4: Load Environment Variables

Use the dotenv library to load your environment variables:

load_dotenv()

Step 5: Define the LLM Configuration

Since we're using Groq's LLaMA3-70B model, define the configuration like this:

LLM_CONFIG = {...}

Part One:

We create agents specifically for the task of reading, analyzing and providing a detailed summary report of key metrics gotten during analysis of a CSV file containing customer feedback.

Step 1: Create the Data Analysis Agent

Next, define the Data Insights Specialist agent, which will provide a summary report of key metrics and trends after analyzing the CSV data.

Step 2: Create the File Parser Agent

The File Parser agent will handle reading, extracting, and formatting the CSV files content:

Step 3: Create the User Agent

The User Agent will collect and return the final summary from the Data Insights Specialist:

Step 4: Create Group Chat and Manager

Now, we'll set up a GroupChat and GroupChatManager to facilitate communication between the agents:

group_chat = ...

Step 5: Initialize Composio Toolset

We now initialize the Composio Toolset, which provides access to all the tools available for our agents:

toolset = ComposioToolset(api_key=os.getenv('COMPOSIO_API_KEY'))

Step 6: Register Tools

We register the tools that will be used by the File Parser and Data Insights Specialist agents:

toolset.register_tool('FILETOOL', actions=[...])

Step 7: Define the Task and Execute the Chat

Define the task that needs to be performed, including the CSV filename:

task = {...}

Finally, retrieve the summary report provided by the Data Insights Specialist:

summary_report = data_insights_specialist.get_summary()

Part Two:

In Part Two, we'll extend the system built in Part One to write the summary report to a Google Document using Composio and AutoGen. We'll create new agents specifically for this task and utilize Google Docs tools available through Composio.

Step 1: Create Agents for Google Docs Writing

We start by defining the agents responsible for writing the summary report to a Google Document.

  • Document Writer Agent: This agent initiates the write operation to the Google Document.
  • Content Writer Agent: This agent is responsible for writing the content to the Google Document.
  • User Agent: This agent ensures the summary report is correctly written to the Google Document.

Step 2: Set Up Group Chat and Manager

We then set up a new GroupChat and GroupChatManager to coordinate these agents:

Step 3: Register the Google Docs Tool

Next, we register the Google Docs tool in Composio for our agents:

Step 4: Write the Summary to Google Docs

Now, we initiate the chat where the summary report generated in Part One is written to a Google Document titled "User Feedback Report":

Running the Python File

Now that our multi-agent system is fully set up, it's time to see it in action! We'll execute our Python script using the terminal in VSCode to observe the magic unfold. In your VSCode terminal, ensure you're in the root directory where your app.py file is located. Then, execute the script by running:

python app.py

Ensure you're using the path to your conda environment.

Review Execution Flow

Once you run your Python file, the logs for each agent and tool should be visible, as verbosity is enabled by default. Now, let’s see the power of Composio tooling in action.

You should see all the tools available in FILETOOL, with the Data Insights Specialist Agent suggesting tool actions to perform based on the task. The agent then delegates the execution to the FILE PARSER and EXTRACTOR agent, which we defined earlier as the executor for the FILETOOL.

After the Extractor agent executes all the suggested tool calls by the Data Specialist agent, it returns all the fields in the CSV file in a formatted way. Then it gives the data to the Data Specialist Agent to generate a detailed report summary based on it. The Data Specialist Agent then generates the report summary.

Next, the User Agent kicks off by passing the summary report provided by the Data Specialist Agent to the Group Chat Manager, which then calls the Document Writer Agent. The Document Writer agent, armed with all actions for interacting with Google Docs, now suggests tool calls for the Content Writer Agent to perform. The Content Writer Agent then starts execution and writes the summary to the Google document as defined by the Document Writer Agent.

After execution, check your Google Drive recents, and you should see the file named 'User Feedback Report' with the summary report.

Next Steps: Expanding Your Use of Composio

Now that you’ve successfully built and run a multi-agent system with Composio, there are several exciting avenues to explore next:

  • Utilizing Triggers for Automated Actions: Triggers are a powerful feature in Composio that can automate workflows based on specific events or conditions. You can set up triggers to initiate actions automatically based on certain criteria.
  • Integrating Additional Tools and APIs: Composio supports a wide range of tools and APIs that you can integrate into your system. Explore the Composio marketplace for ideas.
  • Exploring Advanced Agent Interactions: Experiment with hierarchical agent structures or cooperative learning among agents.
  • Expanding to Other AI Models: Try various AI models supported by Composio or integrate custom models for tailored performance.

Conclusion

In this tutorial, we explored building a multi-agent system using Composio and AutoGen, focusing on analyzing customer feedback from a CSV file and generating a summary report. We walked through setting up the environment, configuring the agents, and using tools to read and analyze data, followed by writing the summary to a Google document.

During the project, I encountered challenges with the OpenAI API and retrieving summary reports in a single step. To overcome these issues, I switched to using the Groq API and split the process into two parts, which successfully achieved the desired outcome. These experiences highlighted both the flexibility of Composio and the importance of troubleshooting and adapting when working with new tools and frameworks.

Composio's vast array of tools and easy integration make it a powerful choice for developers looking to enhance their projects with AI capabilities. I encourage you to explore Composio further by checking out the official documentation. There's a lot more to discover, and I'm excited to continue experimenting with this versatile framework.

Happy coding!

Reading next

A graphic representation of integrating DALLE 2 API with TruLens for enhanced image analysis.
Tutorial on using EasyOCR for text extraction and GPT-3 for summarization.

Leave a comment

All comments are moderated before being published.

This site is protected by hCaptcha and the hCaptcha Privacy Policy and Terms of Service apply.