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

# Lifecycle

> The three phases of a LITE Mode LiveAvatar session

Every LITE Mode session follows three phases: **starting**, **managing**, and **ending**.

## 1. Starting a Session

1. Generate a session token configured for LITE Mode on your backend
2. Start the session using that token
3. The avatar streams into the specified WebRTC room after initialization

```mermaid theme={null}
sequenceDiagram
    participant User as End User
    participant Frontend as Developer Frontend
    participant Agent as Developer API / Agent
    participant Room as Session Room
    participant API as LiveAvatar API

    User->>Frontend: User visits site
    Frontend->>Agent: Start Session Flow
    Agent->>API: POST /v1/sessions/token
    API-->>Agent: Session scoped token
    Agent->>API: POST /v1/sessions/start
    API-->>Agent: Session Details
    Note right of API: LiveAvatar sends the<br/>Avatar to Room
    Agent->>Room: Establish agent connection
    Frontend->>Room: Establish user connection
    Room-->>Frontend: Conversation Start
    Frontend-->>User: User sees Avatar conversation
```

<Tip>
  Your backend should manage both token generation and session start. Pass the WebRTC credentials to your frontend.
</Tip>

<Warning>
  Ensure the session token is explicitly set to `"LITE"` mode. The token configuration determines which mode initializes.
</Warning>

## 2. Managing the Session

LITE Mode provides a WebSocket connection for controlling the avatar. The typical flow:

1. **User speaks** — audio is sent to the room
2. **Your agent processes** — your STT/LLM/TTS pipeline handles the input
3. **Agent constructs response audio** — your TTS generates the speech
4. **Agent streams audio via WebSocket** — send audio chunks to LiveAvatar
5. **LiveAvatar renders video** — avatar video frames are sent to the room

Your "agent" can be anything from a simple backend service to a complex multi-model pipeline.

### Audio format

Audio sent to LiveAvatar must be **PCM 16-bit 24KHz**, Base64-encoded. Recommended chunk size is \~1 second, with a maximum of 1MB per WebSocket packet.

### Latency

LiveAvatar generates avatar video in real time as audio arrives — there is no batch processing or queuing delay on the LiveAvatar side.

* **Plugin path** — end-to-end latency depends on your pipeline (STT, LLM, TTS, and network). LiveAvatar adds minimal overhead on top of your existing stack.
* **Connector path** — LiveAvatar manages the full connection to your voice agent and optimizes latency on your behalf.

```mermaid theme={null}
graph LR
    User["User"] -->|"user audio"| Room["Session Room"]
    Room -->|"avatar video"| User
    Room -->|"audio sent to agent"| Agent["Developer Agent"]
    API["LiveAvatar API"] -->|"stream avatar video"| Room
    Agent -->|"ws command event"| API
    API -->|"ws server event"| Agent
```

### WebSocket commands

Through the WebSocket, you can:

* Command the avatar to speak (by sending audio)
* Interrupt avatar responses
* Modify avatar poses (listening, idle)
* Keep sessions alive

## 3. Ending the Session

When a session ends:

1. The avatar is removed from the LiveKit room
2. The room is torn down (if created by LiveAvatar)
3. The WebSocket connection closes

Clean up your WebSocket resources and LiveKit data after the session ends.
