Hey LiveKit team, I’m using LiveKit Cloud for SFU/...
# ask-ai
l
Hey LiveKit team, I’m using LiveKit Cloud for SFU/media, but my agents are self-hosted in multiple regions. Architecture: - Mobile clients connect to LiveKit Cloud rooms. - Backend creates room/token. - Backend explicitly dispatches self-hosted agents via AgentDispatchService (createDispatch). - I currently have region-specific agent names like: - agent-us-east - agent-eu-central - agent-ap-northeast Problem: I need to dispatch the agent closest to the LiveKit SFU/client region to avoid voice latency. iOS exposes room.serverRegion, but Android livekit-android 2.25.1 does not seem to expose an equivalent public Room.serverRegion field. Android Room.serverInfo only appears to expose edition/version. Questions: 1. What is the recommended way to route explicit dispatch to the closest self-hosted regional agent when using LiveKit Cloud SFU? 2. Should self-hosted regional workers share the same agent_name and rely on LiveKit Cloud geographic affinity, or should I keep region-specific agent names and choose explicitly? 3. If explicit selection is recommended, where should I get the selected room/SFU region for Android? 4. Is calling /settings/regions with the token and selecting the first returned region a supported approach, or is that an internal SDK detail? 5. Is there a current or planned Android equivalent to iOS room.serverRegion? The key constraint is that these are not LiveKit Cloud-hosted agents. They are self-hosted agent workers connected to LiveKit Cloud.
t
Thanks for reaching out, Enyinna. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — this is clear and helpful context. I’ll answer each question directly and suggest a reliable approach you can implement now. Acknowledgement: you’re asking how to route explicit dispatch to the nearest self‑hosted agent when using LiveKit Cloud SFU, and Android’s SDK doesn’t expose the iOS
room.serverRegion
. 1) Recommended routing approach • Explicitly dispatch to the agent in the same SFU region as the room. That minimizes media hop/latency when your agents are self‑hosted across regions. • Determine the room’s assigned SFU region server‑side (see #3) and call AgentDispatchService.createDispatch with the region‑specific agent name. 2) Shared agent_name vs region-specific names • Keep region‑specific agent names (e.g.,
agent-us-east
,
agent-eu-central
) and explicitly select which to dispatch to. • Do not rely on sharing one
agent_name
and expecting LiveKit Cloud affinity to route to the closest self‑hosted worker — geographic affinity only applies to LiveKit‑hosted agents. 3) Where to get the selected room/SFU region for Android • Android SDK 2.25.1 does not expose
room.serverRegion
. The authoritative ways to get assigned region: ◦ Server-side: call the Room service (GetRoom) to read the room’s
region
field after creation/connection. ◦ Or read the region from the client’s Join/Connected event if your client SDK exposes connection details (Android currently does not expose region publicly). • Recommended: perform region lookup on your backend (GetRoom) and use that to choose the agent. 4) Is calling /settings/regions and picking the first returned region supported? • No —
/settings/regions
lists available/preferred regions; it does not guarantee the room was assigned to the first entry. It is not a reliable/authoritative source for the room’s assigned SFU region and should not be used alone to decide dispatch. Use the room’s
region
(GetRoom) instead. 5) Android equivalent to iOS
room.serverRegion
• There is no public Android equivalent in SDK 2.25.1. The JoinResponse does contain the region internally, but it’s not exposed by the Android SDK. • Workarounds: ◦ Use the backend GetRoom API to retrieve
room.region
(recommended). ◦ Patch/extend the Android SDK locally to expose region, or file/track a feature request on the Android SDK repo if you want native exposure in future releases. Suggested implementation pattern (concise) 1. Client connects to LiveKit Cloud room. 2. Backend calls GetRoom (RoomService) to read
room.region
. 3. Backend calls AgentDispatchService.createDispatch with agent_name derived from region (e.g.,
agent-{region}
). 4. Agent in same region handles the call. If you’d like, tell me: • how you currently create rooms (server API or via client), and • whether your backend already calls any Room or RTC service APIs — I can give exact request examples and the minimal fields you need to read
room.region
. Sources: Why WebRTC beats WebSockets for realtime voice AI | LiveKit | Why WebRTC beats WebSockets for realtime voice AI | LiveKit | Understand and Improve Agent Latency | LiveKit | Agent dispatch | LiveKit Documentation, with interactive elements
l
There's no GetRoom api afaik
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!