
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@omarimai/agents-plugin-google
Advanced tools
Support for Gemini, Gemini Live, Cloud Speech-to-Text, and Cloud Text-to-Speech.
Support for Gemini, Gemini Live, Cloud Speech-to-Text, and Cloud Text-to-Speech.
npm install @omarimai/agents-plugin-google
import { multimodal } from '@livekit/agents';
import * as google from '@omarimai/agents-plugin-google';
const model = new google.realtime.RealtimeModel({
apiKey: process.env.GOOGLE_API_KEY,
voice: 'Puck',
});
const agent = new multimodal.MultimodalAgent({
model,
fncCtx,
});
Set your Google API key:
GOOGLE_API_KEY
environment variable, orapiKey
parameter to the constructorFor VertexAI, also set:
GOOGLE_CLOUD_PROJECT
environment variableGOOGLE_APPLICATION_CREDENTIALS
pointing to your service account keypnpm build
Create a simple test file to verify it works with MultimodalAgent:
// test.ts
import { multimodal, llm } from '@livekit/agents';
import * as google from './src/index.js';
const model = new google.realtime.RealtimeModel({
apiKey: 'your-api-key',
voice: 'Puck',
});
const fncCtx = new llm.FunctionContext();
const agent = new multimodal.MultimodalAgent({
model,
fncCtx,
});
console.log('Google plugin integrated successfully!');
Your plugin structure is now ready and should integrate seamlessly with the existing MultimodalAgent!
A TypeScript implementation of the Google Gemini Live API for real-time audio conversations with advanced features including function calling, conversation management, and turn detection.
session.conversation.item.create()
session.response.create()
npm install
Set your Google API key:
export GOOGLE_API_KEY="your-api-key-here"
import { RealtimeModel } from './src/realtime/realtime_model.js';
// Create a realtime model with advanced features
const model = new RealtimeModel({
model: 'gemini-2.0-flash-live-001',
voice: 'Puck',
instructions: 'You are a helpful AI assistant.',
turnDetection: {
type: 'server_vad',
threshold: 0.1,
silence_duration_ms: 1000
}
});
// Create a session
const session = model.session({
fncCtx: {},
chatCtx: new ChatContext()
});
// Advanced conversation management
session.conversation.item.create({
role: 'user',
text: 'Hello, how are you?'
});
// Start response generation
session.response.create();
// Enhanced conversation management
const items = session.conversation.item.list();
console.log('Conversation items:', items);
// Update a conversation item
session.conversation.item.update('msg_1', {
content: 'Updated message content'
});
// Delete a conversation item
session.conversation.item.delete('msg_1');
// Clear all conversation items
session.conversation.item.clear();
The plugin includes sophisticated turn detection with multiple features:
const model = new RealtimeModel({
turnDetection: {
type: 'server_vad',
threshold: 0.1, // Audio level threshold
silence_duration_ms: 1000, // Silence duration before turn end
prefix_padding_ms: 200 // Padding before speech start
}
});
// Listen for turn detection events
session.on('turn_detected', (event) => {
console.log('Turn detected:', event);
// event.type: 'silence_threshold'
// event.duration: silence duration in ms
// event.timestamp: when the turn was detected
});
session.on('input_speech_started', (event) => {
console.log('Speech started:', event);
// event.audioLevel: current audio level
// event.energyLevel: current energy level
// event.threshold: adaptive threshold used
});
Register and use tools with the session:
// Register a tool
session.updateTools([
{
name: 'get_weather',
description: 'Get current weather for a location',
parameters: {
type: 'object',
properties: {
location: { type: 'string' }
}
},
handler: async (args) => {
const { location } = args;
return { temperature: '72°F', condition: 'sunny' };
}
}
]);
// Listen for tool calls
session.on('toolCall', (toolCall) => {
console.log('Tool called:', toolCall);
});
The plugin emits comprehensive events:
// Transcript events
session.on('transcript', (event) => {
console.log('Transcript:', event.transcript, 'Final:', event.isFinal);
});
// Generation events
session.on('generation_created', (event) => {
console.log('Generation started:', event.messageId);
});
// Error handling
session.on('error', (error) => {
console.error('Session error:', error);
});
// Metrics
session.on('metrics_collected', (metrics) => {
console.log('Usage metrics:', metrics);
});
Advanced session control features:
// Interrupt current generation
session.interrupt();
// Start user activity
session.startUserActivity();
// Truncate conversation at specific message
session.truncate('msg_5', 5000); // Truncate at message 5, audio end at 5s
// Update session options
session.updateOptions({
temperature: 0.7,
maxOutputTokens: 1000
});
// Update instructions
session.updateInstructions('You are now a coding assistant.');
// Clear audio buffer
session.clearAudio();
// Commit audio for processing
session.commitAudio();
Handle audio frames with automatic resampling:
// Push audio frames (automatically resampled)
session.pushAudio(audioFrame);
// Push video frames
session.pushVideo(videoFrame);
// Get current audio buffer
const audioBuffer = session.inputAudioBuffer;
The plugin includes robust error recovery:
// Recover from text response
session.recoverFromTextResponse('item_123');
// Session automatically retries on connection failures
// Exponential backoff with configurable max retries
const model = new RealtimeModel({
// Model configuration
model: 'gemini-2.0-flash-live-001',
voice: 'Puck',
instructions: 'Custom instructions',
// Generation parameters
temperature: 0.8,
maxOutputTokens: 1000,
topP: 0.9,
topK: 40,
// Turn detection
turnDetection: {
type: 'server_vad',
threshold: 0.1,
silence_duration_ms: 1000
},
// Language and location
language: 'en-US',
location: 'us-central1',
// VertexAI (optional)
vertexai: false,
project: process.env.GOOGLE_CLOUD_PROJECT
});
session(options)
: Create a new sessionclose()
: Close all sessionsconversation.item.create(message)
: Create conversation itemconversation.item.update(id, updates)
: Update conversation itemconversation.item.delete(id)
: Delete conversation itemconversation.item.list()
: List all conversation itemsconversation.item.get(id)
: Get specific conversation itemconversation.item.clear()
: Clear all conversation itemsresponse.create()
: Start response generationpushAudio(frame)
: Push audio framepushVideo(frame)
: Push video framecommitAudio()
: Commit audio for processingclearAudio()
: Clear audio bufferinterrupt()
: Interrupt current generationstartUserActivity()
: Start user activitytruncate(messageId, audioEndMs)
: Truncate conversationupdateOptions(options)
: Update session optionsupdateInstructions(instructions)
: Update instructionsupdateTools(tools)
: Update available toolson(event, listener)
: Listen for eventsoff(event, listener)
: Remove event listeneremit(event, ...args)
: Emit eventAvailable events:
transcript
: Text transcript updateserror
: Error eventstoolCall
: Tool call eventsgeneration_created
: New generation startedinput_audio_transcription_completed
: Audio transcription completedinput_speech_started
: Speech startedmetrics_collected
: Usage metricsturn_detected
: Turn detection eventsApache-2.0
FAQs
Support for Gemini, Gemini Live, Cloud Speech-to-Text, and Cloud Text-to-Speech.
The npm package @omarimai/agents-plugin-google receives a total of 1,556 weekly downloads. As such, @omarimai/agents-plugin-google popularity was classified as popular.
We found that @omarimai/agents-plugin-google demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.