Skip to content
Limited timeStarter is now $9 a month instead of $20.See plans
charmotion

Building a LiveKit Voice Agent UI with a State-Driven Rive Mascot

By the Charmotion team · Updated · How we write guides

Cover illustration for the guide: Building a LiveKit Voice Agent UI with a State-Driven Rive Mascot, with Charmotion demo characters

Read the agent's state in your frontend, then pass it into a Rive state machine so the mascot changes with it. LiveKit Agents publishes the state as the lk.agent.state attribute, with values such as listening, thinking and speaking, so a voice assistant UI can show each step. Map each state to one Rive state or number input.

Key takeaways

  • LiveKit publishes the agent's state as lk.agent.state, so the frontend needs no extra signalling.
  • Map the five agent states to five mascot states and fall back to idle for any unknown value.
  • Drive the Rive state machine from one value, either a number input or a data-bound property.
  • Exports from Rive's free plan play a splash screen, so ship on a paid plan when the mascot goes live.
  • The speech pipeline you choose does not change the UI code, because the mascot only reads state.

Already have a character or logo? See examples in real app screens: splash, onboarding, loading and empty-state screens, with the animation that plays in each.

How does a LiveKit voice agent report its state?

This guide covers how to build a LiveKit Agents voice assistant UI with an animated Rive mascot that changes with each step of the conversation. The mascot does not run its own logic. It reads the agent's state from LiveKit and shows it.

LiveKit Agents is an open-source Python and Node.js framework for voice and video agents that join a LiveKit room as a participant. Inside the agent, an AgentSession emits an agent_state_changed event whenever the state changes, and the docs give example transitions such as listening to thinking, or thinking to speaking. LiveKit publishes the current state as the lk.agent.state attribute on the agent participant, so any frontend connected to the room can read it.

That attribute is the only input the mascot needs. The rest of the app stays a normal web or mobile interface, and the Rive file stays a set of states that respond to one value.

Which agent states should the mascot show?

The events reference lists five agent states: initializing, idle, listening, thinking and speaking. Give each one a visible meaning in the UI, then choose the mascot state that matches it.

LiveKit stateWhat the user seesMascot state (Charmotion mood number)
initializingThe agent is joining the roomloading (5)
idleThe agent is waiting for the useridle (0)
listeningThe agent is picking up speechlistening (6)
thinkingThe model is working on a replythinking (3)
speakingThe agent's audio is playingtalking (7)

Build the map so an unknown value falls back to idle. Frameworks add states over time, and a mascot that freezes on an unfamiliar value looks broken. Keep the map in one file so designers and developers change it in one place.

Error states are not in the list. If the connection drops, show a sad mood from your own code, and show a success moment with a happy mood. Keep those cases separate from the agent's state so a network problem is not mistaken for the agent being idle.

How do you read the agent state in React?

LiveKit's frontend guide describes the useAgent hook from @livekit/components-react, which gives access to the agent's state and helper values. The hook must render inside the LiveKit room component, so place the voice assistant under your room provider.

Pass the state to a mascot component and keep the mascot free of LiveKit code. That keeps the Rive part testable on its own, and you can open it in Storybook with a list of states.

import { useAgent } from '@livekit/components-react';
import { AgentMascot } from './AgentMascot';

export function VoiceAssistant() {
  const { state } = useAgent();
  return <AgentMascot agentState={state ?? 'idle'} />;
}

If you need the value outside React, read the lk.agent.state attribute from the agent participant directly. The attribute is the same source the hook uses, so both routes show the same state.

How do you drive the Rive state machine from the state?

Rive's React package, @rive-app/react-canvas, is the option Rive recommends for most apps unless you need a WebGL renderer. useRive loads the .riv file and returns a RiveComponent to render. useStateMachineInput returns a handle to a named input on the state machine.

The React runtime marks useStateMachineInput as deprecated in favour of data binding hooks. Treat the code below as a working pattern for a number input, and move to a data-bound property when you upgrade your Rive setup.

import { useEffect } from 'react';
import { useRive, useStateMachineInput } from '@rive-app/react-canvas';

const MOOD = {
  initializing: 5,
  idle: 0,
  listening: 6,
  thinking: 3,
  speaking: 7,
};

