Skip to content

feat: add MeshLite avatar plugin - #8672

Open
michzarx wants to merge 5 commits into
livekit:mainfrom
michzarx:add-meshlite-avatar-plugin
Open

michzarx wants to merge 5 commits into
livekit:mainfrom
michzarx:add-meshlite-avatar-plugin

Conversation

@michzarx

Copy link
Copy Markdown

Summary

Adds livekit-plugins-meshlite, a plugin that gives a LiveKit voice agent a MeshLite avatar: a lip-synced face rendered in the visitor's own browser by the MeshLite web SDK. The agent keeps its own STT, LLM and TTS (or realtime model). Follows up #8535.

It works differently from the other avatar plugins: there is no avatar participant and no video track. meshlite.AvatarSession.start() routes the session audio to the visitor's page with the standard DataStreamAudioOutput (lk.audio_stream, lk.clear_buffer, lk.playback_started, lk.playback_finished), and the page plays the voice in sync with the face. Interruptions and the played-back position work as with the other avatar plugins. Nothing runs server-side per conversation.

  • meshlite.AvatarSession extends livekit.agents.voice.avatar.AvatarSession.
  • avatar_identity is the visitor's identity, since the avatar lives in the visitor's page. For that reason aclose() overrides the base class: it restores the audio output and never removes a participant from the room.
  • wait_for_join() returns once the visitor is in the room (no video track to wait for), and emits the usual AvatarMetrics.
  • The agent side needs no MeshLite key; the page gets a short-lived MeshLite session token from the developer's server.

Known limit: room recordings (egress) do not contain the agent's voice, because no audio track is published.

What's included

  • livekit-plugins/livekit-plugins-meshlite/, the plugin package
  • Registered as a uv workspace member and as a livekit-agents[meshlite] extra, with uv.lock regenerated
  • tests/test_plugin_meshlite.py, unit tests in a faked room (pytest.mark.unit, pytest.mark.plugin("meshlite"))

Test plan

  • ruff check / ruff format --check
  • mypy -p livekit.plugins.meshlite
  • pytest tests/test_plugin_meshlite.py --unit (16 passed)
  • End to end with livekit-agents 1.8 and livekit-client 2.23 in the external package: Chrome and Firefox on desktop, Chrome on iPhone and Android, with interruptions

This code was first published under Apache-2.0 at meshlite-avatar/livekit-plugins-meshlite (on PyPI as 0.1.0). We own the livekit-plugins-meshlite name on PyPI and will set up publishing with you before the first release from this repo.

🤖 Generated with Claude Code

@michzarx
michzarx requested a review from a team as a code owner November 19, 2026 04:44
@CLAassistant

CLAassistant commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

devin-ai-integration[bot]

This comment was marked as resolved.

@michzarx

Copy link
Copy Markdown
Author

@tinalenguyen this one follows up #8535: an avatar drawn in the visitor's browser, with no avatar participant. Happy to change anything to fit your conventions.

@michzarx
michzarx force-pushed the add-meshlite-avatar-plugin branch from f1f2fc5 to 294a6cd Compare November 21, 2026 10:15

@tinalenguyen tinalenguyen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, thanks for the PR! since the avatar is rendered on the visitor's page, the agent side here comes down to agent_session.output.audio = DataStreamAudioOutput(room, destination_identity=visitor_identity, wait_playback_start=True), which users can already do with core and no MeshLite-specific call. the rest of the plugin works around the base AvatarSession assuming an avatar participant (aclose() re-implementing the base cleanup, reaching into output._start_atask, avatar_identity returning the visitor). is there something meshlite-specific the agent side needs? if not, maybe the snippet above could live in meshlite's own livekit guide instead of a separate plugin here, since any client-rendered avatar would need the same few lines

michzarx and others added 3 commits December 2, 2026 15:09
MeshLite draws the avatar in the visitor's browser, so the plugin adds no
participant and no video track: it routes the agent's voice to the visitor's
page over the avatar data-stream protocol. It extends the base AvatarSession
but never removes the visitor from the room on close.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RoomIO wraps the avatar output in a TranscriptSynchronizer, so comparing
session.output.audio with our output missed it and the agent kept speaking
to the visitor after aclose(). Follow next_in_chain instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review feedback: the agent side only routed audio, which core already does
with DataStreamAudioOutput, and worked around the base AvatarSession.

The agent now does the MeshLite-specific step itself, like the other avatar
plugins: with MESHLITE_API_KEY it creates the session on the MeshLite API
and hands the single-use token to the visitor page only, through the
meshlite.session_token RPC. It also tells the page the language of each
reply (meshlite.set_language) so the lip model follows the conversation.

The workarounds are gone: no private attributes, aclose() defers to the
base class, and the output is installed with replace_audio_tail().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michzarx
michzarx force-pushed the add-meshlite-avatar-plugin branch from 294a6cd to 44459c0 Compare December 2, 2026 08:18
@michzarx

michzarx commented Dec 2, 2026

Copy link
Copy Markdown
Author

Thanks Tina, fair points. I pushed an update.

The agent side now does the MeshLite work, like the other avatar plugins. meshlite.AvatarSession() takes MESHLITE_API_KEY, creates the MeshLite session on our API, and hands its single-use token to the visitor page through the meshlite.session_token RPC. Only the visitor participant gets it, and the secret key never enters the room. Without the plugin, the developer's own server had to do that step.

It also keeps the lips in the right language. At the end of each reply it tells the page the reply language through the meshlite.set_language RPC (English, French, Mandarin).

The workarounds you flagged are gone: no private attributes, aclose() defers to the base class, and the output is installed with replace_audio_tail(). The branch is rebased on main.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 new potential issues.

3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +289 to +296
room, session = self._room, self._agent_session
if room is not None and self._started:
room.local_participant.unregister_rpc_method(SESSION_TOKEN_RPC)
if session is not None and self._follow_language and self._started:
session.off("conversation_item_added", self._on_reply_language)
for task in list(self._tasks):
task.cancel()
await super().aclose()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Avatar audio survives session close

aclose() leaves the MeshLite audio sink installed when the agent keeps running. Base cleanup never restores the audio route, so later replies still stream to the closed avatar.

Learn more

MeshLite installs its output with replace_audio_tail, which can put the sink under existing recording or transcription wrappers. Avatar sessions can be closed independently of the running agent, as the avatar switching example shows. The base cleanup releases listeners and the join task but does not touch the output chain.

Example: An app ends the avatar portion of a call, awaits avatar.aclose(), and has the agent say a final message. The message still goes to MeshLite instead of the replacement route or no output.

Recommended fix: On close, remove only the audio route still owned by this MeshLite instance. Restore the displaced sink where applicable, preserve wrappers when swapping the tail, and leave a sink installed by the caller after start untouched. Cover both wrapped and unwrapped routes with a close test.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the other avatar plugins here (Anam, Tavus, Simli, Bey, LiveAvatar): closing the avatar session does not change the agent session's audio output. We removed our own detach code after the review asked us to rely on the base cleanup. Happy to add it back if you prefer.

Devin read the old line as attach after connect, which would drop the
first words. The SDK receives the voice from the first word only when the
room is attached before it connects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps LiveKit's new dependency versions and adds the meshlite extra to them, so the pull request merges cleanly again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

3 participants