Skip to content

Commit eb788eb

Browse files
tillkolternbsp
andauthored
feat: Make tools inventory overridable per session update (#93)
Co-authored-by: aoife cassidy <[email protected]>
1 parent 3a319ab commit eb788eb

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

.changeset/lovely-horses-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@livekit/agents-plugin-openai': minor
3+
---
4+
5+
Narrow tools inventory per session update

plugins/openai/src/realtime/realtime_model.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ export class RealtimeSession extends multimodal.RealtimeSession {
599599
temperature = this.#opts.temperature,
600600
maxResponseOutputTokens = this.#opts.maxResponseOutputTokens,
601601
toolChoice = 'auto',
602+
selectedTools = Object.keys(this.#fncCtx || {}),
602603
}: {
603604
modalities: ['text', 'audio'] | ['text'];
604605
instructions?: string;
@@ -610,6 +611,7 @@ export class RealtimeSession extends multimodal.RealtimeSession {
610611
temperature?: number;
611612
maxResponseOutputTokens?: number;
612613
toolChoice?: api_proto.ToolChoice;
614+
selectedTools?: string[];
613615
}) {
614616
this.#opts = {
615617
modalities,
@@ -630,16 +632,18 @@ export class RealtimeSession extends multimodal.RealtimeSession {
630632
};
631633

632634
const tools = this.#fncCtx
633-
? Object.entries(this.#fncCtx).map(([name, func]) => ({
634-
type: 'function' as const,
635-
name,
636-
description: func.description,
637-
parameters:
638-
// don't format parameters if they are raw openai params
639-
func.parameters.type == ('object' as const)
640-
? func.parameters
641-
: llm.oaiParams(func.parameters),
642-
}))
635+
? Object.entries(this.#fncCtx)
636+
.filter(([name]) => selectedTools.includes(name))
637+
.map(([name, func]) => ({
638+
type: 'function' as const,
639+
name,
640+
description: func.description,
641+
parameters:
642+
// don't format parameters if they are raw openai params
643+
func.parameters.type == ('object' as const)
644+
? func.parameters
645+
: llm.oaiParams(func.parameters),
646+
}))
643647
: [];
644648

645649
const sessionUpdateEvent: api_proto.SessionUpdateEvent = {

0 commit comments

Comments
 (0)