fast-egg-39595
08/21/2025, 7:33 PMtall-airline-16756
08/21/2025, 7:33 PMtall-airline-16756
08/21/2025, 7:35 PM@function_tool decorator to create custom tools. Here’s a quick example to get you started:
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:
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:
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 Docsfast-egg-39595
08/22/2025, 3:30 AMtall-airline-16756
08/22/2025, 3:31 AMupdate_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:
@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:
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:
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.pyfast-egg-39595
08/22/2025, 3:40 AMtall-airline-16756
08/22/2025, 3:40 AMchat_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 | DeepWikifast-egg-39595
08/22/2025, 3:42 AMtall-airline-16756
08/22/2025, 3:42 AMproactivity 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