CrewAI Multi-Agent Customer Support Automation | Complete Tutorial

CrewAI Multi-Agent Customer Support Automation | Complete Tutorial

Learn how to automate customer support with CrewAI’s multi-agent AI system. Improve accuracy, efficiency, and response quality using AI-driven automation.

CrewAI Multi-Agent Customer Support Automation | Complete Tutorial
CrewAI Multi-Agent Customer Support Automation | Complete Tutorial

Introduction

Customer support is a critical aspect of any business, and AI-driven automation is transforming the way companies handle inquiries. Multi-agent AI systems enable multiple AI agents to collaborate efficiently, ensuring quick, accurate, and high-quality responses to customer inquiries.

In this tutorial, we will learn how to automate customer support using CrewAI, leveraging six key elements that enhance agent performance:

  • Role Playing
  • Focus
  • Tools
  • Cooperation
  • Guardrails
  • Memory

By the end of this guide, you will have a fully functional AI-powered customer support system that can handle inquiries, ensure quality, and improve customer satisfaction.

Complete Code

import os
import warnings
from crewai import Agent, Task, Crew
from utils import get_openai_api_key
from crewai_tools import SerperDevTool, ScrapeWebsiteTool

# Suppress warnings
warnings.filterwarnings('ignore')

# Set up API key and environment variables
openai_api_key = get_openai_api_key()
os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'

# Define AI Agents
support_agent = Agent(
    role="Senior Support Representative",
    goal="Be the most friendly and helpful support representative in your team",
    backstory=(
        "You work at CrewAI and are providing support to {customer}, an important client."
        "Your role is to ensure they receive complete and accurate answers, leaving no room for confusion."
    ),
    allow_delegation=False,
    verbose=True
)

support_quality_assurance_agent = Agent(
    role="Support Quality Assurance Specialist",
    goal="Ensure the highest quality of customer support responses",
    backstory=(
        "You work at CrewAI, ensuring that all support responses meet the company's standards."
        "Your job is to review responses for accuracy, completeness, and a friendly tone."
    ),
    verbose=True
)

# Import and instantiate AI tools
search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()

docs_scrape_tool = ScrapeWebsiteTool(
    website_url="https://docs.crewai.com/how-to/Creating-a-Crew-and-kick-it-off/"
)

# Define Tasks
inquiry_resolution = Task(
    description=(
        "{customer} just reached out with an important question: {inquiry}."
        "Your job is to provide a complete and informative response."
    ),
    expected_output=(
        "A detailed response that addresses all aspects of the customer's inquiry."
        "Ensure references are included and no details are left out."
    ),
    tools=[docs_scrape_tool],
    agent=support_agent,
)

quality_assurance_review = Task(
    description=(
        "Review the response drafted by the Support Representative for {customer}."
        "Ensure the answer is comprehensive, accurate, and professional."
    ),
    expected_output=(
        "A fully reviewed and improved response, ready for the customer."
    ),
    agent=support_quality_assurance_agent,
)

# Create the Crew with Memory Enabled
crew = Crew(
    agents=[support_agent, support_quality_assurance_agent],
    tasks=[inquiry_resolution, quality_assurance_review],
    verbose=2,
    memory=True
)

# Define Input Values
inputs = {
    "customer": "DeepLearningAI",
    "person": "Andrew Ng",
    "inquiry": "How can I add memory to my CrewAI setup?"
}

# Execute the Support System
result = crew.kickoff(inputs=inputs)

# Display Final Output
from IPython.display import Markdown
Markdown(result)

Step 1: Setting Up the Environment

Before we begin, install the necessary libraries if you’re running this on your machine:

pip install crewai==0.28.8 crewai_tools==0.1.6 langchain_community==0.0.29

We also set up OpenAI’s GPT-3.5 Turbo as our default model:

import os
from utils import get_openai_api_key

openai_api_key = get_openai_api_key()
os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'

Step 2: Defining AI Agents

Agent: Senior Support Representative

The Senior Support Representative is responsible for answering customer inquiries in a detailed and professional manner.

from crewai import Agent

support_agent = Agent(
    role="Senior Support Representative",
    goal="Be the most friendly and helpful support representative in your team",
    backstory=(
        "You work at CrewAI and are providing support to {customer}, an important client."
        "Your role is to ensure they receive complete and accurate answers, leaving no room for confusion."
    ),
    allow_delegation=False,
    verbose=True
)

Agent: Support Quality Assurance Specialist

The Quality Assurance (QA) Specialist reviews responses to ensure they meet customer service standards.

support_quality_assurance_agent = Agent(
    role="Support Quality Assurance Specialist",
    goal="Ensure the highest quality of customer support responses",
    backstory=(
        "You work at CrewAI, ensuring that all support responses meet the company's standards."
        "Your job is to review responses for accuracy, completeness, and a friendly tone."
    ),
    verbose=True
)

Step 3: Enhancing Agent Capabilities

Role Playing, Focus, and Cooperation

  • Agents are given defined roles and goals.
  • They stay focused on their specific tasks.
  • The QA Specialist can cooperate with the Support Agent by requesting changes if needed.

Step 4: Using Tools to Enhance Customer Support

Importing CrewAI Tools

from crewai_tools import SerperDevTool, ScrapeWebsiteTool

Example Custom Tools

  • Customer data retrieval
  • Accessing past conversations
  • Fetching data from CRM
  • Checking existing bug reports
  • Verifying ongoing support tickets

Instantiating Search and Scraper Tools

search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()

To scrape specific documentation pages:

docs_scrape_tool = ScrapeWebsiteTool(
    website_url="https://docs.crewai.com/how-to/Creating-a-Crew-and-kick-it-off/"
)

Step 5: Defining Tasks

Task: Resolving Customer Inquiries

The Support Agent handles incoming customer inquiries.

from crewai import Task

inquiry_resolution = Task(
    description=(
        "{customer} just reached out with an important question: {inquiry}."
        "Your job is to provide a complete and informative response."
    ),
    expected_output=(
        "A detailed response that addresses all aspects of the customer's inquiry."
        "Ensure references are included and no details are left out."
    ),
    tools=[docs_scrape_tool],
    agent=support_agent,
)

Task: Quality Assurance Review

The QA Specialist reviews responses before they reach the customer.

quality_assurance_review = Task(
    description=(
        "Review the response drafted by the Support Representative for {customer}."
        "Ensure the answer is comprehensive, accurate, and professional."
    ),
    expected_output=(
        "A fully reviewed and improved response, ready for the customer."
    ),
    agent=support_quality_assurance_agent,
)

Step 6: Creating the Crew and Enabling Memory

Memory helps agents retain context, improving their responses over time.

from crewai import Crew

crew = Crew(
    agents=[support_agent, support_quality_assurance_agent],
    tasks=[inquiry_resolution, quality_assurance_review],
    verbose=2,
    memory=True
)

Step 7: Running the AI Customer Support System

Defining Input Values

inputs = {
    "customer": "DeepLearningAI",
    "person": "Andrew Ng",
    "inquiry": "How can I add memory to my CrewAI setup?"
}

Executing the Support System

result = crew.kickoff(inputs=inputs)

Displaying the Final Response in Markdown format

from IPython.display import Markdown
Markdown(result)

Conclusion

This tutorial demonstrated how to automate customer support using CrewAI’s multi-agent system. By leveraging specialized agents, AI tools, and memory retention, businesses can provide fast, high-quality support with minimal human intervention.

Would you like to implement this AI-driven customer support system? Start building with CrewAI today! 🚀

Leave a Comment

Your email address will not be published. Required fields are marked *