export function AgentMascot({ agentState }) {
  const { rive, RiveComponent } = useRive({
    src: '/mascot.riv',
    stateMachines: 'CharacterStateMachine',
    autoplay: true,
  });
  const mood = useStateMachineInput(rive, 'CharacterStateMachine', 'mood');

  useEffect(() => {
    if (mood) mood.value = MOOD[agentState] ?? 0;
  }, [agentState, mood]);

  return <RiveComponent className='agent-mascot' />;
}

Size the .agent-mascot element in your own stylesheet so the canvas keeps its aspect ratio. Setting the number is the only other work the code does. The state machine blends from one mood to the next, so transitions look smooth without frame timing in React. For more on the React setup, see how to use Rive in React and Next.js.

What should the .riv file contain?

A .riv file bundles the artboards, animations, state machines and data binding settings from the Rive editor, and runtimes load it directly into a website or app. Keep the editor source as a .rev file for editing, because runtimes cannot load .rev files.

  • One artboard with a state for each mood your table uses: idle, loading, listening, thinking and talking.
  • One state machine, here named CharacterStateMachine, with a number input named mood.
  • Transitions between moods that blend, so a change of agent state does not cut hard.
  • An accent switch if you want small marks such as thinking dots turned off in the production build.

If you need a character file quickly, Charmotion's AI mascot animator produces this shape from one character image. Its CharacterStateMachine has a number input named mood, its idle is 0 and talking is 7, and it adds a LaunchStateMachine that plays once. Characters have no one-shot triggers, so use happy for success and sad for errors.

Exports from Rive's free plan play a Rive splash screen, and paid plans export without it. Check the plan details in is Rive free and what the pricing covers before a public launch.

Does the speech pipeline change the UI code?

It does not change the mascot code. LiveKit Agents supports two designs. A cascaded pipeline runs speech-to-text, a language model and text-to-speech as separate stages, and an AgentSession can be built from those three, with each stage taking either a LiveKit Inference model string or a plugin instance. A realtime model with direct speech-to-speech capability replaces the three stages with one component in the session.

Either way the frontend reads the same agent state, so the mascot code in this guide stays the same. Choose the pipeline for quality, language coverage and cost, then test the UI with each one, because the time spent in the thinking state changes with the model.

Do not tune the speaking mood to measured loudness unless you need lip sync. A mood that starts when the agent state becomes speaking is simpler and keeps the UI in step with the framework. For the audio-level approach and its trade-offs, read lip-sync vs amplitude for a talking avatar.

Latency figures in blog posts vary widely, and this guide does not rely on them. Measure time to first speech in the region and network your users will use. For cloud plan prices, check livekit.com before you budget, because pricing changes and third-party summaries can lag.

Build a LiveKit voice assistant UI with a Rive mascot

  1. Run the agent. Start a LiveKit Agents worker with an AgentSession, either a cascaded STT, LLM and TTS pipeline or a realtime model.
  2. Watch the state. Join the room from a frontend and confirm that lk.agent.state changes while you speak to the agent.
  3. Map the states. Assign initializing, idle, listening, thinking and speaking to one mascot state each, with idle as the fallback.
  4. Wire the frontend. Call useAgent inside the LiveKit room component and pass the state to the mascot component as a prop.
  5. Drive the Rive file. Set the number input on CharacterStateMachine from the map, then test every transition in the running app.

Frequently asked questions

Do I need LiveKit Cloud to run this?

Not necessarily. The Agents framework is published under the Apache-2.0 licence on GitHub, so you can run the agent code yourself. Check livekit.com for current Cloud plan prices and for the hosting options that fit your project before you commit.

Can the mascot run in a React Native app?

Yes. Rive's React Native runtime is the @rive-app/react-native package, built on Nitro, and it needs a development build or native project rather than Expo Go. Check LiveKit's own client documentation for the agent hook in your React Native setup, since this guide covers the React web hooks.

What should the mascot show before the agent joins?

Show the loading mood while the room connects and before the agent participant appears. Once lk.agent.state is published, switch to the mapped state. If the attribute never arrives, keep the loading mood and show a retry message from your own code.

Does the mascot need a paid Rive plan?

Only if you ship to users without the splash screen. Exports from the free plan play a Rive splash screen, and paid plans export without it. Runtimes are open source and play any .riv file, so the licence question is about the export, not playback.

Sources

Related guides