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

# AI Modules for Intelligent Call Handling

> Attach AI providers to your LaraCopilot tenant to enable intelligent call routing, voice bots, lead qualification, and automated call handling.

AI modules let you connect an AI provider to a specific tenant so that LaraCopilot can handle calls intelligently without human intervention. Each module encapsulates a provider integration, a module type that defines what the AI does, and a JSON configuration block that carries provider-specific settings. Modules are tenant-scoped, so different tenants on the same platform can run different AI providers and behaviours independently.

## Module Fields

Each AI module record holds the following fields:

| Field         | Type        | Required | Description                                                   |
| ------------- | ----------- | -------- | ------------------------------------------------------------- |
| `tenant_id`   | integer     | Yes      | The tenant this module belongs to                             |
| `name`        | string      | Yes      | A human-readable label for the module, max 255 chars          |
| `module_type` | string      | Yes      | The functional role of the module (see below), max 100 chars  |
| `provider`    | string      | Yes      | The AI provider to use (e.g. `openai`, `vapi`), max 100 chars |
| `status`      | string      | Yes      | Whether the module is active or inactive, max 50 chars        |
| `config`      | JSON object | No       | Provider-specific configuration key/value pairs               |

<Note>
  `config` is stored and returned as a JSON object. When submitting via the admin panel form, enter valid JSON in the config textarea — the platform calls `json_decode` on the raw string before saving.
</Note>

## Module Types

The `module_type` field controls what the AI module actually does when attached to a call flow. Based on the platform's AI sub-system, the following module types are supported:

| `module_type`    | Description                                                                                                                                                                                                                                |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `AiLeadAgent`    | A voice AI agent that answers inbound calls, converses with callers, and qualifies them as leads. Configurable with `voice_name`, `language`, `llm_model`, `system_prompt`, and an optional `handoff_destination` for live agent transfer. |
| `AiLeadCampaign` | An outbound dialling campaign that pairs an AI lead agent with a target DID and source number. Drives automated outreach to a list of contacts and tracks outcomes per call.                                                               |
| `AiLeadProduct`  | Associates the module with a specific product offering defined by `product_type` and `api_scope`, allowing the AI to present or qualify callers against a product catalogue.                                                               |

<Tip>
  For inbound lead qualification, use `AiLeadAgent`. For automated outbound prospecting, pair it with an `AiLeadCampaign`. Use `AiLeadProduct` when the AI needs product-aware context during a conversation.
</Tip>

## Creating an AI Module

<Steps>
  <Step title="Open AI Modules in the admin panel">
    Navigate to **AI → Modules** and click **New Module**.
  </Step>

  <Step title="Select a tenant and set the basics">
    Choose the `tenant_id` from the dropdown. Enter a descriptive `name`, select the `module_type` that matches your use case, and choose the `provider` (e.g. `openai`, `vapi`). Set `status` to `active` when you are ready to enable the module.
  </Step>

  <Step title="Supply the provider config">
    In the **Config** textarea, enter a valid JSON object with the settings your provider requires. See the example below for a VAPI-backed lead agent.

    ```json config example — VAPI lead agent theme={null}
    {
      "vapi_assistant_id": "asst_abc123",
      "voice_name": "nova",
      "language": "en-US",
      "llm_model": "gpt-4o",
      "handoff_destination": "+18005550100",
      "mcp_enabled": false
    }
    ```
  </Step>

  <Step title="Save and verify">
    Click **Save**. The module appears in the index with its `tenant`, `module_type`, `provider`, and `status` visible. Toggle `status` to `inactive` at any time to pause the module without deleting it.
  </Step>
</Steps>

## Tenant Isolation

Every AI module is scoped to a single tenant via `tenant_id`. Modules from one tenant are never accessible to another tenant's call flows or admin users. This lets you run different AI providers and prompt strategies per tenant on the same LaraCopilot instance.

<Warning>
  Removing an AI module while it is referenced by an active call flow or campaign will cause those flows to fall back to default handling. Always deactivate (`status: inactive`) before deleting.
</Warning>
