how to use session const session = await agent ...
# ask-ai
r
how to use session const session = await agent ._start_(ctx.room, participant) ._then_((session) => session as openai.realtime.RealtimeSession); for gemini
t
Thanks for reaching out, Hrithik. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're interested in using a session for Gemini in LiveKit! To get started, you can initialize it with the right LLM or TTS model from the LiveKit Google plugin. Here's a simple example for real-time voice interactions using the Gemini Live API:
Copy code
from livekit.plugins import google

session = AgentSession(
    llm=google.beta.realtime.RealtimeModel(
        model="gemini-2.0-flash-exp",
        voice="Puck",
        temperature=0.8,
        instructions="You are a helpful assistant",
    ),
)
Here are the steps to set everything up smoothly: 1. First, install the plugin using:
pip install "livekit-agents[google]~=1.2"
2. Next, set up authentication by either using the
GOOGLE_API_KEY
environment variable or passing it directly in your code. 3. Finally, use the session in your agent entrypoint, just like in the Voice AI quickstart. If you'd like, I’m here to help with more details on text-based interactions or setting up text-to-speech. Just let me know! Sources: Google Gemini integration guide | LiveKit Docs | web/src/data/playground-state.ts | Gemini Live API integration guide | LiveKit Docs | Gemini Live API integration guide | LiveKit Docs
r
in typescript
t
I'd be happy to guide you through using a session for Gemini in LiveKit with TypeScript. Here’s a simple step-by-step to get you started: 1. First, install the plugin by running:
npm install @livekit/agents-plugin-google
2. Next, you'll want to authenticate using your Google Gemini API key. You can do this either by setting an environment variable or directly in your code: 3. Then, create and configure the
RealtimeModel
like this: 4. Finally, integrate your model into an
AgentSession
with the following: If you’d like, I’m here to help with more details or optional settings like text-only mode or custom TTS—just let me know! Sources: Gemini Live API integration guide | LiveKit Docs | plugins/google/README.md | livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime... | web/src/components/session-controls.tsx
r
how to use session const session = await agent ._start_(ctx.room, participant) ._then_((session) => session as openai.realtime.RealtimeSession); how to write this in gemini for typescript
t
Thank you for reaching out! I see you're working with the syntax
const session = await agent.start(ctx.room, participant).then((session) => session as openai.realtime.RealtimeSession)
, which is specific to OpenAI's setup and doesn't quite fit with Gemini in LiveKit. No worries though! For Gemini, it's best to use the
voice.AgentSession
class along with
await
, rather than chaining with
.then()
. Here's a friendly example to guide you:
Copy code
import { voice } from '@livekit/agents';
import * as google from '@livekit/agents-plugin-google';

const session = new voice.AgentSession({
  llm: new google.beta.realtime.RealtimeModel({
    instructions: 'You are a helpful assistant.',
  }),
});

await session.start({
  agent: new voice.Agent({}),
  room: ctx.room,
});

session.generateReply();
This approach simplifies things by removing the need for
.then()
or type assertions, since the session type is set right when you create it. If any part of this feels unclear or you want to dive deeper, please don’t hesitate to ask—I’m here to help! Sources: packages/sip--make-a-call/src/agent.ts | examples/src/drive-thru/drivethru_agent.ts | src/agent.ts | src/agent.ts