calm-book-72252
08/14/2025, 10:59 AMtall-airline-16756
08/14/2025, 10:59 AMtall-airline-16756
08/14/2025, 10:59 AM_gemini_tools
parameter when you set up the RealtimeModel
. This gives you access to handy built-in tools like Google Search and more, making the model even smarter with real-time info.
Here’s a quick example to get you started:
from livekit.plugins import google
from google.genai import types
session = AgentSession(
llm=google.beta.realtime.RealtimeModel(
model="gemini-2.0-flash-exp",
_gemini_tools=[types.GoogleSearch()],
),
)
Just a heads-up: this feature is still experimental, so things might change in future SDK updates. Also, make sure your authentication is set up properly to use the Gemini tools smoothly.
Sources: Gemini Multimodal Live integration guide | LiveKit Docscalm-book-72252
08/14/2025, 11:06 AMtall-airline-16756
08/14/2025, 11:06 AMfrom google.genai import types
llm = google.LLM(
model="gemini-2.0-flash-001",
gemini_tools=[types.GoogleSearch()], # Use only one tool
)
Here are the tools you can use:
• GoogleSearch()
• GoogleSearchRetrieval()
• ToolCodeExecution()
• UrlContext()
• GoogleMaps()
This is just how Gemini’s API works right now, but it might change in future updates. If you have any questions or need a hand with this, just let me know—I’m here to help!
Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime...calm-book-72252
08/14/2025, 11:19 AMtall-airline-16756
08/14/2025, 11:19 AMgenerate
method to get a response that includes Google Search results.
4. Log the Search Response: Grab the search results from the function call output and log them.
Here’s a quick example to get you started:
from livekit.plugins import google
from google.genai import types
# Initialize the Gemini LLM with Google Search tool
llm = google.LLM(
model="gemini-2.0-flash-exp",
api_key="your-api-key", # or set GOOGLE_API_KEY environment variable
gemini_tools=[types.GoogleSearch()], # Enable Google Search tool
)
# Create an AgentSession
session = AgentSession(llm=llm)
# Generate a response that uses Google Search
response = session.generate(
"What is the latest news about AI?"
)
# Check each message for function call outputs
for message in response.messages:
if message.type == "function_call_output":
function_call_output = message
# Log the search response
print(f"Search Response: {function_call_output.output}")
Just make sure your API key is set up correctly, either through the api_key
parameter or your environment variables. If you run into any issues or want to chat more about it, I’m here to help!calm-book-72252
08/14/2025, 11:20 AMtall-airline-16756
08/14/2025, 11:21 AM_gemini_tools
parameter when you initialize the RealtimeModel. Here’s a quick example:
from livekit.plugins import google
from google.genai import types
session = AgentSession(
llm=google.beta.realtime.RealtimeModel(
model="gemini-2.0-flash-exp",
_gemini_tools=[types.GoogleSearch()],
),
# Other configurations like TTS, STT, etc.
)
1. Next, add some logging in your agent: Keep an eye on the responses the model generates and log what you need. Here’s a handy snippet:
async def on_session_started(session: AgentSession):
# Create a callback to log responses
async def on_response(response: llm.Response):
# Log the response text
print("Gemini Response:", response.text)
# You can add more logic here to log or analyze the response
# Register the callback
session.register_callback(llm.Event.RESPONSE_GENERATED, on_response)
Just make sure your authentication is all set up properly (like your GOOGLE_API_KEY
or GOOGLE_APPLICATION_CREDENTIALS
). If anything’s unclear or you want me to walk you through it, just let me know—I’m here to help!calm-book-72252
08/14/2025, 11:25 AMtall-airline-16756
08/14/2025, 11:25 AMfrom os import getenv
from typing import Optional
import asyncio
from google.genai import types
from livekit import AgentSession
from livekit.plugins import google
# Initialize the RealtimeModel with Google Search tool
realtime_model = google.beta.realtime.RealtimeModel(
model="gemini-2.0-flash-exp",
voice="Puck",
temperature=0.8,
instructions="You are a helpful assistant",
_gemini_tools=[types.GoogleSearch()],
)
# Initialize the AgentSession (add other components like TTS, STT, etc. as needed)
async def main():
# Set up authentication
GOOGLE_API_KEY = getenv("GOOGLE_API_KEY")
# Create the AgentSession
session = AgentSession(
llm=realtime_model,
# Add other components (TTS, STT, etc.) here
)
try:
# Example query
response_event = await session.generate_reply(
instructions="Search for the latest developments in AI."
)
# Log the response
if response_event.response:
print("Google Search Response:")
print(response_event.response.text)
except Exception as e:
print(f"Oops, something went wrong during the search: {e}")
finally:
await session.aclose()
# Run the async example
asyncio.run(main())
Key Points:
• Authentication: Make sure your GOOGLE_API_KEY
environment variable is set before running this code.
• Google Search Tool: The _gemini_tools=[types.GoogleSearch()]
parameter is what enables the Google Search integration.
• Response Logging: The response text from your search query gets printed right to the console.
• Error Handling: There’s simple error handling included to catch and let you know if anything goes wrong.
Requirements:
• You’ll need the livekit-agents[google]
package installed.
• Don’t forget to set your GOOGLE_API_KEY
environment variable.
• Make sure all the necessary Python dependencies are installed.
If you have any questions or want me to walk you through anything else, just let me know—I’m here to help!calm-book-72252
08/14/2025, 11:36 AMtall-airline-16756
08/14/2025, 11:37 AMconversation_item_added
event in LiveKit. Whenever a tool runs and generates some output, it gets added as an item in the conversation history, which then triggers the conversation_item_added
event.
Here’s a little example to help you get started:
from livekit.agents import ConversationItemAddedEvent
@session.on("conversation_item_added")
def on_conversation_item_added(event: ConversationItemAddedEvent):
if event.item.role == "assistant" and event.item.tool_call_id:
# Handle tool output
print("Tool output:", event.item.text_content)
This handler will catch the tool output as soon as it’s added to the conversation. If you have any questions or want me to walk you through it, just let me know—I’m happy to help!