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.| 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. |
When using the Node.js SDK, parameters should be specified in camelCase. For example:
agent_image_url becomes agentImageUrl.When using the Gemini Live S2S model for realtime interactions, set
response_done_timeout=0.5 to handle end of responses correctly.If you encounter stutters or glitches with any other TTS, please contact support@lemonslice.com.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 code, front-end UI, and backend token server. |
04-livekit-app-nodejs | Fullstack web app using the LiveKit Node.js SDK. Includes LiveKit Agent code, front-end UI, and backend token server. |
