Skip to main content

Overview

Roleplay actions let your avatar break out of standard talking gestures to perform a specific action mid-call—like celebrating, dancing, or sipping a drink—before seamlessly resuming the conversation. Actions are triggered either from a text prompt or from a pre-registered video clip. There are two ways to ask for one:
  • On demand: a text description of what the avatar should do. We generate the action from the avatar’s current look.
  • Registered: a video clip you register when the session starts, then trigger by name.
Roleplay actions are available on LiveKit only.

On-demand actions

Publish a data message on the LiveKit topic ls.roleplay-action with a prompt.
Only one roleplay action runs at a time. Any roleplay action you send while one is in progress is ignored until that action is over.
FieldRequiredDefaultWhat it does
promptyes—What the avatar should do, up to 1000 characters. The action is generated from the avatar’s current look.
durationno5Length in seconds, between 1.5 and 15.
generate_audionofalsetrue generates a soundtrack for the action. false makes it silent.
end_framenoNoneAn https:// URL, or a base64 image, of the look the avatar should end on. That image becomes the avatar’s look after the action. Without it, the avatar returns to the look it had when you sent the prompt. Prefer a URL; inline images must stay small enough to fit in a data message. See changing the avatar’s look.
An on-demand action takes a few seconds to generate. If the avatar is talking when it is ready, it waits until the avatar finishes, then starts.
When you send the request, have the avatar acknowledge it and keep talking while the action generates, for example “Sure, I can dance for you. I have been taking dancing lessons for this exact purpose.” After the action plays, have the avatar speak again and refer to what it just did, for example “I hope you liked my dance!” You can queue the response audio while the action is playing.

Registered actions

Register clips at session start

Pass your video clips as roleplay_actions when creating the AvatarSession. You can register up to 100 actions. Each key is the name you will use to trigger the action, and each value is an object with video_url and an optional new_image_url.
FieldRequiredDefaultWhat it does
keyyes—The action name. Lowercase letters, digits, _ and -, up to 64 characters. You use this name to trigger the action.
video_urlyes—An https:// URL to the video. The video must be 30 seconds or less.
new_image_urlnoNoneAn https:// URL to the image the avatar should become after the action. See changing the avatar’s look.

Clip requirements

Generate each clip before the session starts. It should show the same character as the avatar’s image, performing the action.
  • Length: 30 seconds or less. Longer clips are skipped.
  • Dimensions: a 2:3 portrait of 416 × 672 pixels or 756 × 1220 pixels.
  • Format: MP4 (H.264) is the safest choice.
  • Audio: optional. If the clip has audio, it plays with the action. Without audio, the action is silent.
  • Start: the first frame should match the avatar’s current reference image.
  • End: the last frame should match the current reference image, or the new image set by new_image_url.
  • Size: up to 256 MB per clip.

Trigger a registered action

Publish a data message on the LiveKit topic ls.roleplay-action with the action name.
Only one roleplay action runs at a time. Any roleplay action you send while one is in progress is ignored until that action is over.
FieldRequiredDefaultWhat it does
actionyes—A name from roleplay_actions.
interruptnofalsefalse waits until the avatar finishes what it is saying, then performs the action. true interrupts the avatar and performs it now.

Events

LemonSlice publishes roleplay_status events as JSON data messages on the LiveKit topic lemonslice. Use them to follow an action from request to finish.

Avatar Lifecycle during a Roleplay Action

  1. Accepted. If the avatar is talking, the action waits until it finishes what it’s saying, then starts. For a registered action, set interrupt: true to skip the wait: the avatar stops talking and performs the action right away.
  2. Performed. The avatar performs the action. If your agent responds during the action, the response is held until the action ends. Only the latest response is kept.
  3. Done. When the action ends, the avatar speaks the held response, if there is one, and you can send the next roleplay action.

Changing the avatar’s look

A roleplay action can also change the avatar’s look, like walking into the garden or putting on a hat. Give us an image of the new look, and the avatar keeps that look after the action ends.
  • On demand: set end_frame to the new image. The action is generated to end on it.
  • Registered: set new_image_url to the new image, next to video_url. Your clip should end on that image.
If you leave these out, the avatar goes back to the look it had before the action.

Example: from the house to the garden

Say your avatar starts in a living room, and you want it to walk outside and keep talking from the garden. You need an image of the avatar standing in the garden, such as garden.jpg. On demand, describe the move and end on the garden image:
Registered, use a clip of the avatar walking from the living room into the garden, and set the garden image as new_image_url:
Then trigger it with { "action": "to_garden" }. Either way, once the action ends, the avatar keeps talking from the garden for the rest of the session, until another action changes its look.