worried-petabyte-38885
08/27/2025, 5:48 AMRoomInputOptions(video_enabled=True) when you started the session. This lets the RoomIO system handle your video input smoothly.
2. Next, inside the on_enter method of your new agent, set up the video stream handling. For example, you can listen for video track subscriptions and process incoming frames like this:
async def on_enter(self):
def _video_handler(reader, participant_identity):
task = asyncio.create_task(self._process_video(reader, participant_identity))
self._tasks.append(task)
task.add_done_callback(lambda t: self._tasks.remove(t))
self.session.room.register_byte_stream_handler("video", _video_handler)
1. Make sure your agent subscribes to video tracks via RoomIO. The video input will reconnect automatically whenever a new video track is published or subscribed to.
2. Also, don’t forget to use the on_attached() and on_detached() methods from the VideoInput class to handle when streams get activated or deactivated.
send me all the code that is need to do this. CAN YOU UPDATE THIS BELOW CODE OF MINE AND SEND ME UPDATED CODE class VisionAssistant(Agent):
def __init__(self) -> None:
super().__init__(
instructions="""
You are a helpful voice and video assistant. Your user is interacting with you via a smartphone app and may speak by using their microphone.
""",
llm=google.beta.realtime.RealtimeModel(
voice="Puck",
temperature=0.8
),
)
async def on_enter(self):
global visionAsynsTask_varRef
global curr_conversation_context
print("WE ARE HERE")
visionAsynsTask_varRef=asyncio.create_task(self.watch_activitytrack())
await self._activity.update_chat_ctx(curr_conversation_context)tall-airline-16756
08/27/2025, 5:48 AMtall-airline-16756
08/27/2025, 5:48 AMVisionAssistant class to handle video input like we talked about, here’s a simple way to do it:
1. Turn on video input by setting RoomInputOptions(video_enabled=True).
2. Use the on_enter method to set up a video handler that processes incoming frames.
3. Make sure your agent subscribes to video tracks through RoomIO.
Here’s the updated code for you:
from livekit.agents import Agent, RoomInputOptions
import asyncio
class VisionAssistant(Agent):
def __init__(self):
super().__init__(
instructions="""
You are a helpful voice and video assistant. Your user is interacting with you via a smartphone app and may speak by using their microphone.
""",
llm=google.beta.realtime.RealtimeModel(
voice="Puck",
temperature=0.8
),
)
self._tasks = []
async def on_enter(self):
global visionAsynsTask_varRef
global curr_conversation_context
print("WE ARE HERE")
# Start activity tracking
visionAsynsTask_varRef = asyncio.create_task(self.watch_activitytrack())
await self._activity.update_chat_ctx(curr_conversation_context)
# Register video handler
def _video_handler(reader, participant_identity):
task = asyncio.create_task(self._process_video(reader, participant_identity))
self._tasks.append(task)
task.add_done_callback(lambda t: self._tasks.remove(t))
self.session.room.register_byte_stream_handler("video", _video_handler)
async def _process_video(self, reader, participant_identity):
async for frame in reader:
# Process each video frame here
print(f"Processing frame from {participant_identity}")
This setup will help your assistant smoothly handle video input and process each frame on the fly. If you want me to walk you through any part or need more help, just let me know!
Sources: livekit-agents/livekit/agents/voice/transcription/synchronizer.py | Vision | LiveKit Docs