diff --git a/.changeset/lovely-horses-eat.md b/.changeset/lovely-horses-eat.md new file mode 100644 index 00000000..a9a9e7bf --- /dev/null +++ b/.changeset/lovely-horses-eat.md @@ -0,0 +1,5 @@ +--- +'@livekit/agents-plugin-openai': minor +--- + +Narrow tools inventory per session update diff --git a/plugins/openai/src/realtime/realtime_model.ts b/plugins/openai/src/realtime/realtime_model.ts index dfd14ccb..d4da3d32 100644 --- a/plugins/openai/src/realtime/realtime_model.ts +++ b/plugins/openai/src/realtime/realtime_model.ts @@ -1,8 +1,7 @@ // SPDX-FileCopyrightText: 2024 LiveKit, Inc. // // SPDX-License-Identifier: Apache-2.0 -import { AsyncIterableQueue, Future, Queue } from '@livekit/agents'; -import { llm, log, multimodal } from '@livekit/agents'; +import { AsyncIterableQueue, Future, Queue, llm, log, multimodal } from '@livekit/agents'; import { AudioFrame } from '@livekit/rtc-node'; import { once } from 'events'; import { WebSocket } from 'ws'; @@ -392,6 +391,7 @@ export class RealtimeSession extends multimodal.RealtimeSession { temperature = this.#opts.temperature, maxResponseOutputTokens = this.#opts.maxResponseOutputTokens, toolChoice = 'auto', + allowedFunctions = Object.keys(this.#fncCtx || {}), }: { modalities: ['text', 'audio'] | ['text']; instructions?: string; @@ -403,6 +403,7 @@ export class RealtimeSession extends multimodal.RealtimeSession { temperature?: number; maxResponseOutputTokens?: number; toolChoice?: api_proto.ToolChoice; + allowedFunctions?: string[]; }) { this.#opts = { modalities, @@ -420,12 +421,14 @@ export class RealtimeSession extends multimodal.RealtimeSession { }; const tools = this.#fncCtx - ? Object.entries(this.#fncCtx).map(([name, func]) => ({ - type: 'function' as const, - name, - description: func.description, - parameters: llm.oaiParams(func.parameters), - })) + ? Object.entries(this.#fncCtx) + .filter(([name]) => allowedFunctions.includes(name)) + .map(([name, func]) => ({ + type: 'function' as const, + name, + description: func.description, + parameters: llm.oaiParams(func.parameters), + })) : []; this.queueMsg({