diff --git a/.changeset/live-model-swaps.md b/.changeset/live-model-swaps.md new file mode 100644 index 000000000..ff2b2e665 --- /dev/null +++ b/.changeset/live-model-swaps.md @@ -0,0 +1,5 @@ +--- +'@livekit/agents': patch +--- + +Add `updateOptions` support to inference LLM for live model swaps. diff --git a/agents/src/inference/llm.ts b/agents/src/inference/llm.ts index 3434e496c..01b9573a8 100644 --- a/agents/src/inference/llm.ts +++ b/agents/src/inference/llm.ts @@ -247,6 +247,27 @@ export class LLM extends llm.LLM { return new LLM({ model: modelString }); } + /** + * Update LLM configuration options used by the next chat call. + * + * `modelOptions` replaces the persistent options object instead of merging; + * pass `{}` to clear it. + */ + updateOptions({ + model, + modelOptions, + }: { + model?: LLMModels; + modelOptions?: ChatCompletionOptions; + }): void { + if (model !== undefined) { + this.opts.model = model; + } + if (modelOptions !== undefined) { + this.opts.modelOptions = { ...modelOptions }; + } + } + chat({ chatCtx, toolCtx,