# qtalen/multi-agent-customer-service architecture

> Architecture diagram of the GitHub repository qtalen/multi-agent-customer-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/qtalen/multi-agent-customer-service
- Repository: https://github.com/qtalen/multi-agent-customer-service

## Overview

##### Project type and purpose
- This is a Python-based multi-agent orchestration demo built on Chainlit (a chat interface) and LlamaIndex Workflow.
- It shows how to implement an “agent handoff” or “swarm” style chat where multiple AI agents collaborate, as described in the two linked articles.

##### File structure
- Top-level:
- data/ : static resources (skus, terms).
- requirements.txt : Python dependencies (chainlit, llamaindex, openai, etc.).
- src/ and src_v2/ : two versions of the same app with slight internal structure differences.
- src/ directory:
- app.py : Chainlit entry point (presentation layer).
- workflow_startup.py : bootstraps the LlamaIndex workflow.
- workflow.py : defines the orchestration logic.
- agents.py : agent definitions, roles, prompts.
- models.py : LLM wrappers or model configuration.
- utils.py : helper functions (data loaders, text processing).
- src_v2/ directory:
- a refactored or alternate version (my_agent.py instead of models.py/utils.py).

##### README insights
- Usage is via `chainlit run src/app.py` or `src_v2/app.py`.
- Dependencies and purpose are clearly documented: a multi-agent orchestration example for LlamaIndex Workflow.

##### Main components and their relationships
a. Presentation Layer
- Chainlit UI (app.py) – accepts user input, displays messages, handles user sessions.
b. Orchestration Layer
- Workflow Startup (workflow_startup.py) – initializes LlamaIndex Workflow, registers agents.
- Workflow Engine (workflow.py) – directs which agent runs on each turn, handles handoff logic.
c. Agent Layer
- Agent Definitions (agents.py / my_agent.py) – each agent’s prompt templates, roles, capabilities.
d. Model Layer
- Model Wrappers (models.py) – functions to call the underlying LLM (OpenAI, etc.).
e. Utility / Data Layer
- Utils (utils.py) – loads static data (data/skus_en.txt, data/terms_en.txt), formatting.
f. External Services
- LLM provider (OpenAI API).
- LlamaIndex Workflow library.

##### Architectural patterns & design principles
- Layered design: UI → orchestrator → agents → LLM.
- Separation of concerns: data loading, prompt definitions, orchestration, and presentation are decoupled.

##### Detail
- Every Python module as a node.
- Distinguish startup (workflow_startup.py) from runtime orchestration (workflow.py).
- Data files feeding into utils.py, and the two entry points (src/app.py vs. src_v2/app.py).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User(("User")):::user

    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Chainlit UI (app.py)"]:::ui
        UI2["Chainlit UI Alt (src_v2/app.py)"]:::ui
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        Startup["Workflow Startup (workflow_startup.py)"]:::orch
        Engine["Workflow Engine (workflow.py)"]:::orch
    end

    %% Agent Layer
    subgraph "Agent Layer"
        Agents["Agent Definitions (agents.py)"]:::agent
        Agents2["Agent Definitions (src_v2/agents.py)"]:::agent
        MyAgent["Alternate Agent (src_v2/my_agent.py)"]:::agent
    end

    %% Model Layer
    subgraph "Model Layer"
        Model["Model Wrapper (models.py)"]:::model
    end

    %% Utility / Data Layer
    subgraph "Utility / Data Layer"
        Utils["Utils (utils.py)"]:::util
        Data1["skus_en.txt"]:::data
        Data2["terms_en.txt"]:::data
    end

    %% External Services
    External["OpenAI API"]:::external

    %% Flows
    User --> UI
    UI --> Startup
    Startup --> Engine
    Engine --> Agents
    Agents --> Model
    Model --> External
    External --> Model
    Model --> Engine
    Engine --> UI
    UI --> User

    %% Alternate path
    User --> UI2
    UI2 --> Startup
    Engine --> Agents2
    Engine --> MyAgent
    Agents2 --> Model
    MyAgent --> Model

    %% Data flows
    Data1 --> Utils
    Data2 --> Utils
    Utils --> Agents
    Utils --> Agents2
    Utils --> MyAgent

    %% Click Events
    click UI "https://github.com/qtalen/multi-agent-customer-service/blob/main/src/app.py"
    click UI2 "https://github.com/qtalen/multi-agent-customer-service/blob/main/src_v2/app.py"
    click Startup "https://github.com/qtalen/multi-agent-customer-service/blob/main/src/workflow_startup.py"
    click Engine "https://github.com/qtalen/multi-agent-customer-service/blob/main/src/workflow.py"
    click Agents "https://github.com/qtalen/multi-agent-customer-service/blob/main/src/agents.py"
    click Agents2 "https://github.com/qtalen/multi-agent-customer-service/blob/main/src_v2/agents.py"
    click MyAgent "https://github.com/qtalen/multi-agent-customer-service/blob/main/src_v2/my_agent.py"
    click Model "https://github.com/qtalen/multi-agent-customer-service/blob/main/src/models.py"
    click Utils "https://github.com/qtalen/multi-agent-customer-service/blob/main/src/utils.py"
    click Data1 "https://github.com/qtalen/multi-agent-customer-service/blob/main/data/skus_en.txt"
    click Data2 "https://github.com/qtalen/multi-agent-customer-service/blob/main/data/terms_en.txt"

    %% Styles
    classDef user fill:#f9f,stroke:#333,stroke-width:1px
    classDef ui fill:#cce5ff,stroke:#1a73e8,stroke-width:1px
    classDef orch fill:#d4edda,stroke:#28a745,stroke-width:1px
    classDef agent fill:#fff3cd,stroke:#ffca2c,stroke-width:1px
    classDef model fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
    classDef util fill:#f1f1f1,stroke:#999,stroke-width:1px
    classDef data fill:#dee2e6,stroke:#6c757d,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#e0bbff,stroke:#800080,stroke-width:1px,stroke-dasharray: 2 2
```
