how do I properly register my own tools with googl...
# ask-ai
f
how do I properly register my own tools with google live api?
t
Thanks for reaching out, Doug. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to register your own tools with Google's Live API (specifically the Gemini Live API), you can easily do that using LiveKit's
@function_tool
decorator to create custom tools. Here’s a quick example to get you started:
Copy code
from livekit.agents import function_tool, Agent, RunContext

class MyAgent(Agent):
    @function_tool()
    async def lookup_weather(
        self,
        context: RunContext,
        location: str,
    ) -> dict[str, Any]:
        """Look up weather information for a given location.
        
        Args:
            location: The location to look up weather information for.
        """
        return {"weather": "sunny", "temperature_f": 70}
On top of that, if you'd like to use built-in Google tools like Google Search or Google Maps, you can integrate them by passing them through the
_gemini_tools
parameter. Here’s how you can do it:
Copy code
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()],
    ),
)
To get things rolling, make sure you’ve installed the right plugin with this command:
Copy code
pip install "livekit-agents[google]~=1.2"
And don’t forget, for authentication, just set either the
GOOGLE_API_KEY
or
GOOGLE_APPLICATION_CREDENTIALS
environment variable. If you have any special needs—like loading tools dynamically or mixing your own custom tools with built-in ones—just give me a shout! I’m happy to help you figure it all out. Sources: Tool definition and use | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/utils.py | mcp_client/agent_tools.py | Gemini Live API integration guide | LiveKit Docs
f
How do I change a given session's configuration mid-stream? Say for example I want to change the voice or turn proactivity = false based on some trigger. This is how I set things up now. "session = AgentSession( llm=google.beta.realtime.RealtimeModel( model="gemini-2.5-flash-exp-native-audio-thinking-dialog", # Using the thinking + dialog model # Voice selection (Puck is default, check Google docs for more voices) voice="Puck", temperature=0.8, # Enable proactive audio - model can initiate responses proactively proactivity=True, # Get API key from environment api_key=os.getenv("GOOGLE_GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY"), # Google's model has built-in VAD-based turn detection by default # The model will automatically detect when to respond ) )"
t
If you want to change a session's configuration while it's running, you can use the
update_agent()
method or some provider-specific options to update things on the fly: • Using `update_agent()`: This lets you swap out the current agent for a new one during runtime. Here's a quick example:
Copy code
@function_tool
async def change_agent(self):
    """Change the agent to a new configuration."""
    self.session.update_agent(NewAgent())
• For Google Gemini: You can use the
update_options()
method to tweak settings like
voice
or
temperature
. Just a heads-up, some changes might need a session restart:
Copy code
self._mark_restart_needed()  # This will trigger a session restart on the next turn
• For OpenAI Realtime Model: You can update parameters on the fly without needing to restart:
Copy code
session.session_update(
    instructions=new_config.instructions,
    voice=new_config.voice,
    temperature=new_config.temperature,
    turn_detection=new_config.turn_detection,
)
If you'd like, I’m happy to share more details or examples tailored to your specific setup—just let me know! Sources: Workflows | LiveKit Docs | multi-agent/long_or_short_agent.py | livekit-agents/livekit/agents/voice/agent_activity.py | agent/main.py
f
is context lost when the session restart takes place?
t
Just a heads-up: by default, the context doesn’t stick around when a session restarts. Every new session kicks off with a clean slate unless you set it up differently. If you want to keep the conversation flowing smoothly, here are a couple of ways to do that: • Grab the
chat_ctx
object from your previous session and pass it along when you start a new one. • Use the Model Context Protocol (MCP) for memory and personalization across sessions—though this one takes a bit more setup. Also, you can peek into
session.history
to pull up past chats and help rebuild context if needed. If you want, I’m here to help you figure out how to keep that context going! Sources: Workflows | LiveKit Docs | Workflows | LiveKit Docs | Model Context Protocol Integration | livekit/livekit_composite | DeepWiki
f
where is documented whether or not I can change the proactivity with the update vs a restart?
t
Just a heads-up: if you want to change the
proactivity
setting, you'll need to restart your session. The
update_options
method in the Google Realtime API plugin doesn’t let you update
proactivity
on the fly during an active session. So, to make this change, you’ll have to start a new session with the updated settings. If you need any help with that, I’m here for you! Sources: livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py