which is faster and more reliable to communicate s...
# ask-ai
a
which is faster and more reliable to communicate state between client and agent, RPC calls or updating the agent metadata?
t
Thanks for reaching out, Sebastián. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you share a bit more about how you’re planning to use this? Like, are you hoping to update the state all the time in real-time, or just every now and then? Also, what kind of state info are you trying to keep track of? I’m here to help!
Hey there! Both RPC calls and updating agent metadata are great ways to communicate state in LiveKit, but which one works best really depends on what you're trying to do: • RPC Calls: These are perfect for real-time, back-and-forth interactions. They come with timeout handling (like 5 seconds in the JavaScript SDK) and are great when you need to coordinate specific application state. • Metadata Updates: When you update metadata, it triggers a
ParticipantMetadataChanged
event that gets sent to all connected clients. This happens through server-side API calls and is handy when you want to share state changes with multiple participants at once. That said, there aren’t any official benchmarks comparing their speed or reliability just yet. If you could tell me a bit more about your use case—like how often you expect updates or what kind of state info you’re working with—I’d be happy to help you figure out the best fit! Sources: livekit-rtc/livekit/rtc/participant.py | src/room/participant/LocalParticipant.ts | Remote method calls (RPC) | LiveKit Docs | Managing participants | LiveKit Docs | rpc/io.pb.go
a
currently we have IDLE, SPEAKING, LISTENING, THINKING states from the client side that represents the Agent state possible flows are: IDLE -> LISTENING (after user presses a button) LISTENING -> IDLE (no user input detected or user press button to mute) LISTENING -> THINKING (after we notify from agent that VAD end of speech was detected) THINKING -> SPEAKING (agent started streaming audio response) SPEAKING -> LISTENING (agent notifies client that it has sent all audio response) THINKING/SPEAKING -> LISTENING (user interrupts an ongoing response from button press) THINKING/SPEAKING -> IDLE (edge case of timeout in waiting for a response)
t
Hey there! For those frequent state changes like
IDLE
,
SPEAKING
,
LISTENING
, and
THINKING
, LiveKit suggests going with RPC calls instead of metadata updates. Metadata updates aren’t the best fit for rapid changes (more than once every few seconds) because they can slow things down on the server side. RPC calls are actually built for real-time state syncing and work really well in situations like these: • Letting the agent know when a user switches states (like moving from
LISTENING
to
THINKING
). • Managing interruptions smoothly (for example, changing from
SPEAKING
to
LISTENING
). • Coordinating when playback finishes or times out. If you want a hand with setting up RPC calls for your specific needs, just give me a shout—I’m here to help! Sources: Participant attributes and metadata | LiveKit Docs | Bringing AI avatars to voice agents | Bringing AI avatars to voice agents | Web and mobile frontends | LiveKit Docs | Events and error handling | LiveKit Docs