Skip to content

This is a basic workflow with CrewAI agents working with sales transactions to draw business insights and marketing recommendations. The agents will work on everything from the execution plan to the business insights report. It works with local LLM via Ollama (I'm using llama3:8B but you can easily change it).

Notifications You must be signed in to change notification settings

cperazza/RFM_Segmentation

Repository files navigation

RFM Segmentation Tool

Project Goals

The RFM Segmentation Tool is designed to help businesses analyze their sales transaction data and segment their customers based on Recency, Frequency, and Monetary (RFM) metrics. This tool utilizes multiple AI agents to manage the project, load and preprocess data, calculate RFM segments, and provide detailed insights and recommendations.

Project Structure

The project is organized into the following directories:

  • config/: Contains YAML configuration files for agents and tasks.
  • src/: Contains the main scripts and agent scripts.
    • agents/: Contains the individual agent scripts.
    • tools/: Contains custom tools if necessary.
  • data/: Contains the output files generated by the agents.
  • venv/: Virtual environment for the project.

Agents and Their Roles

  1. Project Manager: Manages the project scope and execution plan.
  2. Data Loader: Loads and preprocesses sales transaction data.
  3. RFM Calculator: Calculates RFM metrics and segments customers.
  4. Insight Provider: Analyzes RFM segments and provides detailed insights and recommendations.

Installation and Setup

Prerequisites

  • Python 3.11 (or a compatible version)
  • Pip (Python package installer)
  • Git (optional, for cloning the repository)
  • Jupyter Notebook (optional, for running the notebook version)
  • VS Code or PyCharm (optional, for running the script version)
  • Ollama with llama3:8B model installed (or any local model of your preference)

Steps

  1. Clone the Repository

    git clone <https://github.com/cperazza/CrewAI_RFM_Segmentation>
    cd RFM_Tool
  2. Create and Activate Virtual Environment

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install Required Packages

    pip install -r requirements.txt
  4. Configure Local LLM via Ollama Set the following environment variables in your terminal or include them in a .env file.

    export OPENAI_API_BASE='http://localhost:11434/v1'
    export OPENAI_MODEL_NAME='openhermes'  # Adjust based on available model
    export OPENAI_API_KEY=''
  5. Run the Main Script

    python src/main.py

Detailed Interaction Guide

Project Manager Agent

  1. Goal: Define and manage the project scope and execution plan.
  2. Interaction:
    • The agent will ask for detailed project guidelines. Provide a description of your project data.
    • If you have reference files (CSV), provide the file path.
    • The agent will analyze the data and provide an execution plan.
    • Confirm if you are happy with the plan. If not, provide feedback, and the agent will adjust the plan accordingly.
    • The agent will save the execution plan as a PDF in the data/ folder.

Data Loader Agent

  1. Goal: Load and preprocess sales transaction data.
  2. Interaction:
    • The agent will ask for the path to the project data file (CSV).
    • The agent will load and analyze the data, performing exploratory data analysis (EDA).
    • Confirm if you have any questions about the data. The agent will use LLM to provide answers.
    • The agent will calculate RFM, AOV, and AOI metrics and save the processed data as processed_data.csv in the data/ folder.
    • Confirm if you are happy with the processed data. If not, provide feedback, and the agent will adjust the data accordingly.

RFM Calculator Agent

  1. Goal: Calculate RFM metrics and segment customers.
  2. Interaction:
    • The agent will ask for the path to the processed data file (processed_data.csv).
    • The agent will calculate RFM segments using quartiles, quintiles, and deciles.
    • The agent will save the segmented data as rfm_segmented_data.csv in the data/ folder.
    • Confirm if you are happy with the segmented data. If not, provide feedback, and the agent will adjust the segmentation accordingly.

Insight Provider Agent

  1. Goal: Provide detailed insights and recommendations based on RFM analysis.
  2. Interaction:
    • The agent will ask for the path to the segmented data file (rfm_segmented_data.csv).
    • The agent will analyze the RFM segments and generate insights and visualizations.
    • The agent will save the final report as a PDF and the chart code as a Python file in the data/ folder.
    • Confirm if you are happy with the final report and insights. If not, provide feedback, and the agent will adjust the analysis accordingly.

Testing with Real-life Data

To ensure the functionality and performance of the system, load real-life sales transaction data following the standard template:

  • customer_id
  • order_id
  • date
  • revenue

Follow the interaction guide to run the agents sequentially and verify the outputs at each stage.

Conclusion

This documentation provides a comprehensive guide to set up and run the RFM Segmentation Tool using AI agents. Follow the steps carefully to ensure a smooth setup and execution. If you encounter any issues, refer to the troubleshooting section or reach out for support.

Troubleshooting

  • Virtual Environment Issues: Ensure the virtual environment is activated before running any scripts.
  • Package Installation Errors: Check the requirements.txt file for any missing or conflicting packages.
  • LLM Configuration: Ensure the environment variables for Ollama are correctly set.

Contact

For further assistance, please contact [calperazza@gmail.com].

About

This is a basic workflow with CrewAI agents working with sales transactions to draw business insights and marketing recommendations. The agents will work on everything from the execution plan to the business insights report. It works with local LLM via Ollama (I'm using llama3:8B but you can easily change it).

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages