echoing-lamp-18687
11/11/2025, 9:30 AMfrom 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))tall-airline-16756
11/11/2025, 9:30 AMtall-airline-16756
11/11/2025, 9:31 AMpip install livekit livekit-plugins-hedra
Next, initialize and start the avatar session in your Python agent like this:
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:
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 docsechoing-lamp-18687
11/11/2025, 9:32 AMechoing-lamp-18687
11/11/2025, 9:32 AMtall-airline-16756
11/11/2025, 9:33 AMexport 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:
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:
const isAvatar = agentVideoTrack !== undefined && avatarEnabled;
4. Add Configuration Support
Don't forget to update app-config.ts to include the avatar settings like this:
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!echoing-lamp-18687
11/11/2025, 9:34 AMtall-airline-16756
11/11/2025, 9:34 AM