-
Notifications
You must be signed in to change notification settings - Fork 296
Add xAI realtime provider tools #1583
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
Closed
rosetta-livekit-bot
wants to merge
1
commit into
brian/provider-tool-base
from
beveling-sounder-finesse
Closed
Changes from all commits
Commits
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,6 @@ | ||
| --- | ||
| '@livekit/agents-plugin-openai': patch | ||
| '@livekit/agents-plugin-xai': minor | ||
| --- | ||
|
|
||
| Add xAI Realtime provider tools for web search, X search, and file search. |
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 |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // SPDX-FileCopyrightText: 2026 LiveKit, Inc. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import { llm } from '@livekit/agents'; | ||
|
|
||
| export abstract class XAITool extends llm.ProviderTool { | ||
| abstract toToolConfig(): Record<string, unknown>; | ||
| } | ||
|
|
||
| /** Enable web search tool for real-time internet searches. */ | ||
| export class WebSearch extends XAITool { | ||
| constructor() { | ||
| super({ id: 'xai_web_search' }); | ||
| } | ||
|
|
||
| toToolConfig(): Record<string, unknown> { | ||
| return { type: 'web_search' }; | ||
| } | ||
| } | ||
|
|
||
| export interface XSearchOptions { | ||
| allowedXHandles?: string[]; | ||
| } | ||
|
|
||
| /** Enable X search tool for searching posts. */ | ||
| export class XSearch extends XAITool { | ||
| readonly allowedXHandles: string[] | undefined; | ||
|
|
||
| constructor({ allowedXHandles }: XSearchOptions = {}) { | ||
| super({ id: 'xai_x_search' }); | ||
| this.allowedXHandles = allowedXHandles ? [...allowedXHandles] : undefined; | ||
| } | ||
|
|
||
| toToolConfig(): Record<string, unknown> { | ||
| const result: Record<string, unknown> = { type: 'x_search' }; | ||
| if (this.allowedXHandles !== undefined) { | ||
| result.allowed_x_handles = this.allowedXHandles; | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
|
|
||
| export interface FileSearchOptions { | ||
| vectorStoreIds?: string[]; | ||
| maxNumResults?: number; | ||
| } | ||
|
|
||
| /** Enable file search tool for searching uploaded document collections. */ | ||
| export class FileSearch extends XAITool { | ||
| readonly vectorStoreIds: string[]; | ||
| readonly maxNumResults: number | undefined; | ||
|
|
||
| constructor({ vectorStoreIds = [], maxNumResults }: FileSearchOptions = {}) { | ||
| super({ id: 'xai_file_search' }); | ||
| this.vectorStoreIds = [...vectorStoreIds]; | ||
| this.maxNumResults = maxNumResults; | ||
| } | ||
|
|
||
| toToolConfig(): Record<string, unknown> { | ||
| const result: Record<string, unknown> = { | ||
| type: 'file_search', | ||
| vector_store_ids: this.vectorStoreIds, | ||
| }; | ||
| if (this.maxNumResults !== undefined) { | ||
| result.max_num_results = this.maxNumResults; | ||
| } | ||
| return result; | ||
| } | ||
| } |
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.
🔴 Reconnect skips restoring xAI provider tools when no function tools are present
The
reconnect()method inOpenAIRealtimeSessionatplugins/openai/src/realtime/realtime_model.ts:1002only checksObject.keys(this._tools.functionTools).length > 0before sending the tools update event. SincefunctionToolsonly returns function tools (not provider tools), if an xAI session is configured with only provider tools (e.g.,WebSearch,XSearch,FileSearch) and no function tools, those tools will not be sent to the server during reconnection. After the default 20-minutemaxSessionDurationtriggers a reconnect, the xAI provider tools are silently lost.Reconnect condition only checks function tools
At
plugins/openai/src/realtime/realtime_model.ts:1002-1004:functionTools(agents/src/llm/tool_context.ts:287-289) only returns entries from_functionToolsMap, not_providerTools. The xAIRealtimeSessionoverridescreateToolsUpdateEventto append provider tools, but that method is never called when this condition is false.(Refers to lines 1002-1004)
Was this helpful? React with 👍 or 👎 to provide feedback.