Documentation Index
Fetch the complete documentation index at: https://lemonslice.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Overview
LiveKit Agents provides a realtime framework for voice, video, and multimodal applications. Our open-source integration lets you add a LemonSlice avatar to your existing agent stack.Jump to the example code section for ready-to-use starter repos.
Prerequisites
- LemonSlice avatar configuration (either a base image URL or a LemonSlice avatar ID)
- Agent base image — a publicly accessible image URL of your avatar, focused on the face. The image should be 368 × 560 pixels. LemonSlice will automatically center-crop your image to the target aspect ratio if the dimensions do not match the expected values. Best results are achieved with anthropomorphic images where the face and mouth are clearly identifiable.
- LemonSlice Agent ID
Selected voices and personalities for a LemonSlice agent will be ignored when using the LiveKit plugin.
- LiveKit Agents app
- Your own existing application, or
- The ready-to-use LemonSlice LiveKit Agent Python Example, or
- Follow the LiveKit VoiceAI quickstart for Python or Node.js to create one.
How to use
Authenticate
- Create a LemonSlice API key
- In your LiveKit Agents app, set
LEMONSLICE_API_KEYin your .env file
Add AvatarSession to AgentSession
In your LiveKit Agents app, create a Parameters for
lemonslice.AvatarSession alongside your AgentSession:lemonslice.AvatarSession. Either agent_image_url or agent_id is required.- Python
- Node.js
| Parameter | Description |
|---|---|
agent_image_url | A URL to an agent image to use. |
agent_id | The ID of the LemonSlice agent. |
agent_prompt | (Optional) A high-level system prompt that subtly influences the avatar’s movements, expressions, and emotional demeanor. This prompt is best used to suggest general affect or demeanor (for example, “feel excited” or “look sad”) rather than precise or deterministic actions. |
agent_idle_prompt | (Optional) A high-level system prompt that influences the avatar’s movements, expressions, and emotional demeanor during the idle state. |
idle_timeout | (Optional) Idle timeout in seconds. Defaults to 60. If a negative number is provided, the session will have no idle timeout. |
response_done_timeout | (Optional) Time in seconds to wait without receiving new audio bytes before marking the response as complete. Some TTS models do not send an end response event, or do not send it in a timely manner, after transmitting all audio bytes. This parameter enables detection of response completion when such events are missing or delayed. |
simulcast | (Optional) Enable WebRTC simulcast, which publishes multiple resolutions of the avatar video so subscribers receive the best quality their bandwidth allows. LiveKit rooms only. |
When using the Gemini Live S2S model for realtime interactions, set
response_done_timeout=0.8 to handle end of responses correctly.If you encounter stutters or glitches with any other TTS, please contact support@lemonslice.com.Hook into Events
Listen to LemonSlice RPC events over the LiveKit data channel to better manage the avatar lifecycle:LemonSlice Events
| Event Type | Description |
|---|---|
bot_ready | Fired when the LemonSlice agent has successfully joined the room and is ready to send and receive audio and video. |
idle_timeout | Emitted when the agent stops due to inactivity. The idle timeout threshold is defined by the agent’s configuration. |
error | A pipeline-related error occurred. Includes error and fatal fields. |
video_generation_error | A failure occurred while generating a video segment. |
metric | Returned after every avatar response with performance metrics. Includes time_to_first_push (time from receiving the first audio byte to pushing the first generated video frame). If LiveKit/TTS failed to deliver audio in real time, tts_audio_delay will be set to true. |
These events are available to both your backend agent and frontend client, allowing you to coordinate avatar state across your entire application.
Preview
Preview the avatar in the Agents Playground or refer to one of our end-to-end examples for sample frontend code.
Shutdown the LiveKit room
Gracefully shut down the LiveKit room, LiveKit agent, and/or LemonSlice avatar session:
- Call
ctx.room.disconnect()to close the LiveKit room connection which will end the LemonSlice avatar session. - Call
ctx.shutdown()to stop the Agent’s JobContext and the LemonSlice avatar session if you don’t want to shutdown the LiveKit room. - Call the session control endpoint with the
terminateevent to shutdown only the LemonSlice avatar without shutting down the LiveKit room or agent.
ctx is LiveKit’s agents.JobContext defined by the function annotated with @server.rtc_session()PYTHON
Example Code
| Repo | What’s included |
|---|---|
02-livekit-playground-demo | Starter code to launch a LiveKit agent with the LemonSlice avatar plugin. Run your agent locally and connect in the LiveKit playground for rapid prototyping |
03-livekit-app-python | Fullstack web app using the LiveKit Python SDK. Includes LiveKit Agent + LemonSlice code, front-end UI, and backend token server. |
04-livekit-app-nodejs | Fullstack web app using the LiveKit Node.js SDK. Includes LiveKit Agent + LemonSlice code, front-end UI, and backend token server. |
