File size: 5,741 Bytes
75b0ef8
57951aa
62c4ec3
 
 
 
 
 
 
 
 
57951aa
8929018
 
 
75b0ef8
b6ed6f7
75b0ef8
18ddfa2
75b0ef8
b6ed6f7
 
b95582f
 
 
 
0aa8e87
b95582f
 
0aa8e87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b95582f
 
0aa8e87
 
 
 
 
b95582f
b6ed6f7
0aa8e87
b6ed6f7
18ddfa2
0aa8e87
18ddfa2
b6ed6f7
0aa8e87
b6ed6f7
0aa8e87
b6ed6f7
0aa8e87
 
b6ed6f7
0aa8e87
 
 
 
b6ed6f7
 
 
b95582f
 
 
 
0aa8e87
b95582f
18ddfa2
b6ed6f7
0aa8e87
b6ed6f7
0aa8e87
b6ed6f7
 
 
 
 
 
 
 
 
 
 
 
 
0aa8e87
b6ed6f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0aa8e87
b6ed6f7
 
 
 
2a1f84b
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
title: CallCenterSummarizationAgent
emoji: 🚀
colorFrom: red
colorTo: red
sdk: docker
app_port: 8501
tags:
- streamlit
pinned: false
short_description: Summarize Call Center Conversations
license: mit
# Add arguments here if the SDK supports them:
args: ["--server.enableCORS", "false", "--server.enableXsrfProtection", "false"]
---
---
# Call Center Data Analysis Agent

This project implements a multi-agent workflow using **LangGraph** to process, transcribe, summarize, and score call center data. It comes with a **Streamlit** user interface to easily upload `.csv`, `.json`, `.mp3`, or `.wav` files and view the resulting insights.

## Workflow Flow & Agent Classes

The core analysis logic is driven by a LangGraph StateGraph defined in `src/workflow.py`. The state moves sequentially between several agent classes located in the `src/agents/` directory.

### Workflow Architecture
```text
                  [ IntakeAgent ]
                        |
                        v
               [ Router (file type) ]
              /         |           \
 (CSV invalid)/     (If Audio)     (If Text)
          v          v               v
        (END) [ TranscriptionAgent ] |
                  |                  |
                  v                  |
            [ ModerationAgent ] <-----/
                  |
                  v
          [ SummarizationAgent ]
                  |
                  v
     [ PostSummarizeRouter (output) ]
              |                |
           (END)        [ QualityScoringAgent ]
                               |
                               v
                             (END)
```

Notes:
- The workflow uses a LangGraph memory checkpointer (`MemorySaver`) and fallbacks on critical nodes (summarization/scoring) to avoid UI breakage on transient API/parse errors.
- If CSV headers are invalid, the workflow terminates immediately and the UI shows a validation error.
- After summarization, the workflow can short-circuit to `END` if the transcript is too short or the model output is missing/empty.

### Agent Classes

1. **`IntakeAgent` (`src/agents/IntakeAgent.py`)**
   - *Entry Point*.
   - Reads the uploaded file, validates the file format and schema, extracts basic metadata, and runs a first-pass clean-up (using an LLM).
   - **CSV requirement:** headers must include `id` and `transcript` (case-insensitive).
   - **JSON supported shapes:** a list of `{id, transcript}` objects, a single `{id, transcript}` object, or a dict with `transcripts`/`calls` arrays containing `{id, transcript}` objects.

2. **`Router` (`src/agents/Router.py`)**
   - *Conditional Routing Node*.
   - Determines the next step based on the file type and intake validation state.
   - **If Audio (`.mp3`, `.wav`)**: Routes to the `TranscriptionAgent`.
   - **If Text (`.csv`)**: Routes to the `ModerationAgent` then summarization/scoring.
   - **If CSV invalid**: Routes to `END` (the UI displays `metadata.intake_error`).

   **`PostSummarizeRouter` (`src/agents/Router.py`)**
   - Routes based on model output quality (e.g., short transcript or missing summary can skip scoring).

3. **`TranscriptionAgent` (`src/agents/TranscriptionAgent.py`)**
   - Utilizes `openai-whisper` to convert audio files into text.
   - Also scrubs the resulting transcript of profanity before passing it down the pipeline.

4. **`ModerationAgent` (`src/agents/ModerationAgent.py`)**
   - Receives text either directly from the `Router` (if text upload) or from the `TranscriptionAgent` (if audio upload).
   - Identifies any obscene words or profanity using an LLM and replaces them entirely with a `***` mask to safely prepare the text for downstream analysis.

5. **`SummarizationAgent` (`src/agents/SummarizationAgent.py`)**
   - Takes the redacted text from the `ModerationAgent`.
   - Generates a concise **summary**, **key points**, **action items**, **tags**, and **highlights** using OpenAI (`gpt-4o`) with Pydantic-structured output.

6. **`QualityScoringAgent` (`src/agents/QualityScoringAgent.py`)**
   - Takes the clean text and evaluates it against a predefined rubric.
   - Scores the transcript based on Tone, Professionalism, and Structured Resolution using Pydantic structured output (function calling when supported). Automatically applies a 3-point penalty to each score and logs a count of policy violations if the `ModerationAgent` detected and masked any profanity (`***`).

## Prerequisites

- Python 3.9+
- An OpenAI API key
- `ffmpeg` installed on your system (required for `openai-whisper` audio transcription). 
  - On macOS: `brew install ffmpeg`
  - On Ubuntu/Debian: `sudo apt update && sudo apt install ffmpeg`

## Installation

1. Create a virtual environment and activate it (if you haven't already):
   ```bash
   python3 -m venv .venv
   source .venv/bin/activate
   ```
2. Install the required dependencies:
   ```bash
   pip install -r requirements.txt
   ```

## Running the Application

1. Ensure your OpenAI API key is set in your environment variables:
   ```bash
   export OPENAI_API_KEY="your_api_key_here"
   ```

2. Start the Streamlit application:
   ```bash
   streamlit run src/streamlit_app.py
   ```

3. Open your browser to the local URL provided by Streamlit (usually `http://localhost:8501`).
4. Use the sidebar to upload a `.csv`, `.mp3`, or `.wav` file and watch the agents analyze your data!
 
## Processed Files
 
**Note:** The following sample data can be used for analysis:
- [Customer Call Center Dataset Analysis](https://www.kaggle.com/datasets/rafaqatkhan608/customer-call-center-dataset-analysis/code/data)
- [E-commerce Customer Support English Audio](https://huggingface.co/datasets/HumynLabs/e-commerce-customersupport-english-audio/tree/main)