when i switch ASSIStant() agent to visionassistant...
# ask-ai
w
when i switch ASSIStant() agent to visionassistant() my visionassitant agent is not able to see 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. They may also, if they choose, share video with you. This will be either their camera or their smartphone's screen. It is up to the user whether or not to share their video. Your responses should be concise, friendly, and engaging. """, llm=google.beta.realtime.RealtimeModel( voice="Puck", temperature=0.8 ), ) # async def changing(self): # self.session.update_agent(VisionAssistant()) async def on_enter(self): global visionAsynsTask_varRef global curr_conversation_context print("WE ARE HERE") visionAsynsTask_varRef=asyncio.create_task(self.watch_activitytrack()) #TODO: # self._chat_ctx = # asyncio.create_task(self._delayed_agent_update()) # self.chat_ctx = curr_conversation_context await self._activity.update_chat_ctx(curr_conversation_context) #ask-ai
t
Thanks for reaching out, Atharva. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to switch from
ASSIStant()
to
VisionAssistant()
and fix any issues with the class not being recognized, here’s a friendly step-by-step to help you out: 1. First, make sure the
VisionAssistant
class is properly defined and imported. Double-check that the file with the class is actually running. 2. Next, enable video input by setting
video_enabled=True
in
RoomInputOptions
when you start the session, like this:
Copy code
await session.start(
    agent=VisionAssistant(),
    room=ctx.room,
    room_input_options=RoomInputOptions(video_enabled=True),
)
1. Update your agent’s instructions to include the vision context, for example:
Copy code
instructions="You are a helpful voice assistant with live video input from your user."
1. Make sure you’re using a multimodal LLM like
google.beta.realtime.RealtimeModel
or OpenAI’s vision-capable models. 2. Check out the Vision Agent Quickstart guide to enable video subscription and handle video frames smoothly. 3. Don’t forget to have all the necessary dependencies installed (like
livekit-agents>=1.0
and
dotenv
) and that your environment variables for API keys are properly set. If you’re still running into trouble, make sure you’re using the right version of the LiveKit Agents framework (v1.x for Python). I’m here if you need more help! Sources: Vision | LiveKit Docs | Vision Agent Quickstart | LiveKit Docs | Vision Agent Quickstart | LiveKit Docs | agent/main.py | LiveKit | Recipes and examples for voice AI and more. | LiveKit Docs
w
cant i set room_input_options=RoomInputOptions(video_enabled=True), in onentry ?
t
RoomInputOptions(video_enabled=True)
can’t be set inside the
on_enter
method of
VisionAssistant
. Instead, you’ll want to specify it when you start the
AgentSession
in your entrypoint function, just like this:
Copy code
await session.start(
    agent=VisionAssistant(),
    room=ctx.room,
    room_input_options=RoomInputOptions(video_enabled=True),
)
The
on_enter
method is really meant for things that happen after the agent joins the room—like setting up handlers or sending greetings—not for configuring input options like enabling video. Sources: agent/main.py | Vision | LiveKit Docs
w
but what if i was switching from one agent to another using this self.session.update_agent(VisionAssistant())
t
Hey there! Just a quick heads-up: when you switch agents using
self.session.update_agent(VisionAssistant())
, the
RoomInputOptions
you set earlier (like
video_enabled=True
) during the initial
session.start()
call will still be active. Basically, the session’s input/output setup sticks around unless the new agent changes it. To make sure video input works smoothly: • Set
video_enabled=True
in
RoomInputOptions
right when you start the session. • Double-check that your new agent (like
VisionAssistant
) is ready to handle video input—this means it should be able to access the session’s
input.video
stream or work with video frames. No worries about doing extra steps during
update_agent()
to keep the video input going—it’s all managed at the session level. Sources: Vision | LiveKit Docs | evaluating-agents/agent_to_test.py | examples/voice_agents/basic_agent.py
w
but its not able to see
t
Hey there! If you notice that
VisionAssistant
can’t access video input after switching agents using
self.session.update_agent
, it’s probably because the video input setup wasn’t re-enabled during the handoff. Here’s how you can fix it: • Make sure you set
RoomInputOptions(video_enabled=True)
when you first start the session. • Double-check that the new agent (like
VisionAssistant
) properly initializes video stream handling. For instance, in the Vision Quickstart, video stream handling is clearly set up in the agent’s methods. • See if you need to re-attach the video stream to the new agent after switching. You can do this by re-registering video handlers or reinitializing the video input stream inside the new agent’s
on_enter
method. If you’re still running into issues, take a moment to confirm that the session’s
RoomIO
object is still set up for video input and that the new agent supports video processing. Sources: Vision | LiveKit Docs | Workflows | LiveKit Docs | livekit-agents/livekit/agents/voice/room_io/room_io.py | README.md | complex-agents/vision/agent.py
w
• See if you need to re-attach the video stream to the new agent after switching. You can do this by re-registering video handlers or reinitializing the video input stream inside the new agent’s
on_enter
method. how to do it but beause this is the issue i am facing f you notice that
VisionAssistant
can’t access video input after switching agents using
self.session.update_agent
, it’s probably because the video input setup wasn’t re-enabled during the handoff.
t
Hey there! If you want to re-attach the video stream or reinitialize video input in
VisionAssistant
after switching agents using
self.session.update_agent
, here’s a friendly step-by-step to help you out: 1. First, make sure you set
RoomInputOptions(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:
Copy code
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. Follow these steps, and your video input should reinitialize seamlessly when you switch agents. If you hit any bumps or want a hand with anything else, just give me a shout—I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent_session.py | complex-agents/vision/agent.py | Vision | LiveKit Docs
w
1. First, make sure you set
RoomInputOptions(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:
Copy code
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
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!
w
1. based on aboveFirst, make sure you set
RoomInputOptions(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:
Copy code
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)