Header Logo

How to Swap Avatar Models Dynamically in an Agora Voice and Video Agent

How to Swap Avatar Models Dynamically in an Agora Voice and Video Agent

Learn how to swap avatar models in an Agora realtime voice/video agent without dropping the call, losing state, or breaking lip sync.

Introduction


Swapping avatar models dynamically sounds simple until you try to do it in a live voice or video agent without breaking the session. The hard part is that the avatar is not just a static asset; it is part of a realtime media pipeline. If you change the model at the wrong time, you can introduce visible glitches, lip-sync drift, or a brief media renegotiation that feels like a disconnect.


In practice, the goal is to switch the avatar’s visual identity while preserving the conversational state, audio stream, and session continuity. By the end of this post, you should understand the pieces involved, the failure modes to watch for, and a safe way to implement model switching in a production agent.


What “avatar model” means in a realtime agent


In a voice or video agent, the avatar model is the rendering target that turns the agent’s speech into a live talking face. Depending on the stack, this can mean a specific character identity, a facial rig, a style preset, or a visual generation model. The key point is that the avatar is downstream of the agent’s text-to-speech or audio output and must stay synchronized with that output.


That synchronization has two consequences:


  • The avatar session usually tracks the agent session, not the user’s browser tab.

  • Model changes must be coordinated with frame delivery and audio timing, or the viewer will notice a mismatch.


If you are using WebRTC for the media path, the browser or client is receiving a live stream, not polling for images. That means model switching is closer to a controlled media-state transition than a normal API update.


Designing for dynamic swaps without dropping the call


The safe pattern is to separate three concerns:


  1. Conversation state — the dialog history, user context, and tool state.

  2. Media session — the live transport carrying audio/video.

  3. Avatar identity — the model or rendering configuration driving the face.


If you keep those independent, a model swap becomes a metadata update plus a controlled rendering transition, rather than a full session restart. That is the architecture you want in production.


Recommended swap flow


A good implementation typically looks like this:


  1. Detect the trigger for the swap: user intent, agent mode change, brand context, or escalation path.

  2. Wait for a natural boundary if possible, such as the end of an utterance or a pause in speech.

  3. Update the avatar configuration for the active session.

  4. Keep the audio agent running so the conversation context does not reset.

  5. Verify the new avatar is rendering before continuing with the next response.


The “natural boundary” step matters. If you switch mid-phoneme, the old face may still be animating while the new face begins rendering. Even if the media layer handles it, the result looks abrupt. In real systems, a tiny delay is usually better than a visibly broken transition.


Implementation with a REST session update


If your agent backend manages the avatar directly, you can drive the swap over the API. The exact fields depend on the session and avatar schema in the docs, but the shape is usually: authenticate, identify the active session, and patch the avatar reference or model parameters.


curl -X PATCH "https://api.protoface.com/sessions/<session_id>" \
}'
curl -X PATCH "https://api.protoface.com/sessions/<session_id>" \
}'
curl -X PATCH "https://api.protoface.com/sessions/<session_id>" \
}'


The important operational detail is to make the update against the live session, not by tearing down and recreating the agent. That preserves the audio path and any conversation state your application is maintaining.


In a production system, also make the operation idempotent. If the same swap request is retried, the session should end up in the same avatar state without duplicate side effects. That matters if your orchestrator retries on timeouts or network hiccups.


Python orchestration for swap logic


If your agent control plane is in Python, keep the swap logic close to the conversation state machine. A simple controller might react to a tool call, route event, or intent classifier, then update the avatar after a safe boundary.


from protoface import Client  # exact SDK imports may vary; check the docs

swap_avatar(session_id="sess_123", avatar_id="avatar_support_mode")
from protoface import Client  # exact SDK imports may vary; check the docs

swap_avatar(session_id="sess_123", avatar_id="avatar_support_mode")
from protoface import Client  # exact SDK imports may vary; check the docs

swap_avatar(session_id="sess_123", avatar_id="avatar_support_mode")


The point of using the SDK here is not convenience alone; it keeps the swap logic in the same runtime that already understands your session lifecycle. That makes it easier to coordinate with pauses, speech completion, and any downstream state you need to preserve.


What can go wrong


Most swap bugs are not API bugs. They are timing bugs.


  • Mid-utterance switching: the visible face changes while the speech stream is still producing audio.

  • Session recreation: you accidentally create a new avatar session and lose the existing context.

  • Transport churn: the media track briefly disconnects while the new model initializes.

  • Race conditions: two different triggers try to swap avatars at once.


To avoid these, gate swaps through a single state machine, serialize updates per session, and treat avatar changes as a form of media configuration change rather than a UI toggle.


Practical guardrails


A few patterns make dynamic swapping much more reliable:


  • Swap only at utterance boundaries. If your agent stack exposes speech events, wait for completion before updating the avatar.

  • Keep a canonical session record. Store the active avatar ID alongside the agent session so you can recover after retries.

  • Debounce repeated triggers. If a classifier fires multiple times, collapse them into one transition.

  • Log the media state transition. Record when the request was made, when the avatar changed, and whether the stream stayed healthy.


If you are serving end users, also think about fallbacks. If the requested avatar is unavailable or fails to load, it is better to keep the current model running than to blank the video surface.


How Protoface fits in


This is the kind of session-level control Protoface is designed to support: you create and manage avatars and realtime sessions through the REST API, then update the active session rather than rebuilding the whole agent. For programmatic control, the docs and the Python SDK are the right starting points.


If your agent already runs on LiveKit, the LiveKit plugin path is often the cleanest integration point because it keeps the avatar aligned with the agent’s realtime audio pipeline. The same principle applies: preserve the session, update the avatar identity, and let the existing media stream continue.


Conclusion


Dynamic avatar swapping is mostly a systems problem: preserve the conversation, keep the media transport alive, and update the avatar identity at a safe boundary. If you treat the avatar as a live session property instead of a disposable UI element, you can switch models without interrupting the user experience.


Start by wiring the swap behind a single state transition in your agent, then test it under real speaking conditions, not just idle sessions. From there, use the API, SDK, or LiveKit integration that matches your stack, and validate timing, retry behavior, and fallback handling. The docs at docs.protoface.com have the implementation details you’ll need to fill in the exact request shapes and session fields.

Add a face to your AI.

No credit card needed.

Add a face to your AI.

No credit card needed.

Add a face to your AI.

No credit card needed.