Skip to content

Send lk.agent.session messages with one-shot send_bytes instead of stream_bytes - #7751

Draft
1egoman wants to merge 2 commits into
mainfrom
fix/session-transport-send-bytes
Draft

1egoman wants to merge 2 commits into
mainfrom
fix/session-transport-send-bytes

Conversation

@1egoman

@1egoman 1egoman commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

RoomSessionTransport.send_message now sends each lk.agent.session message with the one-shot LocalParticipant.send_bytes instead of opening an incremental stream_bytes stream per message.

With stream_bytes, an incremental stream always results in three packets being sent on the reliable data channel (header, chunk, trailer) and is never compressed.

With send_bytes the SDK knows the whole payload up front, so for receivers that support data streams v2 it can send a small message as a single inline packet, and compress a large one.

Why it matters

Session events are small and frequent, and today they go to every participant in the room, because the room session host is created with no remote identity. Measured against a JS client (clientProtocol of 3), one agent turn sent ~95 session messages: 89× session_usage_updated, 4× agent_state_changed, 2× conversation_item_added. On the client's data channel:

data channel ↓ per agent turn
stream_bytes (today) ~52 KB / 354 messages
send_bytes (this PR) ~37 KB / 170 messages (−29% bytes, −52% messages)
no session host at all ~11 KB / 83 messages

On constrained mobile links, that traffic queues ahead of RPCs and transcriptions on the reliable channel. That's the head-of-line blocking behind customer reports of agent → client RPC connection timeouts.

TODO

1egoman and others added 2 commits October 12, 2026 12:21
RoomSessionTransport opened an incremental byte stream per session message,
which always costs a header, a chunk and a trailer packet on the reliable data
channel and is never compressed. Session events are small and frequent (~90
per agent turn, mostly session_usage_updated), so this was a large share of
the data sent to every participant.

LocalParticipant.send_bytes knows the whole payload up front, so the SDK can
deliver a small message as a single inline packet, and compress a large one,
for receivers that support data streams v2. Measured against a protocol-3 JS
client, one agent turn dropped from ~52 KB / 354 to ~37 KB / 170 data channel
messages.

Requires livekit-rtc with LocalParticipant.send_bytes (livekit/python-sdks
feat/rtc-send-bytes); the livekit pin must be bumped once that is released.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@1egoman 1egoman changed the title perf(voice): send lk.agent.session messages with one-shot send_bytes Send lk.agent.session messages with one-shot send_bytes instead of stream_bytes Oct 11, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants