calm-article-62769
08/08/2025, 12:06 PMimport asyncio
import base64
import logging
from dotenv import load_dotenv
from livekit.agents import (
Agent,
AgentSession,
JobContext,
RoomInputOptions,
WorkerOptions,
cli,
get_job_context,
)
from livekit.agents.llm import ImageContent
from livekit.plugins import openai, silero
# # Load environment variables from .env
load_dotenv()
logger = logging.getLogger("vision-assistant")
load_dotenv()
class VisionAssistant(Agent):
def __init__(self) -> None:
self._tasks = []
super().__init__(
instructions=""" You are a helpful voice assistant Tom.""",
llm=openai.LLM(model="gpt-4o-mini"),
stt=openai.STT(model="whisper-1"),
tts=openai.TTS(model="tts-1", voice="nova"),
vad=silero.VAD.load(),
)
async def on_enter(self):
def _image_received_handler(reader, participant_identity):
task = asyncio.create_task(
self._image_received(reader, participant_identity)
)
self._tasks.append(task)
task.add_done_callback(lambda t: self._tasks.remove(t))
get_job_context().room.register_byte_stream_handler("test", _image_received_handler)
self.session.generate_reply(
instructions="Briefly greet the user and offer your assistance."
)
async def _image_received(self, reader, participant_identity):
logger.info("Received image from %s: '%s'", participant_identity, reader.info.name)
try:
image_bytes = bytes()
async for chunk in reader:
image_bytes += chunk
chat_ctx = self.chat_ctx.copy()
chat_ctx.add_message(
role="user",
content=[
ImageContent(
image=f"data:image/png;base64,{base64.b64encode(image_bytes).decode('utf-8')}"
)
],
)
await self.update_chat_ctx(chat_ctx)
print("Image received", self.chat_ctx.copy().to_dict(exclude_image=False))
except Exception as e:
logger.error("Error processing image: %s", e)
async def entrypoint(ctx: JobContext):
await ctx.connect()
session = AgentSession()
await session.start(
agent=VisionAssistant(),
room=ctx.room,
room_input_options=RoomInputOptions(
video_enabled=True
),
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
For the UI interface, I’m using agent-starter-react package from here.
My agent is joining the room and can communicate with me properly, but whenever I share my screen and ask the bot if it’s visible, it says it can’t see my screen or anything I’m showing. It keeps replying with something like, “I can't see anything.”
So, is there any issue with my agent.py file, or could it be something else?refined-appointment-81829
08/08/2025, 10:19 PMcalm-article-62769
08/11/2025, 5:42 AM