-
Notifications
You must be signed in to change notification settings - Fork 295
Add Gemini provider tools #1578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@livekit/agents-plugin-google': minor | ||
| --- | ||
|
|
||
| Add Gemini provider tools for Google Search, Google Maps, URL context, File Search, code execution, and Vertex RAG retrieval, and serialize them from `ToolContext` for Google LLM and realtime sessions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,100 @@ | ||
| // SPDX-FileCopyrightText: 2025 LiveKit, Inc. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import type { Tool } from '@google/genai'; | ||
| import type * as types from '@google/genai'; | ||
| import { llm } from '@livekit/agents'; | ||
|
|
||
| export type LLMTools = Omit<Tool, 'functionDeclarations'>; | ||
| export type LLMTools = Omit<types.Tool, 'functionDeclarations'>; | ||
|
|
||
| export abstract class GeminiTool extends llm.ProviderTool { | ||
| abstract toToolConfig(): types.Tool; | ||
| } | ||
|
|
||
| export class GoogleSearch extends GeminiTool { | ||
| constructor(public readonly options: types.GoogleSearch = {}) { | ||
| super({ id: 'gemini_google_search' }); | ||
| } | ||
|
|
||
| toToolConfig(): types.Tool { | ||
| return { googleSearch: this.options }; | ||
| } | ||
| } | ||
|
|
||
| export class GoogleMaps extends GeminiTool { | ||
| constructor(public readonly options: types.GoogleMaps = {}) { | ||
| super({ id: 'gemini_google_maps' }); | ||
| } | ||
|
|
||
| toToolConfig(): types.Tool { | ||
| return { googleMaps: this.options }; | ||
| } | ||
| } | ||
|
|
||
| export class URLContext extends GeminiTool { | ||
| constructor() { | ||
| super({ id: 'gemini_url_context' }); | ||
| } | ||
|
|
||
| toToolConfig(): types.Tool { | ||
| return { urlContext: {} }; | ||
| } | ||
| } | ||
|
|
||
| export interface FileSearchOptions extends types.FileSearch { | ||
| fileSearchStoreNames: string[]; | ||
| } | ||
|
|
||
| export class FileSearch extends GeminiTool { | ||
| constructor(public readonly options: FileSearchOptions) { | ||
| super({ id: 'gemini_file_search' }); | ||
| } | ||
|
|
||
| toToolConfig(): types.Tool { | ||
| return { fileSearch: this.options }; | ||
| } | ||
| } | ||
|
|
||
| export class ToolCodeExecution extends GeminiTool { | ||
| constructor() { | ||
| super({ id: 'gemini_code_execution' }); | ||
| } | ||
|
|
||
| toToolConfig(): types.Tool { | ||
| return { codeExecution: {} }; | ||
| } | ||
| } | ||
|
|
||
| export interface VertexRAGRetrievalOptions { | ||
| ragResources: string[]; | ||
| similarityTopK?: number; | ||
| vectorDistanceThreshold?: number; | ||
| } | ||
|
|
||
| export class VertexRAGRetrieval extends GeminiTool { | ||
| readonly ragResources: string[]; | ||
| readonly similarityTopK: number; | ||
| readonly vectorDistanceThreshold?: number; | ||
|
|
||
| constructor({ | ||
| ragResources, | ||
| similarityTopK = 3, | ||
| vectorDistanceThreshold, | ||
| }: VertexRAGRetrievalOptions) { | ||
| super({ id: 'gemini_vertex_rag_retrieval' }); | ||
| this.ragResources = ragResources; | ||
| this.similarityTopK = similarityTopK; | ||
| this.vectorDistanceThreshold = vectorDistanceThreshold; | ||
| } | ||
|
|
||
| toToolConfig(): types.Tool { | ||
| return { | ||
| retrieval: { | ||
| vertexRagStore: { | ||
| ragResources: this.ragResources.map((ragCorpus) => ({ ragCorpus })), | ||
| similarityTopK: this.similarityTopK, | ||
| vectorDistanceThreshold: this.vectorDistanceThreshold, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Regression:
geminiToolscombined with function tools now throws instead of merging into a single Tool objectThe old code in
buildConnectConfigmergedgeminiTools(e.g.,{googleSearch: {}}) andfunctionDeclarationsinto a singleToolobject via the spread operator:[{ functionDeclarations: [...], ...this.options.geminiTools }]. The newtoToolsConfigfunction treatsgeminiToolsas a separate "provider tool" (plugins/google/src/utils.ts:192-193) and then throws an error atplugins/google/src/utils.ts:204-206if both function declarations and provider tools are present. This breaks any existing user who configures bothgeminiTools(e.g.,{googleSearch: {}}) and function tools in a realtime session — a combination that worked before and is valid in the Google API (a singleToolobject can contain bothfunctionDeclarationsand other tool types likegoogleSearch). The fix should mergegeminiToolsinto the function declarationsToolobject (matching the old behavior) rather than pushing it into the separateproviderToolsarray.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.