Is there a way to expose the tools to gemini real-...
# ask-ai
b
Is there a way to expose the tools to gemini real-time API?? Model Used: gemini-2.0-flash-exp Livekit Version: 1.0.13 Livekit Agent Version: 0.12.21
t
Thanks for reaching out, Rahul. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! Could you help me understand a bit more about what you mean by "expose the tools" to the Gemini real-time API? Are you hoping to integrate certain LiveKit features or functionalities with the API, or is there a specific goal you're aiming for? I’m here to help you through this!
b
I want to add tools say to fetch the current weather information
t
I'd be happy to help you integrate tools like fetching current weather information with the Gemini real-time API! Here's a friendly overview to guide you through the process: 1. Define a Weather Tool: You can create a function using the
@function_tool
decorator in Python that fetches weather data from an external API, such as Open-Meteo. For instance, using
aiohttp
to make API calls and return structured results works well. 2. Configure the Agent: To enable smooth, low-latency interactions, use the
google.beta.realtime.RealtimeModel
in your
AgentSession
. Just make sure the model supports function calling, like
gemini-2.0-flash-exp
. 3. Register the Agent: You’ll want to create an agent class that includes your weather tool, then initialize an
AgentSession
to connect your agent to a LiveKit room. 4. Authentication: Don't forget to set up the necessary environment variables, such as
GOOGLE_API_KEY
for the Gemini API. Also, installing the required plugin with
pip install "livekit-agents[google]~=1.2"
will get you ready to go. 5. Optional: To keep things running smoothly, consider using structured output and error handling. This helps ensure consistent results and prevents crashes. If you’d like to see more detailed examples and code snippets, feel free to explore the LiveKit voice agents examples. And please don’t hesitate to reach out if you need any further assistance—I’m here to help you every step of the way! Sources: examples/voice_agents/realtime_with_tts.py | Gemini Live API integration guide | LiveKit Docs
b
If I use the latest version of livekit then I am unable to connect to the gemini realtime api. It shows error during handshake, the above version mentioned works but there is no tool support
t
I'd love to help you with the handshake error you're experiencing! Could you please share a bit more information? Specifically: • The exact error message or code you see in your logs • The versions of the
livekit-agents
and
@google/genai
SDKs you're using • Whether you're working with a stable model like
gemini-2.0-flash-exp
or a preview version With these details, we'll be in a great position to understand what's going on and find the best solution together. Sources: Gemini Live API integration guide | LiveKit Docs | Google integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime... | Gemini Live API integration guide | LiveKit Docs | plugins/google/README.md