How do I make it so that i can manually have an ag...
# ask-ai
i
How do I make it so that i can manually have an agent make a vision assessment on a schedule?
t
Thanks for reaching out, Andres. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're interested in manually scheduling a vision assessment by an agent! You can achieve this by combining vision-enabled agent capabilities with scheduling logic. Here's a friendly overview to guide you: 1. Create a Vision-Capable Agent: Using LiveKit's multimodal LLMs, your agent can process live video by subscribing to the user's video track and buffering frames for analysis. 2. Define a Scheduling Tool: You might want to build a custom tool that helps schedule assessments. For instance, a function that validates input, interacts with a calendar or database, and reserves a time slot. 3. Use Manual Turn Control: This lets you trigger assessments programmatically, so the agent can act on a timer or a specific event—giving you more control. 4. Integrate with External Systems: Connecting to a calendar API or backend service can help manage availability and keep track of scheduled events seamlessly. If you'd like, I’d be happy to walk you through any part of this workflow in more detail—whether it’s setting up the scheduling backend or automating assessment triggers. Just let me know how I can assist! Sources: complex-agents/vision/README.md | Vision | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real...
i
I want to specifically see how to make the session answer the vision question programmatically vs waiting for me to ask it
t
I'm happy to help you programmatically trigger a vision assessment without waiting for user input! Here are a few approaches you might find useful: 1. Manual Turn Control: You can use a timer or an external event to prompt the agent to analyze the latest video frame. For instance, setting up a periodic task that captures the current frame and sends it to the agent for analysis works well. 2. Inject Images Programmatically: Another way is to send images directly to the agent's context via byte streams. The agent can then automatically analyze the image as soon as it receives it and provide observations. 3. Realtime Models: Models like Gemini Live enable continuous visual processing, so the agent can analyze video input in real-time without needing any user prompts. 4. Preloaded Images: You might also consider initializing the agent with specific images for immediate analysis right at startup. If you'd like, I can provide detailed implementation examples for any of these methods, such as how to set up a periodic task or handle byte stream images. Just let me know what would be most helpful for you! Sources: Vision | LiveKit Docs | agent/main.py | realtime/gemini_live_vision.py
i
Can you show me the code and give me a mock example
t
Here is a mock example of how to programmatically trigger a vision assessment using manual turn control and periodic tasks:
Copy code
import asyncio
from livekit import Agent, rtc, get_job_context

class VisionAssistant(Agent):
    def __init__(self):
        super().__init__(
            instructions="You are a helpful assistant that analyzes video frames.",
        )
        self._latest_frame = None
        self._video_stream = None

    async def on_enter(self):
        room = get_job_context().room

        # Subscribe to the first video track
        remote_participant = list(room.remote_participants.values())[0]
        video_tracks = [
            publication.track 
            for publication in remote_participant.track_publications.values() 
            if publication.track.kind == rtc.TrackKind.KIND_VIDEO
        ]
        if video_tracks:
            self._create_video_stream(video_tracks[0])

        # Start periodic vision assessment every 5 seconds
        asyncio.create_task(self._periodic_vision_assessment())

    def _create_video_stream(self, track):
        self._video_stream = rtc.VideoStream(track)
        async def read_stream():
            async for event in self._video_stream:
                self._latest_frame = event.frame
        asyncio.create_task(read_stream())

    async def _periodic_vision_assessment(self):
        while True:
            await asyncio.sleep(5)  # Trigger every 5 seconds
            if self._latest_frame:
                # Analyze the latest frame
                await self.session.generate_reply(
                    instructions="Describe what you observe in the current video frame.",
                    context={"image": self._latest_frame}
                )

# Start the agent session
async def main():
    from livekit import AgentSession
    session = AgentSession(agent=VisionAssistant())
    await session.start()

# Run the agent
asyncio.run(main())
This example sets up a vision assistant that subscribes to a video track, captures frames, and triggers an analysis every 5 seconds. The agent uses the latest video frame to generate a response. If you have any questions or would like me to walk you through any part of this example, please don’t hesitate to ask. I’m here to help you every step of the way!
i
This doesn't seem to follow the patterns from the latest examples repo
t
I'm glad you're interested in the latest patterns for vision assessment in LiveKit! The approach has beautifully evolved to integrated multimodal agents that come with built-in vision support. Here's a quick overview for you: 1. Automatic Frame Capture: Video frames are captured automatically during user speech or programmatically using timers, making the process smooth and efficient. 2. Multimodal Agent Classes: The
MultimodalAgent
class is your friend here, helping you seamlessly combine vision and voice capabilities. 3. Intermediate Vision Models: For LLMs that don’t have native vision support, auxiliary models like Moondream step in to generate image captions for further analysis. 4. Modern Web Interfaces: Next.js frontends now offer real-time video sharing and transcription display, enhancing user interaction. If you'd like to explore the most up-to-date examples, these resources might be really helpful: • Frontend starter apps • Python agent starter repository • LiveKit Agents Playground Please feel free to let me know if you want me to walk you through a specific example from these updated patterns—I’m here to help! Sources: swift-frontend/VisionDemo.xcodeproj/project.pbxproj | vision/moondream_vision.py | Vision | LiveKit Docs
i
Can I use a vision model if I have e2ee enabled?
t
Yes, you can use a vision model with end-to-end encryption (E2EE) enabled in LiveKit, but there are specific considerations: • Client-Side Processing: Vision models must process visual data on the client side after decryption. This ensures that the encrypted media remains secure throughout its transmission and processing lifecycle. • Decryption Before Analysis: Decrypt the video data on the client side before passing it to the vision model for analysis. This respects the E2EE constraints. • Secure Key Management: E2EE requires secure generation, storage, and distribution of encryption keys, which your application must handle. LiveKit does not manage key storage or transport. Would you like guidance on implementing client-side decryption or integrating a vision model with E2EE? Sources: End-to-end encryption | LiveKit docs