I'm working with agent-starter-react and agent-sta...
# ask-ai
e
I'm working with agent-starter-react and agent-starter-python Before starting calling on frontend, i would like to give an option "Enable Avatar", if enabled, i should be able to add avatar to the session Here's my entry point in python async def entrypoint(ctx: JobContext): # ✅ Read participant metadata # import json # participants = list(ctx.room.participants.values()) _# user_metadata = {}_ # if participants: # participant = participants[0] # Main frontend participant # if participant.metadata: # try: _# user_metadata = json.loads(participant.metadata)_ # except Exception as e: # print("Error parsing metadata:", e) _# print("_✅ _Received metadata from frontend:", user_metadata)_ _# avatar_enabled = user_metadata.get("avatar_enabled", False)_ # Logging setup # Add any other context you want in all log entries here ctx.log_context_fields = { "room": ctx.room.name, } # Set up a voice AI pipeline using OpenAI, Cartesia, AssemblyAI, and the LiveKit turn detector session = AgentSession( # Speech-to-text (STT) is your agent's ears, turning the user's speech into text that the LLM can understand # See all available models at https://docs.livekit.io/agents/models/stt/ stt=deepgram.STTv2( model="flux-general-en", eager_eot_threshold=0.4, ), # A Large Language Model (LLM) is your agent's brain, processing user input and generating a response # See all available models at https://docs.livekit.io/agents/models/llm/ llm=openai.LLM(model="gpt-4o-mini"), # Text-to-speech (TTS) is your agent's voice, turning the LLM's text into speech that the user can hear # See all available models as well as voice selections at https://docs.livekit.io/agents/models/tts/ # Default # tts=elevenlabs.TTS( _# voice_id="ODq5zmih8GrVes37Dizd",_ _# model="eleven_multilingual_v2"_ # ), # Eric tts=elevenlabs.TTS( model="eleven_turbo_v2_5", voice_id="cjVigY5qzO86Huf0OWal", ), # tts=elevenlabs.TTS(), # tts=deepgram.TTS( # model="aura-asteria-en", # ), # VAD and turn detection are used to determine when the user is speaking and when the agent should respond # See more at https://docs.livekit.io/agents/build/turns turn_detection=MultilingualModel(), vad=ctx.proc.userdata["vad"], # allow the LLM to generate a response while waiting for the end of turn # See more at https://docs.livekit.io/agents/build/audio/#preemptive-generation preemptive_generation=True, ) # To use a realtime model instead of a voice pipeline, use the following session setup instead. # (Note: This is for the OpenAI Realtime API. For other providers, see https://docs.livekit.io/agents/models/realtime/)) # 1. Install livekit-agents[openai] _# 2. Set OPENAI_API_KEY in .env.local_ # 3. Add
from livekit.plugins import openai
to the top of this file
# 4. Use the following session setup instead of the version above # session = AgentSession( # llm=openai.realtime.RealtimeModel(voice="marin") # ) # Metrics collection, to measure pipeline performance # For more information, see https://docs.livekit.io/agents/build/metrics/ usage_collector = metrics.UsageCollector() async def log_usage(): summary = usage_collector.get_summary() logger.info(f"Usage: {summary}") ctx.add_shutdown_callback(log_usage) # # Add a virtual avatar to the session, if desired # # For other providers, see https://docs.livekit.io/agents/models/avatar/ # avatar = hedra.AvatarSession( _# avatar_id="...", # See https://docs.livekit.io/agents/models/avatar/plugins/hedra_ # ) # # Start the avatar and wait for it to join # await avatar.start(session, room=ctx.room) # avatar = bey.AvatarSession( _# avatar_id="7124071d-480e-4fdc-ad0e-a2e0680f1378", # ID of the Beyond Presence avatar to use_ # ) # await avatar.start(session, room=ctx.room) # Start the session, which initializes the voice pipeline and warms up the models await session.start( agent=Assistant(), room=ctx.room, room_input_options=RoomInputOptions( # For telephony applications, use
BVCTelephony
for best results
noise_cancellation=noise_cancellation.BVC(), ), ) # Join the room and connect to the user await ctx.connect() if name == "__main__": cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm))
t
Thanks for reaching out, Aman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! To help you enable and add an avatar to your session using agent-starter-react (frontend) and agent-starter-python (backend), here’s a simple step-by-step guide: 1. Backend Setup First, you’ll want to install the necessary plugin for your chosen avatar provider (like Hedra):
Copy code
pip install livekit livekit-plugins-hedra
Next, initialize and start the avatar session in your Python agent like this:
Copy code
from livekit.plugins import hedra

async def entrypoint(ctx):
    session = AgentSession(
        # Configure STT, LLM, TTS
    )

    avatar = hedra.AvatarSession(
        avatar_id="your-avatar-id"  # Replace with your Hedra avatar ID
    )

    await avatar.start(session, room=ctx.room)
    await session.start(room=ctx.room)
Just a quick tip: make sure the avatar session starts before the main agent session to keep everything running smoothly. 2. Frontend Integration Good news! The agent-starter-react template automatically detects and shows video tracks from the avatar. You don’t need to add any extra code. If an avatar is active, it will simply appear as a video participant. 3. Environment Variables Don’t forget to set your keys in the
.env
file like this:
Copy code
LIVEKIT_API_KEY=your_api_key
LIVEKIT_API_SECRET=your_api_secret
LIVEKIT_URL=https://your-deployment.livekit.cloud
HEDRA_API_KEY=your_hedra_key
Keep in mind, each avatar provider will need its own API key. If you have any questions or want a tailored example for a different avatar provider, just let me know—I’m here to help! Sources: Virtual avatar plugins | LiveKit Docs | avatars/hedra/education_avatar/agent.py | README.md | livekit-plugins/livekit-plugins-anam/livekit/plugins/anam/avatar.py | Anam virtual avatar integration guide | LiveKit docs
e
from the frontend i would like to give option, it is required for us
From frontend, it is required for us to give option for enabling avatar
t
Hi there! To help you add a frontend option for enabling avatars in agent-starter-react, I've outlined some friendly steps for you to follow: 1. Extend the Control Bar Interface Let's start by adding an avatar toggle option to the control bar interface:
Copy code
export interface ControlBarControls {
  microphone?: boolean;
  screenShare?: boolean;
  chat?: boolean;
  camera?: boolean;
  avatar?: boolean;  // Add this line
  leave?: boolean;
}
2. Add Avatar Toggle Logic Next, you can use React state to manage the avatar toggle like this:
Copy code
const [avatarEnabled, setAvatarEnabled] = React.useState(true);

const handleToggleAvatar = React.useCallback(() => {
  setAvatarEnabled(prev => !prev);
}, []);
3. Modify Media Tiles Rendering Then, update the rendering logic in the
MediaTiles
component so it respects the avatar toggle state:
Copy code
const isAvatar = agentVideoTrack !== undefined && avatarEnabled;
4. Add Configuration Support Don't forget to update
app-config.ts
to include the avatar settings like this:
Copy code
export const APP_CONFIG_DEFAULTS: AppConfig = {
  // ... existing config
  supportsAvatar: true,  // Add this line
  // ... rest of config
};
5. Add UI Controls Finally, follow the existing pattern for toggles (such as camera and microphone) to add a button for enabling or disabling avatars in the control bar. If you have any questions or need a hand with any of these steps, please don’t hesitate to reach out. I’m here to help you every step of the way!
e
please share and example how you will send data for this from frontend to backend
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!