> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leavo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Multi-Agent and Multi-Channel

> How support for multiple assistants and channels per lead works

## Overview

Leavo supports **multi-channel** and **multi-agent**, allowing the same lead to communicate through different channels (WhatsApp, Telegram, Email) with different AI assistants on each one.

## Lead Channels

Each lead can have multiple channel associations. Each association (`LeadChannel`) tracks:

```json theme={null}
{
  "id": "uuid",
  "lead_id": "uuid",
  "channel_id": "uuid",
  "assistant_id": "uuid",
  "channel_name": "WhatsApp Business",
  "channel_type": "whatsapp",
  "department_id": "uuid",
  "assigned_user_id": "uuid",
  "is_primary": true,
  "message_count": 42,
  "last_used_at": "2024-01-15T10:00:00Z"
}
```

## How It Works

```
Lead "John Smith"
├── WhatsApp Business (Channel 1)
│   └── Assistant A (Sales)
│
├── WhatsApp Support (Channel 2)
│   └── Assistant B (Support)
│
└── Telegram (Channel 3)
    └── Assistant C (General)
```

* Each channel has its own AI assistant
* Each channel can belong to a different department
* Message counts and last usage are tracked per channel
* One channel can be marked as **primary** (`is_primary`)

## Supported Channels

| Type       | Providers                            |
| ---------- | ------------------------------------ |
| `whatsapp` | Z-API, Evolution API, Gupshup (Meta) |
| `telegram` | Bot API                              |
| `email`    | SMTP/IMAP                            |
| `sms`      | Various                              |

## WhatsApp Provider Types

| Provider      | Type            | Description                           |
| ------------- | --------------- | ------------------------------------- |
| Z-API         | `z-api`         | Unofficial API (Baileys)              |
| Evolution API | `evolution-api` | Unofficial API                        |
| Gupshup       | `gupshup`       | Official Meta API (WhatsApp Business) |

<Note>
  Gupshup (Meta) channels support official templates and are required for sending messages after the 24-hour window.
</Note>

## Human Attendants

When an operator manually sends a message, they are registered as an **attendant** for that lead on that channel:

```bash theme={null}
GET /backend/leads/{id}/attendants
```

**Response:**

```json theme={null}
[
  {
    "user_id": "uuid",
    "user_name": "Maria Santos",
    "channel_name": "WhatsApp Business",
    "channel_type": "whatsapp",
    "assistant_name": "Sales Assistant",
    "department_name": "Sales",
    "last_message_at": "2024-01-15T10:00:00Z",
    "message_count": 15
  }
]
```

## Agencies

Leavo supports an organization hierarchy:

| Type                  | Description                                           |
| --------------------- | ----------------------------------------------------- |
| **Agency** (`agency`) | Main organization that manages multiple clients       |
| **Client** (`client`) | Organization linked to an agency (`parent_tenant_id`) |

Agencies can create and manage their clients, each with their own leads, channels, and assistants.
