i am using the gemini realtime model now how do i ...
# ask-ai
s
i am using the gemini realtime model now how do i use the prompt caching feature
t
Thanks for reaching out, Ajay. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The Gemini Realtime model doesn’t have a specific prompt caching feature, but it does a great job with real-time streaming and managing the session state dynamically. When you set up a session, system prompts (through the
instructions
parameter) are sent right then, and the chat history is managed in real time as well. If you're hoping to improve latency or reuse prompts, the model takes care of that through backend optimizations, though there isn’t a user-configurable caching option available. Please feel free to reach out if you’d like some tips on how to reduce latency or make the most of context handling with the Gemini Realtime model—I’m here to help! Sources: tools/main/README.md | AI Agents Framework | livekit/livekit_composite | DeepWiki | plugins/google/src/beta/realtime/realtime_api.ts | livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real... | Gemini Live API plugin | LiveKit Docs
s
when i am having a conversation the token suddenly goes up and starts increasing exponentialy so i want to use prompt caching
t
To help you manage the issue of token usage increasing exponentially during conversations, here are some friendly strategies you can try with the Gemini Realtime model: • Message Limits: The system gently enforces a 40-message limit in the chat context. When this limit is reached, it gracefully truncates older messages, keeping only the most recent ones to keep things running smoothly. • Message Concatenation: Sequential messages from the same role get combined into a single message if their total size is under 1kB, which helps reduce redundancy and keeps the conversation tidy. • Context Window Compression: You can use the
contextWindowCompression
option to compress earlier parts of the conversation. This keeps the important context without going over token limits. • Token Metrics: Keep an eye on token usage with telemetry data like
input_tokens
,
output_tokens
, and
total_tokens
. This can help spot any inefficiencies and optimize your usage. • Response Control: Adjust settings such as
maxOutputTokens
to limit how many tokens are generated in each response, giving you more control over the conversation flow. I hope these tips help you manage token usage more effectively! If you’d like, I’m here to guide you through detailed steps for any of these options—just let me know. Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | plugins/google/src/beta/realtime/realtime_api.ts
s
how do i do it contextWindowCompression
t
I'd love to help you out! Could you please share a bit more about which part you'd like to focus on? For example: • Are you interested in enabling context window compression to better handle long conversations? • Would you like to set up maxOutputTokens to control the size of responses? • Or maybe you want to keep an eye on token metrics to monitor your usage? Just let me know, and I'll happily guide you through the steps tailored to what you need!
s
contextWindowCompression
t
To enable and configure contextWindowCompression in the Gemini Realtime model, you can simply pass the parameter during initialization. Here’s a friendly guide to help you get started: Python Example:
Copy code
from livekit.plugins.google import RealtimeModel
import types  # Assuming Google GenAI SDK types are imported

model = RealtimeModel(
    context_window_compression=types.ContextWindowCompressionConfig(
        # Add specific configuration options here
    )
)
Node.js Example:
Copy code
import { RealtimeModel } from '@livekit/agents/plugins/google';

const model = new RealtimeModel({
  contextWindowCompression: {
    // Add specific configuration options here
  }
});
I want to mention that the exact configuration options for ContextWindowCompressionConfig aren’t fully detailed in the sources I have. To make the most out of this feature, checking out the official Google GenAI SDK documentation will be really helpful for finding all the available fields and settings. Please don’t hesitate to reach out if you’d like me to walk you through anything else or if you have a particular use case you want to explore together! Sources: plugins/google/src/beta/realtime/realtime_api.ts | Gemini Live API plugin | LiveKit Docs | realtime/gemini_live_vision.py | Turn detection and interruptions | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real...